Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

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.  :)
  • Loading branch information
icculus committed Oct 4, 2006
1 parent 6c27348 commit 614de8336b41fce0ec4de70a1930c15733e4d2b9
@@ -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;
@@ -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 */
@@ -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 */
@@ -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 */
@@ -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 */
@@ -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: */
@@ -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 */
@@ -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
@@ -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 */
@@ -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
};


@@ -102,7 +102,7 @@ Audio_CreateDevice(int devindex)

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


@@ -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
};


@@ -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: */
@@ -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 */
@@ -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
@@ -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;
@@ -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
};


@@ -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)
{
@@ -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;
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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 */
@@ -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 */
@@ -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 */
@@ -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

0 comments on commit 614de83

Please sign in to comment.