3 Ann Hell Ex Machina - Music Software
4 Copyright (C) 2003/2005 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
29 #include "ss_output.h"
31 #ifdef CONFOPT_LINUX_OSS
36 #include <sys/ioctl.h>
37 #include <sys/types.h>
42 #include <linux/soundcard.h>
48 static int _audio_fd
=-1;
50 #define OSS_BUFFER_BITS 10
51 #define OSS_BUFFER_SIZE (1<<OSS_BUFFER_BITS)
58 static int detect_endianess(void)
59 /* is this machine big or little endian? */
65 c
=(unsigned char *) &s
;
67 if(*c
==1) return(AFMT_S16_LE
);
72 static int _out_open_oss(char * devfile
)
76 /* OSS does not support more than stereo output */
80 if((_audio_fd
=open(devfile
, O_WRONLY
))==-1)
83 n
=(2<<16)|OSS_BUFFER_BITS
;
84 if(ioctl(_audio_fd
, SNDCTL_DSP_SETFRAGMENT
, &n
)==-1)
87 if(ioctl(_audio_fd
, SNDCTL_DSP_RESET
, 0)==-1)
90 if(ioctl(_audio_fd
, SNDCTL_DSP_SPEED
, &ss_frequency
)==-1)
93 n
=ss_nchannels
== 2 ? 1 : 0;
94 if(ioctl(_audio_fd
, SNDCTL_DSP_STEREO
, &n
)==-1)
98 if(ioctl(_audio_fd
, SNDCTL_DSP_SETFMT
, &n
)==-1)
100 /* do I really want 8 bit output? */
102 if(ioctl(_audio_fd
, SNDCTL_DSP_SETFMT
, &n
)==-1)
106 return(OSS_BUFFER_SIZE
);
110 static int _out_write_oss(short int * buffer
, int size
)
112 return(write(_audio_fd
, buffer
, size
* sizeof(short int)));
116 static int _out_close_oss(void)
125 struct _output_driver _out_driver_oss
=
126 { "oss", "/dev/dsp", _out_open_oss
, _out_write_oss
, _out_close_oss
};
128 #else /* CONFOPT_LINUX_OSS */
130 struct _output_driver _out_driver_oss
=
131 { "oss", NULL
, NULL
, NULL
, NULL
};
133 #endif /* #ifdef CONFOPT_LINUX_OSS */