From 43d98235fd5e0680142ff6cbaf3857fdaa90f1c9 Mon Sep 17 00:00:00 2001 From: Aaron Culliney Date: Tue, 16 Jun 2015 21:33:31 -0700 Subject: [PATCH] Refactor : cleaned up a bit of deadcode --- src/audio/soundcore.c | 69 +++++++++++++------------------------------ 1 file changed, 20 insertions(+), 49 deletions(-) diff --git a/src/audio/soundcore.c b/src/audio/soundcore.c index eb0f64db..f84d78ae 100644 --- a/src/audio/soundcore.c +++ b/src/audio/soundcore.c @@ -35,15 +35,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA static char **sound_devices = NULL; static long num_sound_devices = 0; -static AudioContext_s *g_lpDS = NULL; - -//------------------------------------- - -// Used for muting & fading: - -#define uMAX_VOICES 66 -static unsigned int g_uNumVoices = 0; -static AudioBuffer_s* g_pVoices[uMAX_VOICES] = {NULL}; +static AudioContext_s *audioContext = NULL; //------------------------------------- @@ -85,8 +77,7 @@ bool DSGetLock(AudioBuffer_s *pVoice, unsigned long dwOffset, unsigned long dwBy //----------------------------------------------------------------------------- -long DSGetSoundBuffer(INOUT AudioBuffer_s **pVoice, unsigned long dwFlags, unsigned long dwBufferSize, unsigned long nSampleRate, int nChannels) -{ +long DSGetSoundBuffer(INOUT AudioBuffer_s **pVoice, unsigned long dwFlags, unsigned long dwBufferSize, unsigned long nSampleRate, int nChannels) { AudioParams_s params = { 0 }; params.nChannels = nChannels; @@ -96,39 +87,23 @@ long DSGetSoundBuffer(INOUT AudioBuffer_s **pVoice, unsigned long dwFlags, unsig params.nAvgBytesPerSec = params.nBlockAlign * params.nSamplesPerSec; params.dwBufferBytes = dwBufferSize; - if (*pVoice) - { - DSReleaseSoundBuffer(pVoice); - } - int hr = g_lpDS->CreateSoundBuffer(¶ms, pVoice, g_lpDS); - if(hr) - return hr; - - assert(g_uNumVoices < uMAX_VOICES); - if(g_uNumVoices < uMAX_VOICES) - g_pVoices[g_uNumVoices++] = *pVoice; - - return hr; -} - -void DSReleaseSoundBuffer(INOUT AudioBuffer_s **pVoice) -{ - - for(unsigned int i=0; iDestroySoundBuffer(pVoice); + long err = 0; + do { + err = audioContext->CreateSoundBuffer(¶ms, pVoice, audioContext); + if (err) { + break; } + } while (0); + + return err; +} + +void DSReleaseSoundBuffer(INOUT AudioBuffer_s **pVoice) { + audioContext->DestroySoundBuffer(pVoice); } //----------------------------------------------------------------------------- @@ -246,11 +221,11 @@ bool audio_init(void) bool bCreatedOK = false; for(int x=0; xshutdown((AudioContext_s**)&g_lpDS); + audio_backend->shutdown((AudioContext_s**)&audioContext); } - hr = (int)audio_backend->init(sound_devices[x], (AudioContext_s**)&g_lpDS); + hr = (int)audio_backend->init(sound_devices[x], (AudioContext_s**)&audioContext); if(hr == 0) { bCreatedOK = true; @@ -291,11 +266,7 @@ void audio_shutdown(void) if(g_uDSInitRefCount) return; - // - - assert(g_uNumVoices == 0); - - audio_backend->shutdown((AudioContext_s**)&g_lpDS); + audio_backend->shutdown(&audioContext); audio_isAvailable = false; }