From 010f7d12f48f8e046dcda4a5e39221265554e2ff Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Thu, 13 Nov 2008 05:48:38 -0800 Subject: [PATCH] Don't ramp gains when starting a sound from the beginning --- Alc/ALu.c | 20 +++++++++++++++++--- OpenAL32/Include/alSource.h | 1 + OpenAL32/alSource.c | 2 ++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/Alc/ALu.c b/Alc/ALu.c index 5371d3b5..fbf5a128 100644 --- a/Alc/ALu.c +++ b/Alc/ALu.c @@ -732,9 +732,23 @@ ALvoid aluMixData(ALCcontext *ALContext,ALvoid *buffer,ALsizei size,ALenum forma WetSend = &ALSource->WetGain; //Compute the gain steps for each output channel - for(i = 0;i < OUTPUTCHANNELS;i++) - dryGainStep[i] = (newDrySend[i]-DrySend[i]) / rampLength; - wetGainStep = (newWetSend-(*WetSend)) / rampLength; + if(ALSource->FirstStart && DataPosInt == 0 && DataPosFrac == 0) + { + for(i = 0;i < OUTPUTCHANNELS;i++) + { + DrySend[i] = newDrySend[i]; + dryGainStep[i] = 0; + } + *WetSend = newWetSend; + wetGainStep = 0; + } + else + { + for(i = 0;i < OUTPUTCHANNELS;i++) + dryGainStep[i] = (newDrySend[i]-DrySend[i]) / rampLength; + wetGainStep = (newWetSend-(*WetSend)) / rampLength; + } + ALSource->FirstStart = AL_FALSE; //Compute 18.14 fixed point step if(Pitch > (float)MAX_PITCH) diff --git a/OpenAL32/Include/alSource.h b/OpenAL32/Include/alSource.h index 2bd1db08..617dc4e3 100644 --- a/OpenAL32/Include/alSource.h +++ b/OpenAL32/Include/alSource.h @@ -96,6 +96,7 @@ typedef struct ALsource // Current gains, which are ramped while mixed ALfloat DryGains[OUTPUTCHANNELS]; ALfloat WetGain; + ALboolean FirstStart; struct ALsource *next; } ALsource; diff --git a/OpenAL32/alSource.c b/OpenAL32/alSource.c index 50217783..e130e044 100644 --- a/OpenAL32/alSource.c +++ b/OpenAL32/alSource.c @@ -1435,6 +1435,7 @@ ALAPI ALvoid ALAPIENTRY alSourcePlayv(ALsizei n, const ALuint *pSourceList) pSource->position = 0; pSource->position_fraction = 0; pSource->BuffersPlayed = 0; + pSource->FirstStart = AL_TRUE; pSource->ulBufferID = pSource->queue->buffer; @@ -1451,6 +1452,7 @@ ALAPI ALvoid ALAPIENTRY alSourcePlayv(ALsizei n, const ALuint *pSourceList) pSource->state = AL_PLAYING; pSource->inuse = AL_TRUE; pSource->play = AL_TRUE; + pSource->FirstStart = AL_FALSE; } // Check if an Offset has been set -- 2.11.4.GIT