Added a new source file, ss_song.c, to hold the old "event2" stream,
[ahxm.git] / out_oss.c
blob45a383f39cf713474f782a1804647c099a9cfd36
1 /*
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
26 #include "config.h"
27 #include <stdio.h>
28 #include "output.h"
30 #ifdef CONFOPT_LINUX_OSS
32 #include <string.h>
33 #include <stdlib.h>
34 #include <fcntl.h>
35 #include <sys/ioctl.h>
36 #include <sys/types.h>
37 #include <unistd.h>
38 #include <errno.h>
39 #include <signal.h>
41 #include <linux/soundcard.h>
43 #include "core.h"
46 /*******************
47 Data
48 ********************/
50 static int _audio_fd=-1;
52 #define OSS_BUFFER_BITS 10
53 #define OSS_BUFFER_SIZE (1<<OSS_BUFFER_BITS)
56 /*******************
57 Code
58 ********************/
60 static int detect_endianess(void)
61 /* is this machine big or little endian? */
63 short s;
64 unsigned char * c;
66 s=1;
67 c=(unsigned char *) &s;
69 if(*c==1) return(AFMT_S16_LE);
70 return(AFMT_S16_BE);
74 static int _out_open_oss(char * devfile)
76 int n;
78 /* OSS does not support more than stereo output */
79 if(_n_channels > 2)
80 _n_channels=2;
82 if((_audio_fd=open(devfile, O_WRONLY))==-1)
83 return(-100);
85 n=(2<<16)|OSS_BUFFER_BITS;
86 if(ioctl(_audio_fd, SNDCTL_DSP_SETFRAGMENT, &n)==-1)
87 return(-101);
89 if(ioctl(_audio_fd, SNDCTL_DSP_RESET, 0)==-1)
90 return(-102);
92 if(ioctl(_audio_fd, SNDCTL_DSP_SPEED, &_frequency)==-1)
93 return(-103);
95 n=_n_channels == 2 ? 1 : 0;
96 if(ioctl(_audio_fd, SNDCTL_DSP_STEREO, &n)==-1)
97 return(-104);
99 n=detect_endianess();
100 if(ioctl(_audio_fd, SNDCTL_DSP_SETFMT, &n)==-1)
102 /* do I really want 8 bit output? */
103 n=AFMT_U8;
104 if(ioctl(_audio_fd, SNDCTL_DSP_SETFMT, &n)==-1)
105 return(-105);
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)
120 close(_audio_fd);
121 return(0);
125 /* driver */
127 struct _output_driver _out_driver_oss=
128 { "oss", "/dev/dsp", _out_open_oss, _out_write_oss, _out_close_oss };
130 #else /* CONFOPT_LINUX_OSS */
132 struct _output_driver _out_driver_oss=
133 { "oss", NULL, NULL, NULL, NULL };
135 #endif /* #ifdef CONFOPT_LINUX_OSS */