changeset 3798:c8b3d3d13ed1 SDL-ryan-multiple-audio-device

Audio bootstraps can now specify that a driver is only to be used if explicitly requested (for things like the "disk" driver that is always available but you would never want to default to using). Trimmed out code that can be handled by stubs in the core. The "dummy" driver is pretty damned small now. :)
author Ryan C. Gordon <icculus@icculus.org>
date Wed, 04 Oct 2006 21:27:53 +0000
parents 9dc81c6acaf5
children f424927138ff
files src/audio/SDL_audio.c src/audio/SDL_sysaudio.h src/audio/alsa/SDL_alsa_audio.c src/audio/arts/SDL_artsaudio.c src/audio/bsd/SDL_bsdaudio.c src/audio/dart/SDL_dart.c src/audio/dc/SDL_dcaudio.c src/audio/disk/SDL_diskaudio.c src/audio/dma/SDL_dmaaudio.c src/audio/dmedia/SDL_irixaudio.c src/audio/dsp/SDL_dspaudio.c src/audio/dummy/SDL_dummyaudio.c src/audio/esd/SDL_esdaudio.c src/audio/macosx/SDL_coreaudio.c src/audio/macrom/SDL_romaudio.c src/audio/mint/SDL_mintaudio_dma8.c src/audio/mint/SDL_mintaudio_gsxb.c src/audio/mint/SDL_mintaudio_mcsn.c src/audio/mint/SDL_mintaudio_stfa.c src/audio/mint/SDL_mintaudio_xbios.c src/audio/mme/SDL_mmeaudio.c src/audio/nas/SDL_nasaudio.c src/audio/nto/SDL_nto_audio.c src/audio/paudio/SDL_paudio.c src/audio/sun/SDL_sunaudio.c src/audio/ums/SDL_umsaudio.c src/audio/windib/SDL_dibaudio.c src/audio/windx5/SDL_dx5audio.c
diffstat 28 files changed, 33 insertions(+), 140 deletions(-) [+]
line wrap: on
line diff
--- a/src/audio/SDL_audio.c	Wed Oct 04 20:42:39 2006 +0000
+++ b/src/audio/SDL_audio.c	Wed Oct 04 21:27:53 2006 +0000
@@ -480,7 +480,7 @@
             }
         } else {
             for (i = 0; (!initialized) && (bootstrap[i]); ++i) {
-                if (bootstrap[i]->available()) {
+                if ((!bootstrap[i]->demand) && (bootstrap[i]->available())) {
                     SDL_memset(&current_audio, 0, sizeof (current_audio));
                     current_audio.name = bootstrap[i]->name;
                     current_audio.desc = bootstrap[i]->desc;
--- a/src/audio/SDL_sysaudio.h	Wed Oct 04 20:42:39 2006 +0000
+++ b/src/audio/SDL_sysaudio.h	Wed Oct 04 21:27:53 2006 +0000
@@ -109,6 +109,7 @@
     const char *desc;
     int (*available) (void);
     int (*init) (SDL_AudioDriverImpl *impl);
+    int demand:1;  /* 1==must request explicitly, or it won't be available. */
 } AudioBootStrap;
 
 #endif /* _SDL_sysaudio_h */
--- a/src/audio/alsa/SDL_alsa_audio.c	Wed Oct 04 20:42:39 2006 +0000
+++ b/src/audio/alsa/SDL_alsa_audio.c	Wed Oct 04 21:27:53 2006 +0000
@@ -330,7 +330,7 @@
 
 AudioBootStrap ALSA_bootstrap = {
     DRIVER_NAME, "ALSA 0.9 PCM audio",
-    Audio_Available, Audio_CreateDevice
+    Audio_Available, Audio_CreateDevice, 0
 };
 
 /* This function waits until it is possible to write a full sound buffer */
--- a/src/audio/arts/SDL_artsaudio.c	Wed Oct 04 20:42:39 2006 +0000
+++ b/src/audio/arts/SDL_artsaudio.c	Wed Oct 04 21:27:53 2006 +0000
@@ -199,7 +199,7 @@
 
 AudioBootStrap ARTS_bootstrap = {
     ARTS_DRIVER_NAME, "Analog Realtime Synthesizer",
-    Audio_Available, Audio_CreateDevice
+    Audio_Available, Audio_CreateDevice, 0
 };
 
 /* This function waits until it is possible to write a full sound buffer */
--- a/src/audio/bsd/SDL_bsdaudio.c	Wed Oct 04 20:42:39 2006 +0000
+++ b/src/audio/bsd/SDL_bsdaudio.c	Wed Oct 04 21:27:53 2006 +0000
@@ -136,7 +136,7 @@
 
 AudioBootStrap BSD_AUDIO_bootstrap = {
     BSD_AUDIO_DRIVER_NAME, BSD_AUDIO_DRIVER_DESC,
-    Audio_Available, Audio_CreateDevice
+    Audio_Available, Audio_CreateDevice, 0
 };
 
 /* This function waits until it is possible to write a full sound buffer */
--- a/src/audio/dart/SDL_dart.c	Wed Oct 04 20:42:39 2006 +0000
+++ b/src/audio/dart/SDL_dart.c	Wed Oct 04 21:27:53 2006 +0000
@@ -484,7 +484,7 @@
 
 AudioBootStrap DART_bootstrap = {
     "dart", "OS/2 Direct Audio RouTines (DART)",
-    Audio_Available, Audio_CreateDevice
+    Audio_Available, Audio_CreateDevice, 0
 };
 
 /* vi: set ts=4 sw=4 expandtab: */
--- a/src/audio/dc/SDL_dcaudio.c	Wed Oct 04 20:42:39 2006 +0000
+++ b/src/audio/dc/SDL_dcaudio.c	Wed Oct 04 21:27:53 2006 +0000
@@ -92,7 +92,7 @@
 
 AudioBootStrap DCAUD_bootstrap = {
     "dcaudio", "Dreamcast AICA audio",
-    DCAUD_Available, DCAUD_CreateDevice
+    DCAUD_Available, DCAUD_CreateDevice, 0
 };
 
 /* This function waits until it is possible to write a full sound buffer */
--- a/src/audio/disk/SDL_diskaudio.c	Wed Oct 04 20:42:39 2006 +0000
+++ b/src/audio/disk/SDL_diskaudio.c	Wed Oct 04 21:27:53 2006 +0000
@@ -64,13 +64,7 @@
 static int
 DISKAUD_Available(void)
 {
-    /* !!! FIXME: check this at a higher level... */
-    /* only ever use this driver if explicitly requested. */
-    const char *envr = SDL_getenv("SDL_AUDIODRIVER");
-    if (envr && (SDL_strcasecmp(envr, DISKAUD_DRIVER_NAME) == 0)) {
-        return (1);
-    }
-    return (0);
+    return 1;  /* always available. */
 }
 
 static int
@@ -91,7 +85,7 @@
 
 AudioBootStrap DISKAUD_bootstrap = {
     DISKAUD_DRIVER_NAME, "direct-to-disk audio",
-    DISKAUD_Available, DISKAUD_Init
+    DISKAUD_Available, DISKAUD_Init, 1
 };
 
 /* This function waits until it is possible to write a full sound buffer */
--- a/src/audio/dma/SDL_dmaaudio.c	Wed Oct 04 20:42:39 2006 +0000
+++ b/src/audio/dma/SDL_dmaaudio.c	Wed Oct 04 21:27:53 2006 +0000
@@ -117,7 +117,7 @@
 
 AudioBootStrap DMA_bootstrap = {
     DMA_DRIVER_NAME, "OSS /dev/dsp DMA audio",
-    DMA_Available, DMA_Init
+    DMA_Available, DMA_Init, 0
 };
 
 
--- a/src/audio/dmedia/SDL_irixaudio.c	Wed Oct 04 20:42:39 2006 +0000
+++ b/src/audio/dmedia/SDL_irixaudio.c	Wed Oct 04 21:27:53 2006 +0000
@@ -102,7 +102,7 @@
 
 AudioBootStrap DMEDIA_bootstrap = {
     "AL", "IRIX DMedia audio",
-    Audio_Available, Audio_CreateDevice
+    Audio_Available, Audio_CreateDevice, 0
 };
 
 
--- a/src/audio/dsp/SDL_dspaudio.c	Wed Oct 04 20:42:39 2006 +0000
+++ b/src/audio/dsp/SDL_dspaudio.c	Wed Oct 04 21:27:53 2006 +0000
@@ -103,7 +103,7 @@
 
 AudioBootStrap DSP_bootstrap = {
     DSP_DRIVER_NAME, "OSS /dev/dsp standard audio",
-    DSP_Available, DSP_Init
+    DSP_Available, DSP_Init, 0
 };
 
 
--- a/src/audio/dummy/SDL_dummyaudio.c	Wed Oct 04 20:42:39 2006 +0000
+++ b/src/audio/dummy/SDL_dummyaudio.c	Wed Oct 04 21:27:53 2006 +0000
@@ -47,13 +47,7 @@
 static int
 DUMMYAUD_Available(void)
 {
-    /* !!! FIXME: check this at a higher level... */
-    /* only ever use this driver if explicitly requested. */
-    const char *envr = SDL_getenv("SDL_AUDIODRIVER");
-    if (envr && (SDL_strcmp(envr, DUMMYAUD_DRIVER_NAME) == 0)) {
-        return (1);
-    }
-    return (0);
+    return 1;  /* always available. */
 }
 
 static int
@@ -61,10 +55,6 @@
 {
     /* Set the function pointers */
     impl->OpenDevice = DUMMYAUD_OpenDevice;
-    impl->WaitDevice = DUMMYAUD_WaitDevice;
-    impl->PlayDevice = DUMMYAUD_PlayDevice;
-    impl->GetDeviceBuf = DUMMYAUD_GetDeviceBuf;
-    impl->CloseDevice = DUMMYAUD_CloseDevice;
     impl->OnlyHasDefaultOutputDevice = 1;
 
     return 1;
@@ -72,82 +62,13 @@
 
 AudioBootStrap DUMMYAUD_bootstrap = {
     DUMMYAUD_DRIVER_NAME, "SDL dummy audio driver",
-    DUMMYAUD_Available, DUMMYAUD_Init
+    DUMMYAUD_Available, DUMMYAUD_Init, 1
 };
 
-/* This function waits until it is possible to write a full sound buffer */
-static void
-DUMMYAUD_WaitDevice(_THIS)
-{
-    /* Don't block on first calls to simulate initial fragment filling. */
-    if (this->hidden->initial_calls)
-        this->hidden->initial_calls--;
-    else
-        SDL_Delay(this->hidden->write_delay);
-}
-
-static void
-DUMMYAUD_PlayDevice(_THIS)
-{
-    /* no-op...this is a null driver. */
-}
-
-static Uint8 *
-DUMMYAUD_GetDeviceBuf(_THIS)
-{
-    return (this->hidden->mixbuf);
-}
-
-static void
-DUMMYAUD_CloseDevice(_THIS)
-{
-    if (this->hidden->mixbuf != NULL) {
-        SDL_FreeAudioMem(this->hidden->mixbuf);
-        this->hidden->mixbuf = NULL;
-    }
-    SDL_free(this->hidden);
-    this->hidden = NULL;
-}
-
 static int
 DUMMYAUD_OpenDevice(_THIS, const char *devname, int iscapture)
 {
-    float bytes_per_sec = 0.0f;
-
-    /* Initialize all variables that we clean on shutdown */
-    this->hidden = (struct SDL_PrivateAudioData *)
-                    SDL_malloc((sizeof *this->hidden));
-    if (this->hidden == NULL) {
-        SDL_OutOfMemory();
-        return 0;
-    }
-    SDL_memset(this->hidden, 0, (sizeof *this->hidden));
-
-    /* Allocate mixing buffer */
-    this->hidden->mixlen = this->spec.size;
-    this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen);
-    if (this->hidden->mixbuf == NULL) {
-        DUMMYAUD_CloseDevice(this);
-        return 0;
-    }
-    SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size);
-
-    bytes_per_sec = (float) (SDL_AUDIO_BITSIZE(this->spec.format) / 8) *
-                             this->spec.channels * this->spec.freq;
-
-    /*
-     * We try to make this request more audio at the correct rate for
-     *  a given audio spec, so timing stays fairly faithful.
-     * Also, we have it not block at all for the first two calls, so
-     *  it seems like we're filling two audio fragments right out of the
-     *  gate, like other SDL drivers tend to do.
-     */
-    this->hidden->initial_calls = 2;
-    this->hidden->write_delay =
-        (Uint32) ((((float) this->spec.size) / bytes_per_sec) * 1000.0f);
-
-    /* We're ready to rock and roll. :-) */
-    return 1;
+    return 1;   /* always succeeds. */
 }
 
 /* vi: set ts=4 sw=4 expandtab: */
--- a/src/audio/esd/SDL_esdaudio.c	Wed Oct 04 20:42:39 2006 +0000
+++ b/src/audio/esd/SDL_esdaudio.c	Wed Oct 04 21:27:53 2006 +0000
@@ -187,7 +187,7 @@
 
 AudioBootStrap ESD_bootstrap = {
     ESD_DRIVER_NAME, "Enlightened Sound Daemon",
-    Audio_Available, Audio_CreateDevice
+    Audio_Available, Audio_CreateDevice, 0
 };
 
 /* This function waits until it is possible to write a full sound buffer */
--- a/src/audio/macosx/SDL_coreaudio.c	Wed Oct 04 20:42:39 2006 +0000
+++ b/src/audio/macosx/SDL_coreaudio.c	Wed Oct 04 21:27:53 2006 +0000
@@ -218,7 +218,7 @@
 static int
 COREAUDIO_Available(void)
 {
-    return (1);
+    return 1;  /* always available on Mac OS X. */
 }
 
 static int
@@ -228,9 +228,6 @@
     impl->DetectDevices = COREAUDIO_DetectDevices;
     impl->GetDeviceName = COREAUDIO_GetDeviceName;
     impl->OpenDevice = COREAUDIO_OpenDevice;
-    impl->WaitDevice = COREAUDIO_WaitDevice;
-    impl->PlayDevice = COREAUDIO_PlayDevice;
-    impl->GetDeviceBuf = COREAUDIO_GetDeviceBuf;
     impl->CloseDevice = COREAUDIO_CloseDevice;
     impl->Deinitialize = COREAUDIO_Deinitialize;
     impl->ProvidesOwnCallbackThread = 1;
@@ -239,7 +236,7 @@
 
 AudioBootStrap COREAUDIO_bootstrap = {
     "coreaudio", "Mac OS X CoreAudio",
-    COREAUDIO_Available, COREAUDIO_Init
+    COREAUDIO_Available, COREAUDIO_Init, 0
 };
 
 
@@ -355,25 +352,6 @@
 }
 
 
-/* Dummy functions -- we don't use thread-based audio */
-static void
-COREAUDIO_WaitDevice(_THIS)
-{
-    return;
-}
-
-static void
-COREAUDIO_PlayDevice(_THIS)
-{
-    return;
-}
-
-static Uint8 *
-COREAUDIO_GetDeviceBuf(_THIS)
-{
-    return (NULL);
-}
-
 static void
 COREAUDIO_CloseDevice(_THIS)
 {
--- a/src/audio/macrom/SDL_romaudio.c	Wed Oct 04 20:42:39 2006 +0000
+++ b/src/audio/macrom/SDL_romaudio.c	Wed Oct 04 21:27:53 2006 +0000
@@ -70,8 +70,6 @@
 SNDMGR_Init(SDL_AudioDriverImpl *impl)
 {
     /* Set the function pointers */
-    impl->DetectDevices = SNDMGR_DetectDevices;
-    impl->GetDeviceName = SNDMGR_GetDeviceName;
     impl->OpenDevice = SNDMGR_OpenDevice;
     impl->CloseDevice = SNDMGR_CloseDevice;
     impl->ProvidesOwnCallbackThread = 1;
@@ -87,7 +85,7 @@
 
 AudioBootStrap SNDMGR_bootstrap = {
     "sndmgr", SDL_MACOS_NAME " SoundManager",
-    SNDMGR_Available, SNDMGR_Init
+    SNDMGR_Available, SNDMGR_Init, 0
 };
 
 #pragma options align=power
--- a/src/audio/mint/SDL_mintaudio_dma8.c	Wed Oct 04 20:42:39 2006 +0000
+++ b/src/audio/mint/SDL_mintaudio_dma8.c	Wed Oct 04 21:27:53 2006 +0000
@@ -160,7 +160,7 @@
 
 AudioBootStrap MINTAUDIO_DMA8_bootstrap = {
     MINT_AUDIO_DRIVER_NAME, "MiNT DMA 8 bits audio driver",
-    Audio_Available, Audio_CreateDevice
+    Audio_Available, Audio_CreateDevice, 0
 };
 
 static void
--- a/src/audio/mint/SDL_mintaudio_gsxb.c	Wed Oct 04 20:42:39 2006 +0000
+++ b/src/audio/mint/SDL_mintaudio_gsxb.c	Wed Oct 04 21:27:53 2006 +0000
@@ -166,7 +166,7 @@
 
 AudioBootStrap MINTAUDIO_GSXB_bootstrap = {
     MINT_AUDIO_DRIVER_NAME, "MiNT GSXB audio driver",
-    Audio_Available, Audio_CreateDevice
+    Audio_Available, Audio_CreateDevice, 0
 };
 
 static void
--- a/src/audio/mint/SDL_mintaudio_mcsn.c	Wed Oct 04 20:42:39 2006 +0000
+++ b/src/audio/mint/SDL_mintaudio_mcsn.c	Wed Oct 04 21:27:53 2006 +0000
@@ -181,7 +181,7 @@
 
 AudioBootStrap MINTAUDIO_MCSN_bootstrap = {
     MINT_AUDIO_DRIVER_NAME, "MiNT MCSN audio driver",
-    Audio_Available, Audio_CreateDevice
+    Audio_Available, Audio_CreateDevice, 0
 };
 
 static void
--- a/src/audio/mint/SDL_mintaudio_stfa.c	Wed Oct 04 20:42:39 2006 +0000
+++ b/src/audio/mint/SDL_mintaudio_stfa.c	Wed Oct 04 21:27:53 2006 +0000
@@ -160,7 +160,7 @@
 
 AudioBootStrap MINTAUDIO_STFA_bootstrap = {
     MINT_AUDIO_DRIVER_NAME, "MiNT STFA audio driver",
-    Audio_Available, Audio_CreateDevice
+    Audio_Available, Audio_CreateDevice, 0
 };
 
 static void
--- a/src/audio/mint/SDL_mintaudio_xbios.c	Wed Oct 04 20:42:39 2006 +0000
+++ b/src/audio/mint/SDL_mintaudio_xbios.c	Wed Oct 04 21:27:53 2006 +0000
@@ -165,7 +165,7 @@
 
 AudioBootStrap MINTAUDIO_XBIOS_bootstrap = {
     MINT_AUDIO_DRIVER_NAME, "MiNT XBIOS audio driver",
-    Audio_Available, Audio_CreateDevice
+    Audio_Available, Audio_CreateDevice, 0
 };
 
 static void
--- a/src/audio/mme/SDL_mmeaudio.c	Wed Oct 04 20:42:39 2006 +0000
+++ b/src/audio/mme/SDL_mmeaudio.c	Wed Oct 04 21:27:53 2006 +0000
@@ -92,7 +92,7 @@
 
 AudioBootStrap MMEAUDIO_bootstrap = {
     "waveout", "Tru64 MME WaveOut",
-    Audio_Available, Audio_CreateDevice
+    Audio_Available, Audio_CreateDevice, 0
 };
 
 static void
--- a/src/audio/nas/SDL_nasaudio.c	Wed Oct 04 20:42:39 2006 +0000
+++ b/src/audio/nas/SDL_nasaudio.c	Wed Oct 04 21:27:53 2006 +0000
@@ -104,7 +104,7 @@
 
 AudioBootStrap NAS_bootstrap = {
     NAS_DRIVER_NAME, "Network Audio System",
-    Audio_Available, Audio_CreateDevice
+    Audio_Available, Audio_CreateDevice, 0
 };
 
 /* This function waits until it is possible to write a full sound buffer */
--- a/src/audio/nto/SDL_nto_audio.c	Wed Oct 04 20:42:39 2006 +0000
+++ b/src/audio/nto/SDL_nto_audio.c	Wed Oct 04 21:27:53 2006 +0000
@@ -212,7 +212,8 @@
 AudioBootStrap QNXNTOAUDIO_bootstrap = {
     DRIVER_NAME, "QNX6 QSA-NTO Audio",
     NTO_AudioAvailable,
-    NTO_CreateAudioDevice
+    NTO_CreateAudioDevice,
+    0
 };
 
 /* This function waits until it is possible to write a full sound buffer */
--- a/src/audio/paudio/SDL_paudio.c	Wed Oct 04 20:42:39 2006 +0000
+++ b/src/audio/paudio/SDL_paudio.c	Wed Oct 04 21:27:53 2006 +0000
@@ -121,7 +121,7 @@
 
 AudioBootStrap Paud_bootstrap = {
     Paud_DRIVER_NAME, "AIX Paudio",
-    Audio_Available, Audio_CreateDevice
+    Audio_Available, Audio_CreateDevice, 0
 };
 
 /* This function waits until it is possible to write a full sound buffer */
--- a/src/audio/sun/SDL_sunaudio.c	Wed Oct 04 20:42:39 2006 +0000
+++ b/src/audio/sun/SDL_sunaudio.c	Wed Oct 04 21:27:53 2006 +0000
@@ -116,7 +116,7 @@
 
 AudioBootStrap SUNAUDIO_bootstrap = {
     "audio", "UNIX /dev/audio interface",
-    Audio_Available, Audio_CreateDevice
+    Audio_Available, Audio_CreateDevice, 0
 };
 
 #ifdef DEBUG_AUDIO
--- a/src/audio/ums/SDL_umsaudio.c	Wed Oct 04 20:42:39 2006 +0000
+++ b/src/audio/ums/SDL_umsaudio.c	Wed Oct 04 21:27:53 2006 +0000
@@ -152,7 +152,7 @@
 
 AudioBootStrap UMS_bootstrap = {
     UMS_DRIVER_NAME, "AIX UMS audio",
-    Audio_Available, Audio_CreateDevice
+    Audio_Available, Audio_CreateDevice, 0
 };
 
 static Uint8 *
--- a/src/audio/windib/SDL_dibaudio.c	Wed Oct 04 20:42:39 2006 +0000
+++ b/src/audio/windib/SDL_dibaudio.c	Wed Oct 04 21:27:53 2006 +0000
@@ -97,7 +97,7 @@
 
 AudioBootStrap WAVEOUT_bootstrap = {
     "waveout", "Win95/98/NT/2000 WaveOut",
-    Audio_Available, Audio_CreateDevice
+    Audio_Available, Audio_CreateDevice, 0
 };
 
 
--- a/src/audio/windx5/SDL_dx5audio.c	Wed Oct 04 20:42:39 2006 +0000
+++ b/src/audio/windx5/SDL_dx5audio.c	Wed Oct 04 21:27:53 2006 +0000
@@ -180,7 +180,7 @@
 
 AudioBootStrap DSOUND_bootstrap = {
     "dsound", "Win95/98/2000 DirectSound",
-    Audio_Available, Audio_CreateDevice
+    Audio_Available, Audio_CreateDevice, 0
 };
 
 static void