Finally got rid of all _ prefixed symbols (apart from out_*.c, that will
[ahxm.git] / out_oss.c
blob019bc022f5aff5d1a6ab1903f4acf757d83b7360
1 /*
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
26 #include "config.h"
27 #include <stdio.h>
28 #include "ss_core.h"
29 #include "ss_output.h"
31 #ifdef CONFOPT_LINUX_OSS
33 #include <string.h>
34 #include <stdlib.h>
35 #include <fcntl.h>
36 #include <sys/ioctl.h>
37 #include <sys/types.h>
38 #include <unistd.h>
39 #include <errno.h>
40 #include <signal.h>
42 #include <linux/soundcard.h>
44 /*******************
45 Data
46 ********************/
48 static int _audio_fd=-1;
50 #define OSS_BUFFER_BITS 10
51 #define OSS_BUFFER_SIZE (1<<OSS_BUFFER_BITS)
54 /*******************
55 Code
56 ********************/
58 static int detect_endianess(void)
59 /* is this machine big or little endian? */
61 short s;
62 unsigned char * c;
64 s=1;
65 c=(unsigned char *) &s;
67 if(*c==1) return(AFMT_S16_LE);
68 return(AFMT_S16_BE);
72 static int _out_open_oss(char * devfile)
74 int n;
76 /* OSS does not support more than stereo output */
77 if(ss_nchannels > 2)
78 ss_nchannels=2;
80 if((_audio_fd=open(devfile, O_WRONLY))==-1)
81 return(-100);
83 n=(2<<16)|OSS_BUFFER_BITS;
84 if(ioctl(_audio_fd, SNDCTL_DSP_SETFRAGMENT, &n)==-1)
85 return(-101);
87 if(ioctl(_audio_fd, SNDCTL_DSP_RESET, 0)==-1)
88 return(-102);
90 if(ioctl(_audio_fd, SNDCTL_DSP_SPEED, &ss_frequency)==-1)
91 return(-103);
93 n=ss_nchannels == 2 ? 1 : 0;
94 if(ioctl(_audio_fd, SNDCTL_DSP_STEREO, &n)==-1)
95 return(-104);
97 n=detect_endianess();
98 if(ioctl(_audio_fd, SNDCTL_DSP_SETFMT, &n)==-1)
100 /* do I really want 8 bit output? */
101 n=AFMT_U8;
102 if(ioctl(_audio_fd, SNDCTL_DSP_SETFMT, &n)==-1)
103 return(-105);
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)
118 close(_audio_fd);
119 return(0);
123 /* driver */
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 */