From 81dd71dd71aa1b11d3304265acd0728659465ab1 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sat, 17 Apr 2010 00:50:28 -0700 Subject: [PATCH] Stop and start the backend device only if new attributes are being requested --- Alc/ALc.c | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/Alc/ALc.c b/Alc/ALc.c index 2763d7a3..c4617252 100644 --- a/Alc/ALc.c +++ b/Alc/ALc.c @@ -1203,6 +1203,7 @@ ALC_API ALCenum ALC_APIENTRY alcGetEnumValue(ALCdevice *device, const ALCchar *e ALC_API ALCcontext* ALC_APIENTRY alcCreateContext(ALCdevice *device, const ALCint *attrList) { ALCcontext *ALContext; + ALboolean running; ALuint attrIdx; void *temp; ALuint i; @@ -1216,25 +1217,30 @@ ALC_API ALCcontext* ALC_APIENTRY alcCreateContext(ALCdevice *device, const ALCin return NULL; } + running = ((device->NumContexts > 0) ? AL_TRUE : AL_FALSE); + // Reset Context Last Error code device->LastError = ALC_NO_ERROR; - // If a context is already running on the device, stop playback so the - // device attributes can be updated - if(device->NumContexts > 0) - { - ProcessContext(NULL); - ALCdevice_StopPlayback(device); - SuspendContext(NULL); - } - // Check for attributes - if(attrList) + if(attrList && attrList[0]) { - ALCuint freq = device->Frequency; - ALCuint numMono = device->NumMonoSources; - ALCuint numStereo = device->NumStereoSources; - ALCuint numSends = device->NumAuxSends; + ALCuint freq, numMono, numStereo, numSends; + + // If a context is already running on the device, stop playback so the + // device attributes can be updated + if(running) + { + ProcessContext(NULL); + ALCdevice_StopPlayback(device); + SuspendContext(NULL); + running = AL_FALSE; + } + + freq = device->Frequency; + numMono = device->NumMonoSources; + numStereo = device->NumStereoSources; + numSends = device->NumAuxSends; attrIdx = 0; while(attrList[attrIdx]) @@ -1276,7 +1282,7 @@ ALC_API ALCcontext* ALC_APIENTRY alcCreateContext(ALCdevice *device, const ALCin device->NumAuxSends = numSends; } - if(ALCdevice_ResetPlayback(device) == ALC_FALSE) + if(running == AL_FALSE && ALCdevice_ResetPlayback(device) == ALC_FALSE) { alcSetError(device, ALC_INVALID_DEVICE); aluHandleDisconnect(device); -- 2.11.4.GIT