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 ***************************************************************************/
22 #include "externals.h"
24 ////////////////////////////////////////////////////////////////////////
26 ////////////////////////////////////////////////////////////////////////
28 #define OSS_MODE_STEREO 1
29 #define OSS_MODE_MONO 0
31 #define OSS_SPEED_44100 44100
33 static int oss_audio_fd = -1;
36 ////////////////////////////////////////////////////////////////////////
38 ////////////////////////////////////////////////////////////////////////
47 int oss_speed, oss_stereo;
49 if(iDisStereo) pstereo=OSS_MODE_MONO;
50 else pstereo=OSS_MODE_STEREO;
55 if((oss_audio_fd=open("/dev/dsp",O_WRONLY,0))==-1)
57 printf("Sound device not available!\n");
61 if(ioctl(oss_audio_fd,SNDCTL_DSP_RESET,0)==-1)
63 printf("Sound reset failed\n");
67 // we use 64 fragments with 1024 bytes each
68 // rearmed: now using 10*4096 for better latency
71 myfrag=(10<<16)|fragsize;
73 if(ioctl(oss_audio_fd,SNDCTL_DSP_SETFRAGMENT,&myfrag)==-1)
75 printf("Sound set fragment failed!\n");
81 if(ioctl(oss_audio_fd,SNDCTL_DSP_SETFMT,&format) == -1)
83 printf("Sound format not supported!\n");
87 if(format!=AFMT_S16_NE)
89 printf("Sound format not supported!\n");
93 if(ioctl(oss_audio_fd,SNDCTL_DSP_STEREO,&oss_stereo)==-1)
95 printf("Stereo mode not supported!\n");
104 if(ioctl(oss_audio_fd,SNDCTL_DSP_SPEED,&oss_speed)==-1)
106 printf("Sound frequency not supported\n");
110 if(oss_speed!=pspeed)
112 printf("Sound frequency not supported\n");
117 ////////////////////////////////////////////////////////////////////////
119 ////////////////////////////////////////////////////////////////////////
121 void RemoveSound(void)
123 if(oss_audio_fd != -1 )
130 ////////////////////////////////////////////////////////////////////////
131 // GET BYTES BUFFERED
132 ////////////////////////////////////////////////////////////////////////
134 unsigned long SoundGetBytesBuffered(void)
139 if(oss_audio_fd == -1) return SOUNDSIZE;
140 if(ioctl(oss_audio_fd,SNDCTL_DSP_GETOSPACE,&info)==-1)
144 if(info.fragments<(info.fragstotal>>1)) // can we write in at least the half of fragments?
145 l=SOUNDSIZE; // -> no? wait
146 else l=0; // -> else go on
152 ////////////////////////////////////////////////////////////////////////
154 ////////////////////////////////////////////////////////////////////////
156 void SoundFeedStreamData(unsigned char* pSound,long lBytes)
158 if(oss_audio_fd == -1) return;
159 write(oss_audio_fd,pSound,lBytes);