Mercurial > sdl-ios-xcode
comparison src/audio/SDL_audio.c @ 3801:e17a59e6aff6 SDL-ryan-multiple-audio-device
Removed AmigaOS audio driver from 1.3; it hasn't compiled for years, and it
adds a lot of cruft to the core.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Wed, 04 Oct 2006 21:54:57 +0000 |
parents | c8b3d3d13ed1 |
children | cef5d927591f |
comparison
equal
deleted
inserted
replaced
3800:2d77a732bd20 | 3801:e17a59e6aff6 |
---|---|
65 extern AudioBootStrap WAVEOUT_bootstrap; | 65 extern AudioBootStrap WAVEOUT_bootstrap; |
66 extern AudioBootStrap Paud_bootstrap; | 66 extern AudioBootStrap Paud_bootstrap; |
67 extern AudioBootStrap BAUDIO_bootstrap; | 67 extern AudioBootStrap BAUDIO_bootstrap; |
68 extern AudioBootStrap COREAUDIO_bootstrap; | 68 extern AudioBootStrap COREAUDIO_bootstrap; |
69 extern AudioBootStrap SNDMGR_bootstrap; | 69 extern AudioBootStrap SNDMGR_bootstrap; |
70 extern AudioBootStrap AHI_bootstrap; | |
71 extern AudioBootStrap MINTAUDIO_GSXB_bootstrap; | 70 extern AudioBootStrap MINTAUDIO_GSXB_bootstrap; |
72 extern AudioBootStrap MINTAUDIO_MCSN_bootstrap; | 71 extern AudioBootStrap MINTAUDIO_MCSN_bootstrap; |
73 extern AudioBootStrap MINTAUDIO_STFA_bootstrap; | 72 extern AudioBootStrap MINTAUDIO_STFA_bootstrap; |
74 extern AudioBootStrap MINTAUDIO_XBIOS_bootstrap; | 73 extern AudioBootStrap MINTAUDIO_XBIOS_bootstrap; |
75 extern AudioBootStrap MINTAUDIO_DMA8_bootstrap; | 74 extern AudioBootStrap MINTAUDIO_DMA8_bootstrap; |
126 &COREAUDIO_bootstrap, | 125 &COREAUDIO_bootstrap, |
127 #endif | 126 #endif |
128 #if SDL_AUDIO_DRIVER_SNDMGR | 127 #if SDL_AUDIO_DRIVER_SNDMGR |
129 &SNDMGR_bootstrap, | 128 &SNDMGR_bootstrap, |
130 #endif | 129 #endif |
131 #if SDL_AUDIO_DRIVER_AHI | |
132 &AHI_bootstrap, | |
133 #endif | |
134 #if SDL_AUDIO_DRIVER_MINT | 130 #if SDL_AUDIO_DRIVER_MINT |
135 &MINTAUDIO_GSXB_bootstrap, | 131 &MINTAUDIO_GSXB_bootstrap, |
136 &MINTAUDIO_MCSN_bootstrap, | 132 &MINTAUDIO_MCSN_bootstrap, |
137 &MINTAUDIO_STFA_bootstrap, | 133 &MINTAUDIO_STFA_bootstrap, |
138 &MINTAUDIO_XBIOS_bootstrap, | 134 &MINTAUDIO_XBIOS_bootstrap, |
153 #if SDL_AUDIO_DRIVER_DART | 149 #if SDL_AUDIO_DRIVER_DART |
154 &DART_bootstrap, | 150 &DART_bootstrap, |
155 #endif | 151 #endif |
156 NULL | 152 NULL |
157 }; | 153 }; |
158 | |
159 #if SDL_AUDIO_DRIVER_AHI | |
160 static int audio_configured = 0; | |
161 #endif | |
162 | 154 |
163 static SDL_AudioDevice *get_audio_device(SDL_AudioDeviceID id) | 155 static SDL_AudioDevice *get_audio_device(SDL_AudioDeviceID id) |
164 { | 156 { |
165 id--; | 157 id--; |
166 if ( (id >= SDL_arraysize(open_devices)) || (open_devices[id] == NULL) ) { | 158 if ( (id >= SDL_arraysize(open_devices)) || (open_devices[id] == NULL) ) { |
250 int stream_len; | 242 int stream_len; |
251 void *udata; | 243 void *udata; |
252 void (SDLCALL * fill) (void *userdata, Uint8 * stream, int len); | 244 void (SDLCALL * fill) (void *userdata, Uint8 * stream, int len); |
253 int silence; | 245 int silence; |
254 | 246 |
255 /* !!! FIXME: can we push this into the Amiga driver? */ | |
256 #if SDL_AUDIO_DRIVER_AHI | |
257 #error this is probably broken. | |
258 int started = 0; | |
259 | |
260 /* AmigaOS NEEDS that the audio driver is opened in the thread that uses it! */ | |
261 | |
262 D(bug("Task audio started audio struct:<%lx>...\n", audiop)); | |
263 | |
264 D(bug("Before Openaudio...")); | |
265 if (audio->OpenAudio(audio, &audio->spec) == -1) { | |
266 D(bug("Open audio failed...\n")); | |
267 return (-1); | |
268 } | |
269 D(bug("OpenAudio...OK\n")); | |
270 #endif | |
271 | |
272 /* Perform any thread setup */ | 247 /* Perform any thread setup */ |
273 device->threadid = SDL_ThreadID(); | 248 device->threadid = SDL_ThreadID(); |
274 current_audio.impl.ThreadInit(device); | 249 current_audio.impl.ThreadInit(device); |
275 | 250 |
276 /* Set up the mixing function */ | 251 /* Set up the mixing function */ |
277 fill = device->spec.callback; | 252 fill = device->spec.callback; |
278 udata = device->spec.userdata; | 253 udata = device->spec.userdata; |
279 | |
280 #if SDL_AUDIO_DRIVER_AHI | |
281 audio_configured = 1; | |
282 | |
283 D(bug("Audio configured... Checking for conversion\n")); | |
284 SDL_mutexP(audio->mixer_lock); | |
285 D(bug("Semaphore obtained...\n")); | |
286 #endif | |
287 | 254 |
288 if (device->convert.needed) { | 255 if (device->convert.needed) { |
289 if (device->convert.src_format == AUDIO_U8) { | 256 if (device->convert.src_format == AUDIO_U8) { |
290 silence = 0x80; | 257 silence = 0x80; |
291 } else { | 258 } else { |
294 stream_len = device->convert.len; | 261 stream_len = device->convert.len; |
295 } else { | 262 } else { |
296 silence = device->spec.silence; | 263 silence = device->spec.silence; |
297 stream_len = device->spec.size; | 264 stream_len = device->spec.size; |
298 } | 265 } |
299 | |
300 #if SDL_AUDIO_DRIVER_AHI | |
301 SDL_mutexV(device->mixer_lock); | |
302 D(bug("Entering audio loop...\n")); | |
303 #endif | |
304 | 266 |
305 /* Loop, filling the audio buffers */ | 267 /* Loop, filling the audio buffers */ |
306 while (device->enabled) { | 268 while (device->enabled) { |
307 | 269 |
308 /* Fill the current buffer with sound */ | 270 /* Fill the current buffer with sound */ |
353 } | 315 } |
354 } | 316 } |
355 | 317 |
356 /* Wait for the audio to drain.. */ | 318 /* Wait for the audio to drain.. */ |
357 current_audio.impl.WaitDone(device); | 319 current_audio.impl.WaitDone(device); |
358 | |
359 /* !!! FIXME: get this out of core. */ | |
360 #if SDL_AUDIO_DRIVER_AHI | |
361 D(bug("WaitDevice...Done\n")); | |
362 current_audio.impl.CloseDevice(device); | |
363 device->opened = 0; | |
364 D(bug("CloseDevice..Done, subtask exiting...\n")); | |
365 audio_configured = 0; | |
366 #endif | |
367 | 320 |
368 return (0); | 321 return (0); |
369 } | 322 } |
370 | 323 |
371 | 324 |
746 SDL_SetError("Couldn't create mixer lock"); | 699 SDL_SetError("Couldn't create mixer lock"); |
747 return 0; | 700 return 0; |
748 } | 701 } |
749 } | 702 } |
750 | 703 |
751 /* !!! FIXME: Get this #if out of the core. */ | |
752 /* AmigaOS opens audio inside the main loop */ | |
753 #if !SDL_AUDIO_DRIVER_AHI | |
754 if (!current_audio.impl.OpenDevice(device, devname, iscapture)) { | 704 if (!current_audio.impl.OpenDevice(device, devname, iscapture)) { |
755 close_audio_device(device); | 705 close_audio_device(device); |
756 return 0; | 706 return 0; |
757 } | 707 } |
758 device->opened = 1; | 708 device->opened = 1; |
759 #else | |
760 # error needs to be fixed for new internal API. Email Ryan for details. | |
761 | |
762 D(bug("Locking semaphore...")); | |
763 SDL_mutexP(audio->mixer_lock); | |
764 | |
765 | |
766 audio->thread = SDL_CreateThread(SDL_RunAudio, audio); | |
767 D(bug("Created thread...\n")); | |
768 | |
769 if (audio->thread == NULL) { | |
770 SDL_mutexV(audio->mixer_lock); | |
771 SDL_CloseAudio(); | |
772 SDL_SetError("Couldn't create audio thread"); | |
773 return 0; | |
774 } | |
775 | |
776 while (!audio_configured) | |
777 SDL_Delay(100); | |
778 #endif | |
779 | 709 |
780 /* If the audio driver changes the buffer size, accept it */ | 710 /* If the audio driver changes the buffer size, accept it */ |
781 if (device->spec.samples != desired.samples) { | 711 if (device->spec.samples != desired.samples) { |
782 desired.samples = device->spec.samples; | 712 desired.samples = device->spec.samples; |
783 SDL_CalculateAudioSpec(&device->spec); | 713 SDL_CalculateAudioSpec(&device->spec); |
832 SDL_SetError("Too many open audio devices"); | 762 SDL_SetError("Too many open audio devices"); |
833 close_audio_device(device); | 763 close_audio_device(device); |
834 return 0; | 764 return 0; |
835 } | 765 } |
836 | 766 |
837 /* !!! FIXME: get this out of core. */ | |
838 #if !SDL_AUDIO_DRIVER_AHI | |
839 /* Start the audio thread if necessary */ | 767 /* Start the audio thread if necessary */ |
840 if (!current_audio.impl.ProvidesOwnCallbackThread) { | 768 if (!current_audio.impl.ProvidesOwnCallbackThread) { |
841 /* Start the audio thread */ | 769 /* Start the audio thread */ |
842 /* !!! FIXME: this is nasty. */ | 770 /* !!! FIXME: this is nasty. */ |
843 #if (defined(__WIN32__) && !defined(_WIN32_WCE)) && !defined(HAVE_LIBC) | 771 #if (defined(__WIN32__) && !defined(_WIN32_WCE)) && !defined(HAVE_LIBC) |
850 SDL_CloseAudioDevice(id+1); | 778 SDL_CloseAudioDevice(id+1); |
851 SDL_SetError("Couldn't create audio thread"); | 779 SDL_SetError("Couldn't create audio thread"); |
852 return 0; | 780 return 0; |
853 } | 781 } |
854 } | 782 } |
855 | |
856 #else | |
857 SDL_mutexV(audio->mixer_lock); | |
858 D(bug("SDL_OpenAudio USCITA...\n")); | |
859 | |
860 #endif | |
861 | 783 |
862 return id+1; | 784 return id+1; |
863 } | 785 } |
864 | 786 |
865 | 787 |