Support for unsigned 16 bit samples.
[ahxm.git] / out_oss.c
blob331a3a47f67ae4b16497f65b3f6caec79579e4f9
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 "output.h"
44 /*******************
45 Data
46 ********************/
48 extern int _frequency;
50 static int _audio_fd=-1;
52 #define SOUND_BUFFER_BITS 10
53 #define SOUND_BUFFER_SIZE (1<<SOUND_BUFFER_BITS)
55 /*******************
56 Code
57 ********************/
59 static int detect_endianess(void)
60 /* is this machine big or little endian? */
62 short s;
63 unsigned char * c;
65 s=1;
66 c=(unsigned char *) &s;
68 if(*c==1) return(AFMT_S16_LE);
69 return(AFMT_S16_BE);
73 int _out_open_oss(char * devfile)
75 int n;
77 if((_audio_fd=open(devfile, O_WRONLY))==-1)
78 return(-100);
80 n=(2<<16)|SOUND_BUFFER_BITS;
81 if(ioctl(_audio_fd, SNDCTL_DSP_SETFRAGMENT, &n)==-1)
82 return(-101);
84 if(ioctl(_audio_fd, SNDCTL_DSP_RESET, 0)==-1)
85 return(-102);
87 if(ioctl(_audio_fd, SNDCTL_DSP_SPEED, &_frequency)==-1)
88 return(-103);
90 n=1;
91 if(ioctl(_audio_fd, SNDCTL_DSP_STEREO, &n)==-1)
92 return(-104);
94 n=detect_endianess();
95 if(ioctl(_audio_fd, SNDCTL_DSP_SETFMT, &n)==-1)
97 /* do I really want 8 bit output? */
98 n=AFMT_U8;
99 if(ioctl(_audio_fd, SNDCTL_DSP_SETFMT, &n)==-1)
100 return(-105);
103 return(0);
107 int _out_write_oss(int lsample, int rsample)
109 /* char c;
111 c=lsample & 0xff; write(_audio_fd, &c, 1);
112 c=(lsample & 0xff00) >> 8; write(_audio_fd, &c, 1);
113 c=rsample & 0xff; write(_audio_fd, &c, 1);
114 c=(rsample & 0xff00) >> 8; write(_audio_fd, &c, 1); */
115 short int i;
117 i=lsample & 0xffff; write(_audio_fd, &i, sizeof(short int));
118 i=rsample & 0xffff; write(_audio_fd, &i, sizeof(short int));
120 return(0);
124 int _out_close_oss(void)
126 close(_audio_fd);
127 return(0);
130 #endif /* #ifdef LINUX_OSS */