1 /***************************************************************************
4 begin : Wed May 15 2002
5 copyright : (C) 2002 by Pete Bernert
6 email : BlackDove@addcom.de
7 ***************************************************************************/
8 /***************************************************************************
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. See also the license.txt file for *
14 * additional informations. *
16 ***************************************************************************/
20 #include <sys/types.h>
23 #include <sys/ioctl.h>
25 #include <sys/soundcard.h>
28 ////////////////////////////////////////////////////////////////////////
30 ////////////////////////////////////////////////////////////////////////
32 #define OSS_MODE_STEREO 1
33 #define OSS_MODE_MONO 0
35 #define OSS_SPEED_44100 44100
37 static int oss_audio_fd = -1;
40 ////////////////////////////////////////////////////////////////////////
42 ////////////////////////////////////////////////////////////////////////
44 static int oss_init(void)
51 int oss_speed, oss_stereo;
53 pstereo = OSS_MODE_STEREO;
57 if((oss_audio_fd=open("/dev/dsp",O_WRONLY,0))==-1)
59 printf("OSS device not available\n");
63 if(ioctl(oss_audio_fd,SNDCTL_DSP_RESET,0)==-1)
65 printf("Sound reset failed\n");
69 // we use 64 fragments with 1024 bytes each
70 // rearmed: now using 10*4096 for better latency
73 myfrag=(10<<16)|fragsize;
75 if(ioctl(oss_audio_fd,SNDCTL_DSP_SETFRAGMENT,&myfrag)==-1)
77 printf("Sound set fragment failed!\n");
83 if(ioctl(oss_audio_fd,SNDCTL_DSP_SETFMT,&format) == -1)
85 printf("Sound format not supported!\n");
89 if(format!=AFMT_S16_NE)
91 printf("Sound format not supported!\n");
95 if(ioctl(oss_audio_fd,SNDCTL_DSP_STEREO,&oss_stereo)==-1 || !oss_stereo)
97 printf("Stereo mode not supported!\n");
101 if(ioctl(oss_audio_fd,SNDCTL_DSP_SPEED,&oss_speed)==-1)
103 printf("Sound frequency not supported\n");
107 if(oss_speed!=pspeed)
109 printf("Sound frequency not supported\n");
116 ////////////////////////////////////////////////////////////////////////
118 ////////////////////////////////////////////////////////////////////////
120 static void oss_finish(void)
122 if(oss_audio_fd != -1 )
129 ////////////////////////////////////////////////////////////////////////
130 // GET BUFFERED STATUS
131 ////////////////////////////////////////////////////////////////////////
133 static int oss_busy(void)
138 if(oss_audio_fd == -1) return 1;
139 if(ioctl(oss_audio_fd,SNDCTL_DSP_GETOSPACE,&info)==-1)
143 if(info.fragments<(info.fragstotal>>1)) // can we write in at least the half of fragments?
145 else l=0; // -> else go on
151 ////////////////////////////////////////////////////////////////////////
153 ////////////////////////////////////////////////////////////////////////
155 static void oss_feed(void *buf, int bytes)
160 if(oss_audio_fd == -1) return;
161 if(ioctl(oss_audio_fd,SNDCTL_DSP_GETOSPACE,&info)==0)
163 if(info.fragments==info.fragstotal)
165 memset(sbuf, 0, sizeof(sbuf));
166 write(oss_audio_fd, sbuf, sizeof(sbuf));
167 write(oss_audio_fd, sbuf, sizeof(sbuf));
171 write(oss_audio_fd, buf, bytes);
174 void out_register_oss(struct out_driver *drv)
177 drv->init = oss_init;
178 drv->finish = oss_finish;
179 drv->busy = oss_busy;
180 drv->feed = oss_feed;