comparison libao2/ao_sdl.c @ 3095:981a9e5118ce

interface to libao2 changed ao_plugin added
author anders
date Sat, 24 Nov 2001 05:21:22 +0000
parents e7d98f8f9459
children b9ee2d8d7279
comparison
equal deleted inserted replaced
3094:4150aff2ac17 3095:981a9e5118ce
27 "" 27 ""
28 }; 28 };
29 29
30 LIBAO_EXTERN(sdl) 30 LIBAO_EXTERN(sdl)
31 31
32 // there are some globals:
33 // ao_samplerate
34 // ao_channels
35 // ao_format
36 // ao_bps
37 // ao_outburst
38 // ao_buffersize
39 32
40 extern int verbose; 33 extern int verbose;
41 34
42 // Samplesize used by the SDLlib AudioSpec struct 35 // Samplesize used by the SDLlib AudioSpec struct
43 #define SAMPLESIZE 1024 36 #define SAMPLESIZE 1024
148 141
149 if(ao_subdevice) { 142 if(ao_subdevice) {
150 setenv("SDL_AUDIODRIVER", ao_subdevice, 1); 143 setenv("SDL_AUDIODRIVER", ao_subdevice, 1);
151 printf("SDL: using %s audio driver\n", ao_subdevice); 144 printf("SDL: using %s audio driver\n", ao_subdevice);
152 } 145 }
146
147 ao_data.bps=(channels+1)*rate;
148 if(format != AFMT_U8 && format != AFMT_S8)
149 ao_data.bps*=2;
153 150
154 /* The desired audio format (see SDL_AudioSpec) */ 151 /* The desired audio format (see SDL_AudioSpec) */
155 switch(format) { 152 switch(format) {
156 case AFMT_U8: 153 case AFMT_U8:
157 aspec.format = AUDIO_U8; 154 aspec.format = AUDIO_U8;
203 printf("SDL: Unable to open audio: %s\n", SDL_GetError()); 200 printf("SDL: Unable to open audio: %s\n", SDL_GetError());
204 return(0); 201 return(0);
205 } 202 }
206 203
207 if(verbose) printf("SDL: buf size = %d\n",aspec.size); 204 if(verbose) printf("SDL: buf size = %d\n",aspec.size);
208 if(ao_buffersize==-1) ao_buffersize=aspec.size; 205 if(ao_data.buffersize==-1) ao_data.buffersize=aspec.size;
209 206
210 /* unsilence audio, if callback is ready */ 207 /* unsilence audio, if callback is ready */
211 SDL_PauseAudio(0); 208 SDL_PauseAudio(0);
212 209
213 return 1; 210 return 1;
276 #else 273 #else
277 return write_buffer(data, len); 274 return write_buffer(data, len);
278 #endif 275 #endif
279 } 276 }
280 277
281 // return: how many unplayed bytes are in the buffer 278 // return: delay in seconds between first and last sample in buffer
282 static int get_delay(){ 279 static float get_delay(){
283 return buffered_bytes + ao_buffersize; 280 return (float)(buffered_bytes + ao_data.buffersize)/(float)ao_data.bps;
284 } 281 }
285 282
286 283
287 284
288 285
289 286
290 287