Several bugfixes.
[ahxm.git] / out_oss.c
blobd62e57b8b4846c10f627d465abe1ded76eb40b23
1 /*
3 PROGRAM_NAME PROGRAM_VERSION - PROGRAM_DESCRIPTION
5 Copyright (C) 2003 Angel Ortega <angel@triptico.com>
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2
10 of the License, or (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 http://www.triptico.com
25 #ifdef LINUX_OSS
27 #include <stdio.h>
28 #include <string.h>
29 #include <stdlib.h>
30 #include <fcntl.h>
31 #include <sys/ioctl.h>
32 #include <sys/types.h>
33 #include <unistd.h>
34 #include <errno.h>
35 #include <signal.h>
37 #include <linux/soundcard.h>
38 #include <linux/cdrom.h>
40 #include "output.h"
42 /*******************
43 Data
44 ********************/
46 extern int _frequency;
48 static int _audio_fd=-1;
50 #define SOUND_BUFFER_BITS 10
51 #define SOUND_BUFFER_SIZE (1<<SOUND_BUFFER_BITS)
53 /*******************
54 Code
55 ********************/
57 static int detect_endianess(void)
58 /* is this machine big or little endian? */
60 short s;
61 unsigned char * c;
63 s=1;
64 c=(unsigned char *) &s;
66 if(*c==1) return(AFMT_S16_LE);
67 return(AFMT_S16_BE);
71 int _out_open_oss(char * devfile)
73 int n;
75 if((_audio_fd=open(devfile, O_WRONLY))==-1)
76 return(0);
78 n=(2<<16)|SOUND_BUFFER_BITS;
79 if(ioctl(_audio_fd, SNDCTL_DSP_SETFRAGMENT, &n)==-1)
80 return(0);
82 if(ioctl(_audio_fd, SNDCTL_DSP_RESET, 0)==-1)
83 return(0);
85 if(ioctl(_audio_fd, SNDCTL_DSP_SPEED, &_frequency)==-1)
86 return(0);
88 n=1;
89 if(ioctl(_audio_fd, SNDCTL_DSP_STEREO, &n)==-1)
90 return(0);
92 n=detect_endianess();
93 if(ioctl(_audio_fd, SNDCTL_DSP_SETFMT, &n)==-1)
95 /* do I really want 8 bit output? */
96 n=AFMT_U8;
97 if(ioctl(_audio_fd, SNDCTL_DSP_SETFMT, &n)==-1)
98 return(0);
101 return(1);
105 int _out_write_oss(int lsample, int rsample)
107 /* char c;
109 c=lsample & 0xff; write(_audio_fd, &c, 1);
110 c=(lsample & 0xff00) >> 8; write(_audio_fd, &c, 1);
111 c=rsample & 0xff; write(_audio_fd, &c, 1);
112 c=(rsample & 0xff00) >> 8; write(_audio_fd, &c, 1); */
113 short int i;
115 i=lsample & 0xffff; write(_audio_fd, &i, sizeof(short int));
116 i=rsample & 0xffff; write(_audio_fd, &i, sizeof(short int));
118 return(0);
122 int _out_close_oss(void)
124 close(_audio_fd);
125 return(0);
128 #endif /* #ifdef LINUX_OSS */