Store the filter gains directly in the source instead of duplicate filter objects

This commit is contained in:
Chris Robinson 2011-08-31 02:18:16 -07:00
parent 49e2fa428f
commit b28f48c1bd
4 changed files with 38 additions and 48 deletions

View File

@ -1267,8 +1267,8 @@ static ALCboolean UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
if(source->Send[s].Slot)
DecrementRef(&source->Send[s].Slot->ref);
source->Send[s].Slot = NULL;
source->Send[s].WetFilter.type = 0;
source->Send[s].WetFilter.filter = 0;
source->Send[s].WetGain = 1.0f;
source->Send[s].WetGainHF = 1.0f;
s++;
}
source->NeedsUpdate = AL_FALSE;

View File

@ -183,25 +183,13 @@ ALvoid CalcNonAttnSourceParams(ALsource *ALSource, const ALCcontext *ALContext)
/* Calculate gains */
DryGain = clampf(SourceVolume, MinVolume, MaxVolume);
DryGainHF = 1.0f;
switch(ALSource->DirectFilter.type)
{
case AL_FILTER_LOWPASS:
DryGain *= ALSource->DirectFilter.Gain;
DryGainHF *= ALSource->DirectFilter.GainHF;
break;
}
DryGain *= ALSource->DirectGain;
DryGainHF = ALSource->DirectGainHF;
for(i = 0;i < NumSends;i++)
{
WetGain[i] = clampf(SourceVolume, MinVolume, MaxVolume);
WetGainHF[i] = 1.0f;
switch(ALSource->Send[i].WetFilter.type)
{
case AL_FILTER_LOWPASS:
WetGain[i] *= ALSource->Send[i].WetFilter.Gain;
WetGainHF[i] *= ALSource->Send[i].WetFilter.GainHF;
break;
}
WetGain[i] *= ALSource->Send[i].WetGain;
WetGainHF[i] = WetGainHF[i] *= ALSource->Send[i].WetGainHF;
}
SrcMatrix = ALSource->Params.DryGains;
@ -610,24 +598,12 @@ ALvoid CalcSourceParams(ALsource *ALSource, const ALCcontext *ALContext)
WetGain[i] = clampf(WetGain[i], MinVolume, MaxVolume);
// Apply filter gains and filters
switch(ALSource->DirectFilter.type)
{
case AL_FILTER_LOWPASS:
DryGain *= ALSource->DirectFilter.Gain;
DryGainHF *= ALSource->DirectFilter.GainHF;
break;
}
DryGain *= ListenerGain;
DryGain *= ALSource->DirectGain * ListenerGain;
DryGainHF *= ALSource->DirectGainHF;
for(i = 0;i < NumSends;i++)
{
switch(ALSource->Send[i].WetFilter.type)
{
case AL_FILTER_LOWPASS:
WetGain[i] *= ALSource->Send[i].WetFilter.Gain;
WetGainHF[i] *= ALSource->Send[i].WetFilter.GainHF;
break;
}
WetGain[i] *= ListenerGain;
WetGain[i] *= ALSource->Send[i].WetGain * ListenerGain;
WetGainHF[i] *= ALSource->Send[i].WetGainHF;
}
if(WetGainAuto)

View File

@ -59,11 +59,13 @@ typedef struct ALsource
ALuint BuffersInQueue; // Number of buffers in queue
ALuint BuffersPlayed; // Number of buffers played on this loop
ALfilter DirectFilter;
ALfloat DirectGain;
ALfloat DirectGainHF;
struct {
struct ALeffectslot *Slot;
ALfilter WetFilter;
ALfloat WetGain;
ALfloat WetGainHF;
} Send[MAX_SENDS];
ALboolean DryGainHFAuto;

View File

@ -653,11 +653,14 @@ AL_API ALvoid AL_APIENTRY alSourcei(ALuint source,ALenum eParam,ALint lValue)
{
if(!filter)
{
Source->DirectFilter.type = AL_FILTER_NULL;
Source->DirectFilter.filter = 0;
Source->DirectGain = 1.0f;
Source->DirectGainHF = 1.0f;
}
else
memcpy(&Source->DirectFilter, filter, sizeof(*filter));
{
Source->DirectGain = filter->Gain;
Source->DirectGainHF = filter->GainHF;
}
Source->NeedsUpdate = AL_TRUE;
}
else
@ -777,11 +780,14 @@ AL_API void AL_APIENTRY alSource3i(ALuint source, ALenum eParam, ALint lValue1,
if(!ALFilter)
{
/* Disable filter */
Source->Send[lValue2].WetFilter.type = 0;
Source->Send[lValue2].WetFilter.filter = 0;
Source->Send[lValue2].WetGain = 1.0f;
Source->Send[lValue2].WetGainHF = 1.0f;
}
else
memcpy(&Source->Send[lValue2].WetFilter, ALFilter, sizeof(*ALFilter));
{
Source->Send[lValue2].WetGain = ALFilter->Gain;
Source->Send[lValue2].WetGainHF = ALFilter->GainHF;
}
Source->NeedsUpdate = AL_TRUE;
}
else
@ -1166,10 +1172,6 @@ AL_API ALvoid AL_APIENTRY alGetSourcei(ALuint source, ALenum eParam, ALint *plVa
*plValue = (ALint)Offsets[0];
break;
case AL_DIRECT_FILTER:
*plValue = Source->DirectFilter.filter;
break;
case AL_DIRECT_FILTER_GAINHF_AUTO:
*plValue = Source->DryGainHFAuto;
break;
@ -1741,6 +1743,8 @@ done:
static ALvoid InitSourceParams(ALsource *Source)
{
ALuint i;
Source->flInnerAngle = 360.0f;
Source->flOuterAngle = 360.0f;
Source->flPitch = 1.0f;
@ -1780,6 +1784,14 @@ static ALvoid InitSourceParams(ALsource *Source)
Source->lSourceType = AL_UNDETERMINED;
Source->lOffset = -1;
Source->DirectGain = 1.0f;
Source->DirectGainHF = 1.0f;
for(i = 0;i < MAX_SENDS;i++)
{
Source->Send[i].WetGain = 1.0f;
Source->Send[i].WetGainHF = 1.0f;
}
Source->NeedsUpdate = AL_TRUE;
Source->HrtfMoving = AL_FALSE;