Mercurial > sdl-ios-xcode
diff src/audio/dummy/SDL_dummyaudio.c @ 3784:37c9c4590689 SDL-ryan-multiple-audio-device
First batch of heavy lifting on supporting multiple audio devices at once.
This has a long way to go yet, most of the drivers aren't updated for the
new interfaces, and it's still got some obvious bugs, FIXMEs, and wistlist
items.
Don't use yet.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Sun, 01 Oct 2006 05:24:03 +0000 |
parents | c121d94672cb |
children | 866c310e2cb5 |
line wrap: on
line diff
--- a/src/audio/dummy/SDL_dummyaudio.c Sun Oct 01 05:21:40 2006 +0000 +++ b/src/audio/dummy/SDL_dummyaudio.c Sun Oct 01 05:24:03 2006 +0000 @@ -37,7 +37,7 @@ #define DUMMYAUD_DRIVER_NAME "dummy" /* Audio driver functions */ -static int DUMMYAUD_OpenAudio(_THIS, SDL_AudioSpec * spec); +static int DUMMYAUD_OpenAudio(_THIS, const char *devname, int iscapture); static void DUMMYAUD_WaitAudio(_THIS); static void DUMMYAUD_PlayAudio(_THIS); static Uint8 *DUMMYAUD_GetAudioBuf(_THIS); @@ -47,6 +47,8 @@ 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); @@ -54,49 +56,22 @@ return (0); } -static void -DUMMYAUD_DeleteDevice(SDL_AudioDevice * device) +static int +DUMMYAUD_Init(SDL_AudioDriverImpl *impl) { - SDL_free(device->hidden); - SDL_free(device); -} - -static SDL_AudioDevice * -DUMMYAUD_CreateDevice(int devindex) -{ - SDL_AudioDevice *this; + /* Set the function pointers */ + impl->OpenAudio = DUMMYAUD_OpenAudio; + impl->WaitAudio = DUMMYAUD_WaitAudio; + impl->PlayAudio = DUMMYAUD_PlayAudio; + impl->GetAudioBuf = DUMMYAUD_GetAudioBuf; + impl->CloseAudio = DUMMYAUD_CloseAudio; - /* Initialize all variables that we clean on shutdown */ - this = (SDL_AudioDevice *) SDL_malloc(sizeof(SDL_AudioDevice)); - if (this) { - SDL_memset(this, 0, (sizeof *this)); - this->hidden = (struct SDL_PrivateAudioData *) - SDL_malloc((sizeof *this->hidden)); - } - if ((this == NULL) || (this->hidden == NULL)) { - SDL_OutOfMemory(); - if (this) { - SDL_free(this); - } - return (0); - } - SDL_memset(this->hidden, 0, (sizeof *this->hidden)); - - /* Set the function pointers */ - this->OpenAudio = DUMMYAUD_OpenAudio; - this->WaitAudio = DUMMYAUD_WaitAudio; - this->PlayAudio = DUMMYAUD_PlayAudio; - this->GetAudioBuf = DUMMYAUD_GetAudioBuf; - this->CloseAudio = DUMMYAUD_CloseAudio; - - this->free = DUMMYAUD_DeleteDevice; - - return this; + return 1; } AudioBootStrap DUMMYAUD_bootstrap = { DUMMYAUD_DRIVER_NAME, "SDL dummy audio driver", - DUMMYAUD_Available, DUMMYAUD_CreateDevice + DUMMYAUD_Available, DUMMYAUD_Init }; /* This function waits until it is possible to write a full sound buffer */ @@ -129,23 +104,35 @@ SDL_FreeAudioMem(this->hidden->mixbuf); this->hidden->mixbuf = NULL; } + SDL_free(this->hidden); + this->hidden = NULL; } static int -DUMMYAUD_OpenAudio(_THIS, SDL_AudioSpec * spec) +DUMMYAUD_OpenAudio(_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 = spec->size; + this->hidden->mixlen = this->spec.size; this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen); if (this->hidden->mixbuf == NULL) { - return (-1); + DUMMYAUD_CloseAudio(this); + return 0; } - SDL_memset(this->hidden->mixbuf, spec->silence, spec->size); + SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size); - bytes_per_sec = (float) (((spec->format & 0xFF) / 8) * - spec->channels * spec->freq); + 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 @@ -156,10 +143,10 @@ */ this->hidden->initial_calls = 2; this->hidden->write_delay = - (Uint32) ((((float) spec->size) / bytes_per_sec) * 1000.0f); + (Uint32) ((((float) this->spec.size) / bytes_per_sec) * 1000.0f); /* We're ready to rock and roll. :-) */ - return (0); + return 1; } /* vi: set ts=4 sw=4 expandtab: */