3 Ann Hell Ex Machina - Music Software
4 Copyright (C) 2003/2004 Angel Ortega <angel@triptico.com>
6 out_oss.c - Output driver for Linux Open Sound System
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 http://www.triptico.com
35 #include <sys/ioctl.h>
36 #include <sys/types.h>
41 #include <linux/soundcard.h>
50 static int _audio_fd
=-1;
52 #define OSS_BUFFER_BITS 10
53 #define OSS_BUFFER_SIZE (1<<OSS_BUFFER_BITS)
60 static int detect_endianess(void)
61 /* is this machine big or little endian? */
67 c
=(unsigned char *) &s
;
69 if(*c
==1) return(AFMT_S16_LE
);
74 static int _out_open_oss(char * devfile
)
78 /* OSS does not support more than stereo output */
82 if((_audio_fd
=open(devfile
, O_WRONLY
))==-1)
85 n
=(2<<16)|OSS_BUFFER_BITS
;
86 if(ioctl(_audio_fd
, SNDCTL_DSP_SETFRAGMENT
, &n
)==-1)
89 if(ioctl(_audio_fd
, SNDCTL_DSP_RESET
, 0)==-1)
92 if(ioctl(_audio_fd
, SNDCTL_DSP_SPEED
, &_frequency
)==-1)
95 n
=_n_channels
== 2 ? 1 : 0;
96 if(ioctl(_audio_fd
, SNDCTL_DSP_STEREO
, &n
)==-1)
100 if(ioctl(_audio_fd
, SNDCTL_DSP_SETFMT
, &n
)==-1)
102 /* do I really want 8 bit output? */
104 if(ioctl(_audio_fd
, SNDCTL_DSP_SETFMT
, &n
)==-1)
108 return(OSS_BUFFER_SIZE
);
112 static int _out_write_oss(short int * buffer
, int size
)
114 return(write(_audio_fd
, buffer
, size
* sizeof(short int)));
118 static int _out_close_oss(void)
127 struct _output_driver _out_driver_oss
=
128 { "oss", "/dev/dsp", _out_open_oss
, _out_write_oss
, _out_close_oss
};
130 #else /* LINUX_OSS */
132 struct _output_driver _out_driver_oss
=
133 { "oss", NULL
, NULL
, NULL
, NULL
};
135 #endif /* #ifdef LINUX_OSS */