Merged annhell-branch-float into trunk.
[ahxm.git] / out_oss.c
blobb75a136a2f5cf42cb886eed2f2dc2fa53721b9e7
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 #include "config.h"
27 #ifdef LINUX_OSS
29 #include <stdio.h>
30 #include <string.h>
31 #include <stdlib.h>
32 #include <fcntl.h>
33 #include <sys/ioctl.h>
34 #include <sys/types.h>
35 #include <unistd.h>
36 #include <errno.h>
37 #include <signal.h>
39 #include <linux/soundcard.h>
40 #include <linux/cdrom.h>
42 #include "core.h"
43 #include "output.h"
45 /*******************
46 Data
47 ********************/
49 static int _audio_fd=-1;
51 #define SOUND_BUFFER_BITS 10
52 #define SOUND_BUFFER_SIZE (1<<SOUND_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 int _out_open_oss(char * devfile)
74 int n;
76 if((_audio_fd=open(devfile, O_WRONLY))==-1)
77 return(-100);
79 n=(2<<16)|SOUND_BUFFER_BITS;
80 if(ioctl(_audio_fd, SNDCTL_DSP_SETFRAGMENT, &n)==-1)
81 return(-101);
83 if(ioctl(_audio_fd, SNDCTL_DSP_RESET, 0)==-1)
84 return(-102);
86 if(ioctl(_audio_fd, SNDCTL_DSP_SPEED, &_frequency)==-1)
87 return(-103);
89 n=1;
90 if(ioctl(_audio_fd, SNDCTL_DSP_STEREO, &n)==-1)
91 return(-104);
93 n=detect_endianess();
94 if(ioctl(_audio_fd, SNDCTL_DSP_SETFMT, &n)==-1)
96 /* do I really want 8 bit output? */
97 n=AFMT_U8;
98 if(ioctl(_audio_fd, SNDCTL_DSP_SETFMT, &n)==-1)
99 return(-105);
102 return(0);
106 int _out_write_oss(float lsample, float rsample)
108 /* char c;
110 c=lsample & 0xff; write(_audio_fd, &c, 1);
111 c=(lsample & 0xff00) >> 8; write(_audio_fd, &c, 1);
112 c=rsample & 0xff; write(_audio_fd, &c, 1);
113 c=(rsample & 0xff00) >> 8; write(_audio_fd, &c, 1); */
114 short int i;
116 i=(short int) lsample & 0xffff;
117 write(_audio_fd, &i, sizeof(short int));
119 i=(short int) rsample & 0xffff;
120 write(_audio_fd, &i, sizeof(short int));
122 return(0);
126 int _out_close_oss(void)
128 close(_audio_fd);
129 return(0);
132 #endif /* #ifdef LINUX_OSS */