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 ***************************************************************************/
19 #include <sys/types.h>
22 #include <sys/ioctl.h>
24 #include <sys/soundcard.h>
27 ////////////////////////////////////////////////////////////////////////
29 ////////////////////////////////////////////////////////////////////////
31 #define OSS_MODE_STEREO 1
32 #define OSS_MODE_MONO 0
34 #define OSS_SPEED_44100 44100
36 static int oss_audio_fd = -1;
39 ////////////////////////////////////////////////////////////////////////
41 ////////////////////////////////////////////////////////////////////////
43 static int oss_init(void)
50 int oss_speed, oss_stereo;
52 pstereo = OSS_MODE_STEREO;
56 if((oss_audio_fd=open("/dev/dsp",O_WRONLY,0))==-1)
58 printf("OSS device not available\n");
62 if(ioctl(oss_audio_fd,SNDCTL_DSP_RESET,0)==-1)
64 printf("Sound reset failed\n");
68 // we use 64 fragments with 1024 bytes each
69 // rearmed: now using 10*4096 for better latency
72 myfrag=(10<<16)|fragsize;
74 if(ioctl(oss_audio_fd,SNDCTL_DSP_SETFRAGMENT,&myfrag)==-1)
76 printf("Sound set fragment failed!\n");
82 if(ioctl(oss_audio_fd,SNDCTL_DSP_SETFMT,&format) == -1)
84 printf("Sound format not supported!\n");
88 if(format!=AFMT_S16_NE)
90 printf("Sound format not supported!\n");
94 if(ioctl(oss_audio_fd,SNDCTL_DSP_STEREO,&oss_stereo)==-1 || !oss_stereo)
96 printf("Stereo mode not supported!\n");
100 if(ioctl(oss_audio_fd,SNDCTL_DSP_SPEED,&oss_speed)==-1)
102 printf("Sound frequency not supported\n");
106 if(oss_speed!=pspeed)
108 printf("Sound frequency not supported\n");
115 ////////////////////////////////////////////////////////////////////////
117 ////////////////////////////////////////////////////////////////////////
119 static void oss_finish(void)
121 if(oss_audio_fd != -1 )
128 ////////////////////////////////////////////////////////////////////////
129 // GET BUFFERED STATUS
130 ////////////////////////////////////////////////////////////////////////
132 static int oss_busy(void)
137 if(oss_audio_fd == -1) return 1;
138 if(ioctl(oss_audio_fd,SNDCTL_DSP_GETOSPACE,&info)==-1)
142 if(info.fragments<(info.fragstotal>>1)) // can we write in at least the half of fragments?
144 else l=0; // -> else go on
150 ////////////////////////////////////////////////////////////////////////
152 ////////////////////////////////////////////////////////////////////////
154 static void oss_feed(void *buf, int bytes)
156 if(oss_audio_fd == -1) return;
157 write(oss_audio_fd, buf, bytes);
160 void out_register_oss(struct out_driver *drv)
163 drv->init = oss_init;
164 drv->finish = oss_finish;
165 drv->busy = oss_busy;
166 drv->feed = oss_feed;