Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Audio bootstraps can now specify that a driver is only to be used if
Browse files Browse the repository at this point in the history
 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.  :)
  • Loading branch information
icculus committed Oct 4, 2006
1 parent 6c27348 commit 614de83
Show file tree
Hide file tree
Showing 28 changed files with 33 additions and 140 deletions.
2 changes: 1 addition & 1 deletion src/audio/SDL_audio.c
Expand Up @@ -480,7 +480,7 @@ SDL_AudioInit(const char *driver_name)
}
} 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;
Expand Down
1 change: 1 addition & 0 deletions src/audio/SDL_sysaudio.h
Expand Up @@ -109,6 +109,7 @@ typedef struct AudioBootStrap
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 */
Expand Down
2 changes: 1 addition & 1 deletion src/audio/alsa/SDL_alsa_audio.c
Expand Up @@ -330,7 +330,7 @@ Audio_CreateDevice(int devindex)

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 */
Expand Down
2 changes: 1 addition & 1 deletion src/audio/arts/SDL_artsaudio.c
Expand Up @@ -199,7 +199,7 @@ Audio_CreateDevice(int devindex)

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 */
Expand Down
2 changes: 1 addition & 1 deletion src/audio/bsd/SDL_bsdaudio.c
Expand Up @@ -136,7 +136,7 @@ Audio_CreateDevice(int devindex)

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 */
Expand Down
2 changes: 1 addition & 1 deletion src/audio/dart/SDL_dart.c
Expand Up @@ -484,7 +484,7 @@ Audio_CreateDevice(int devindex)

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: */
2 changes: 1 addition & 1 deletion src/audio/dc/SDL_dcaudio.c
Expand Up @@ -92,7 +92,7 @@ DCAUD_CreateDevice(int devindex)

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 */
Expand Down
10 changes: 2 additions & 8 deletions src/audio/disk/SDL_diskaudio.c
Expand Up @@ -64,13 +64,7 @@ DISKAUD_GetOutputFilename(void)
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
Expand All @@ -91,7 +85,7 @@ DISKAUD_Init(SDL_AudioDriverImpl *impl)

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 */
Expand Down
2 changes: 1 addition & 1 deletion src/audio/dma/SDL_dmaaudio.c
Expand Up @@ -117,7 +117,7 @@ DMA_Init(SDL_AudioDriverImpl *impl)

AudioBootStrap DMA_bootstrap = {
DMA_DRIVER_NAME, "OSS /dev/dsp DMA audio",
DMA_Available, DMA_Init
DMA_Available, DMA_Init, 0
};


Expand Down
2 changes: 1 addition & 1 deletion src/audio/dmedia/SDL_irixaudio.c
Expand Up @@ -102,7 +102,7 @@ Audio_CreateDevice(int devindex)

AudioBootStrap DMEDIA_bootstrap = {
"AL", "IRIX DMedia audio",
Audio_Available, Audio_CreateDevice
Audio_Available, Audio_CreateDevice, 0
};


Expand Down
2 changes: 1 addition & 1 deletion src/audio/dsp/SDL_dspaudio.c
Expand Up @@ -103,7 +103,7 @@ DSP_Init(SDL_AudioDriverImpl *impl)

AudioBootStrap DSP_bootstrap = {
DSP_DRIVER_NAME, "OSS /dev/dsp standard audio",
DSP_Available, DSP_Init
DSP_Available, DSP_Init, 0
};


Expand Down
85 changes: 3 additions & 82 deletions src/audio/dummy/SDL_dummyaudio.c
Expand Up @@ -47,107 +47,28 @@ static void DUMMYAUD_CloseDevice(_THIS);
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
DUMMYAUD_Init(SDL_AudioDriverImpl *impl)
{
/* 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;
}

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: */
2 changes: 1 addition & 1 deletion src/audio/esd/SDL_esdaudio.c
Expand Up @@ -187,7 +187,7 @@ Audio_CreateDevice(int devindex)

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 */
Expand Down
26 changes: 2 additions & 24 deletions src/audio/macosx/SDL_coreaudio.c
Expand Up @@ -218,7 +218,7 @@ static void COREAUDIO_Deinitialize(void);
static int
COREAUDIO_Available(void)
{
return (1);
return 1; /* always available on Mac OS X. */
}

static int
Expand All @@ -228,9 +228,6 @@ COREAUDIO_Init(SDL_AudioDriverImpl *impl)
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;
Expand All @@ -239,7 +236,7 @@ COREAUDIO_Init(SDL_AudioDriverImpl *impl)

AudioBootStrap COREAUDIO_bootstrap = {
"coreaudio", "Mac OS X CoreAudio",
COREAUDIO_Available, COREAUDIO_Init
COREAUDIO_Available, COREAUDIO_Init, 0
};


Expand Down Expand Up @@ -355,25 +352,6 @@ inputCallback(void *inRefCon,
}


/* 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)
{
Expand Down
4 changes: 1 addition & 3 deletions src/audio/macrom/SDL_romaudio.c
Expand Up @@ -70,8 +70,6 @@ static int
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;
Expand All @@ -87,7 +85,7 @@ SNDMGR_Init(SDL_AudioDriverImpl *impl)

AudioBootStrap SNDMGR_bootstrap = {
"sndmgr", SDL_MACOS_NAME " SoundManager",
SNDMGR_Available, SNDMGR_Init
SNDMGR_Available, SNDMGR_Init, 0
};

#pragma options align=power
Expand Down
2 changes: 1 addition & 1 deletion src/audio/mint/SDL_mintaudio_dma8.c
Expand Up @@ -160,7 +160,7 @@ Audio_CreateDevice(int devindex)

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
Expand Down
2 changes: 1 addition & 1 deletion src/audio/mint/SDL_mintaudio_gsxb.c
Expand Up @@ -166,7 +166,7 @@ Audio_CreateDevice(int devindex)

AudioBootStrap MINTAUDIO_GSXB_bootstrap = {
MINT_AUDIO_DRIVER_NAME, "MiNT GSXB audio driver",
Audio_Available, Audio_CreateDevice
Audio_Available, Audio_CreateDevice, 0
};

static void
Expand Down
2 changes: 1 addition & 1 deletion src/audio/mint/SDL_mintaudio_mcsn.c
Expand Up @@ -181,7 +181,7 @@ Audio_CreateDevice(int devindex)

AudioBootStrap MINTAUDIO_MCSN_bootstrap = {
MINT_AUDIO_DRIVER_NAME, "MiNT MCSN audio driver",
Audio_Available, Audio_CreateDevice
Audio_Available, Audio_CreateDevice, 0
};

static void
Expand Down
2 changes: 1 addition & 1 deletion src/audio/mint/SDL_mintaudio_stfa.c
Expand Up @@ -160,7 +160,7 @@ Audio_CreateDevice(int devindex)

AudioBootStrap MINTAUDIO_STFA_bootstrap = {
MINT_AUDIO_DRIVER_NAME, "MiNT STFA audio driver",
Audio_Available, Audio_CreateDevice
Audio_Available, Audio_CreateDevice, 0
};

static void
Expand Down
2 changes: 1 addition & 1 deletion src/audio/mint/SDL_mintaudio_xbios.c
Expand Up @@ -165,7 +165,7 @@ Audio_CreateDevice(int devindex)

AudioBootStrap MINTAUDIO_XBIOS_bootstrap = {
MINT_AUDIO_DRIVER_NAME, "MiNT XBIOS audio driver",
Audio_Available, Audio_CreateDevice
Audio_Available, Audio_CreateDevice, 0
};

static void
Expand Down
2 changes: 1 addition & 1 deletion src/audio/mme/SDL_mmeaudio.c
Expand Up @@ -92,7 +92,7 @@ Audio_CreateDevice(int devindex)

AudioBootStrap MMEAUDIO_bootstrap = {
"waveout", "Tru64 MME WaveOut",
Audio_Available, Audio_CreateDevice
Audio_Available, Audio_CreateDevice, 0
};

static void
Expand Down
2 changes: 1 addition & 1 deletion src/audio/nas/SDL_nasaudio.c
Expand Up @@ -104,7 +104,7 @@ Audio_CreateDevice(int devindex)

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 */
Expand Down
3 changes: 2 additions & 1 deletion src/audio/nto/SDL_nto_audio.c
Expand Up @@ -212,7 +212,8 @@ NTO_CreateAudioDevice(int devindex)
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 */
Expand Down
2 changes: 1 addition & 1 deletion src/audio/paudio/SDL_paudio.c
Expand Up @@ -121,7 +121,7 @@ Audio_CreateDevice(int devindex)

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 */
Expand Down
2 changes: 1 addition & 1 deletion src/audio/sun/SDL_sunaudio.c
Expand Up @@ -116,7 +116,7 @@ Audio_CreateDevice(int devindex)

AudioBootStrap SUNAUDIO_bootstrap = {
"audio", "UNIX /dev/audio interface",
Audio_Available, Audio_CreateDevice
Audio_Available, Audio_CreateDevice, 0
};

#ifdef DEBUG_AUDIO
Expand Down

0 comments on commit 614de83

Please sign in to comment.