From 51e458b106b6b500d621f352b9adadab2da18fd6 Mon Sep 17 00:00:00 2001 From: thilo Date: Sat, 24 Oct 2009 08:33:12 +0000 Subject: A few more last fixes that will handle some special cases git-svn-id: svn://svn.icculus.org/quake3/trunk@1700 edf5b092-35ff-0310-97b2-ce42778d08ea --- code/client/snd_openal.c | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) (limited to 'code') diff --git a/code/client/snd_openal.c b/code/client/snd_openal.c index 7d9e66d..a25a5c6 100644 --- a/code/client/snd_openal.c +++ b/code/client/snd_openal.c @@ -501,7 +501,7 @@ typedef struct src_s float curGain; // gain employed if source is within maxdistance. float scaleGain; // Last gain value for this source. 0 if muted. - float lastTimePos; // On stopped loops, last time position in s + float lastTimePos; // On stopped loops, the last position in the buffer int lastSampleTime; // Time when this was stopped qboolean local; // Is this local (relative to the cam) @@ -758,7 +758,8 @@ static void S_AL_NewLoopMaster(src_t *rmSource, qboolean iskilled) curSfx = &knownSfx[rmSource->sfx]; - curSfx->loopActiveCnt--; + if(rmSource->isPlaying) + curSfx->loopActiveCnt--; if(iskilled) curSfx->loopCnt--; @@ -798,9 +799,20 @@ static void S_AL_NewLoopMaster(src_t *rmSource, qboolean iskilled) else curSource = &srcList[firstInactive]; - // this was the last not stopped source, save last sample position + time - qalGetSourcef(rmSource->alSource, AL_SEC_OFFSET, &curSource->lastTimePos); - curSource->lastSampleTime = Sys_Milliseconds(); + if(rmSource->isPlaying) + { + // this was the last not stopped source, save last sample position + time + qalGetSourcef(rmSource->alSource, AL_SEC_OFFSET, &curSource->lastTimePos); + curSource->lastSampleTime = Sys_Milliseconds(); + } + else + { + // second case: all loops using this sound have stopped due to listener being of of range, + // and now the inactive master gets deleted. Just move over the soundpos settings to the + // new master. + curSource->lastTimePos = rmSource->lastTimePos; + curSource->lastSampleTime = rmSource->lastSampleTime; + } } } } @@ -840,9 +852,11 @@ static void S_AL_SrcKill(srcHandle_t src) } // Stop it if it's playing - if(curSource->isActive) + if(curSource->isPlaying) + { qalSourceStop(curSource->alSource); - curSource->isPlaying = qfalse; + curSource->isPlaying = qfalse; + } // Remove the buffer qalSourcei(curSource->alSource, AL_BUFFER, 0); @@ -1340,7 +1354,6 @@ void S_AL_SrcUpdate( void ) qalSourcei(curSource->alSource, AL_LOOPING, AL_TRUE); curSource->isPlaying = qtrue; qalSourcePlay(curSource->alSource); - } // Update locality @@ -1370,6 +1383,7 @@ void S_AL_SrcUpdate( void ) qalGetSourcei(curSource->alSource, AL_SOURCE_STATE, &state); if(state == AL_STOPPED) { + curSource->isPlaying = qfalse; S_AL_SrcKill(i); continue; } -- cgit v1.2.3