diff options
author | Chris Robinson <[email protected]> | 2010-08-07 06:57:31 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2010-08-07 06:57:31 -0700 |
commit | 8003278a5589c6300650710be924d596791946ac (patch) | |
tree | 2ff52972421bdb6e726bb5f99aca357ed5592dcb /Alc | |
parent | 5f22d30fc91e677933e12034979f42f74c4f653d (diff) |
Combine non-attenuated source calculation functions
Diffstat (limited to 'Alc')
-rw-r--r-- | Alc/ALu.c | 218 |
1 files changed, 62 insertions, 156 deletions
@@ -84,112 +84,8 @@ ALvoid CalcNonAttnSourceParams(ALsource *ALSource, const ALCcontext *ALContext) ALfloat WetGain[MAX_SENDS]; ALfloat WetGainHF[MAX_SENDS]; ALint NumSends, Frequency; - ALfloat Pitch; - ALfloat cw; - ALint i; - - //Get context properties - NumSends = ALContext->Device->NumAuxSends; - Frequency = ALContext->Device->Frequency; - - //Get listener properties - ListenerGain = ALContext->Listener.Gain; - - //Get source properties - SourceVolume = ALSource->flGain; - MinVolume = ALSource->flMinGain; - MaxVolume = ALSource->flMaxGain; - - //1. Multi-channel buffers always play "normal" - Pitch = ALSource->flPitch; - BufferListItem = ALSource->queue; - while(BufferListItem != NULL) - { - ALbuffer *ALBuffer; - if((ALBuffer=BufferListItem->buffer) != NULL) - { - Pitch = Pitch * ALBuffer->frequency / Frequency; - break; - } - BufferListItem = BufferListItem->next; - } - - if(Pitch > (float)MAX_PITCH) - ALSource->Params.Step = MAX_PITCH<<FRACTIONBITS; - else if(!(Pitch > 0.0f)) - ALSource->Params.Step = 1<<FRACTIONBITS; - else - { - ALSource->Params.Step = Pitch*(1<<FRACTIONBITS); - if(ALSource->Params.Step == 0) - ALSource->Params.Step = 1; - } - - DryGain = SourceVolume; - DryGain = __min(DryGain,MaxVolume); - DryGain = __max(DryGain,MinVolume); - DryGainHF = 1.0f; - - switch(ALSource->DirectFilter.type) - { - case AL_FILTER_LOWPASS: - DryGain *= ALSource->DirectFilter.Gain; - DryGainHF *= ALSource->DirectFilter.GainHF; - break; - } - - for(i = 0;i < OUTPUTCHANNELS;i++) - ALSource->Params.DryGains[i] = DryGain * ListenerGain; - - for(i = 0;i < NumSends;i++) - { - WetGain[i] = SourceVolume; - WetGain[i] = __min(WetGain[i],MaxVolume); - WetGain[i] = __max(WetGain[i],MinVolume); - 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; - } - - ALSource->Params.WetGains[i] = WetGain[i] * ListenerGain; - } - for(i = NumSends;i < MAX_SENDS;i++) - { - ALSource->Params.WetGains[i] = 0.0f; - WetGainHF[i] = 1.0f; - } - - /* Update filter coefficients. Calculations based on the I3DL2 - * spec. */ - cw = cos(2.0*M_PI * LOWPASSFREQCUTOFF / Frequency); - - /* We use two chained one-pole filters, so we need to take the - * square root of the squared gain, which is the same as the base - * gain. */ - ALSource->Params.iirFilter.coeff = lpCoeffCalc(DryGainHF, cw); - - for(i = 0;i < NumSends;i++) - { - /* We use a one-pole filter, so we need to take the squared gain */ - ALfloat a = lpCoeffCalc(WetGainHF[i]*WetGainHF[i], cw); - ALSource->Params.Send[i].iirFilter.coeff = a; - } -} - -ALvoid CalcNonAttnStereoSourceParams(ALsource *ALSource, const ALCcontext *ALContext) -{ - ALfloat SourceVolume,ListenerGain,MinVolume,MaxVolume; - ALbufferlistitem *BufferListItem; - ALfloat DryGain, DryGainHF; - ALfloat WetGain[MAX_SENDS]; - ALfloat WetGainHF[MAX_SENDS]; - ALint NumSends, Frequency; ALboolean DupStereo; + ALint Channels; ALfloat Pitch; ALenum Format; ALfloat cw; @@ -210,6 +106,7 @@ ALvoid CalcNonAttnStereoSourceParams(ALsource *ALSource, const ALCcontext *ALCon MaxVolume = ALSource->flMaxGain; //1. Multi-channel buffers always play "normal" + Channels = 0; Pitch = ALSource->flPitch; BufferListItem = ALSource->queue; while(BufferListItem != NULL) @@ -217,6 +114,7 @@ ALvoid CalcNonAttnStereoSourceParams(ALsource *ALSource, const ALCcontext *ALCon ALbuffer *ALBuffer; if((ALBuffer=BufferListItem->buffer) != NULL) { + Channels = aluChannelsFromFormat(ALBuffer->format); Pitch = Pitch * ALBuffer->frequency / Frequency; break; } @@ -247,67 +145,75 @@ ALvoid CalcNonAttnStereoSourceParams(ALsource *ALSource, const ALCcontext *ALCon break; } - for(i = 0;i < OUTPUTCHANNELS;i++) - ALSource->Params.DryGains[i] = 0.0f; - - if(DupStereo == AL_FALSE) + if(Channels == 2) { - ALSource->Params.DryGains[FRONT_LEFT] = DryGain * ListenerGain; - ALSource->Params.DryGains[FRONT_RIGHT] = DryGain * ListenerGain; - } - else - { - switch(Format) + for(i = 0;i < OUTPUTCHANNELS;i++) + ALSource->Params.DryGains[i] = 0.0f; + + if(DupStereo == AL_FALSE) { - case AL_FORMAT_MONO8: - case AL_FORMAT_MONO16: - case AL_FORMAT_MONO_FLOAT32: - case AL_FORMAT_STEREO8: - case AL_FORMAT_STEREO16: - case AL_FORMAT_STEREO_FLOAT32: ALSource->Params.DryGains[FRONT_LEFT] = DryGain * ListenerGain; ALSource->Params.DryGains[FRONT_RIGHT] = DryGain * ListenerGain; - break; + } + else + { + switch(Format) + { + case AL_FORMAT_MONO8: + case AL_FORMAT_MONO16: + case AL_FORMAT_MONO_FLOAT32: + case AL_FORMAT_STEREO8: + case AL_FORMAT_STEREO16: + case AL_FORMAT_STEREO_FLOAT32: + ALSource->Params.DryGains[FRONT_LEFT] = DryGain * ListenerGain; + ALSource->Params.DryGains[FRONT_RIGHT] = DryGain * ListenerGain; + break; - case AL_FORMAT_QUAD8: - case AL_FORMAT_QUAD16: - case AL_FORMAT_QUAD32: - case AL_FORMAT_51CHN8: - case AL_FORMAT_51CHN16: - case AL_FORMAT_51CHN32: - DryGain *= aluSqrt(2.0f/4.0f); - ALSource->Params.DryGains[FRONT_LEFT] = DryGain * ListenerGain; - ALSource->Params.DryGains[FRONT_RIGHT] = DryGain * ListenerGain; - ALSource->Params.DryGains[BACK_LEFT] = DryGain * ListenerGain; - ALSource->Params.DryGains[BACK_RIGHT] = DryGain * ListenerGain; - break; + case AL_FORMAT_QUAD8: + case AL_FORMAT_QUAD16: + case AL_FORMAT_QUAD32: + case AL_FORMAT_51CHN8: + case AL_FORMAT_51CHN16: + case AL_FORMAT_51CHN32: + DryGain *= aluSqrt(2.0f/4.0f); + ALSource->Params.DryGains[FRONT_LEFT] = DryGain * ListenerGain; + ALSource->Params.DryGains[FRONT_RIGHT] = DryGain * ListenerGain; + ALSource->Params.DryGains[BACK_LEFT] = DryGain * ListenerGain; + ALSource->Params.DryGains[BACK_RIGHT] = DryGain * ListenerGain; + break; - case AL_FORMAT_61CHN8: - case AL_FORMAT_61CHN16: - case AL_FORMAT_61CHN32: - DryGain *= aluSqrt(2.0f/4.0f); - ALSource->Params.DryGains[FRONT_LEFT] = DryGain * ListenerGain; - ALSource->Params.DryGains[FRONT_RIGHT] = DryGain * ListenerGain; - ALSource->Params.DryGains[SIDE_LEFT] = DryGain * ListenerGain; - ALSource->Params.DryGains[SIDE_RIGHT] = DryGain * ListenerGain; - break; + case AL_FORMAT_61CHN8: + case AL_FORMAT_61CHN16: + case AL_FORMAT_61CHN32: + DryGain *= aluSqrt(2.0f/4.0f); + ALSource->Params.DryGains[FRONT_LEFT] = DryGain * ListenerGain; + ALSource->Params.DryGains[FRONT_RIGHT] = DryGain * ListenerGain; + ALSource->Params.DryGains[SIDE_LEFT] = DryGain * ListenerGain; + ALSource->Params.DryGains[SIDE_RIGHT] = DryGain * ListenerGain; + break; - case AL_FORMAT_71CHN8: - case AL_FORMAT_71CHN16: - case AL_FORMAT_71CHN32: - DryGain *= aluSqrt(2.0f/6.0f); - ALSource->Params.DryGains[FRONT_LEFT] = DryGain * ListenerGain; - ALSource->Params.DryGains[FRONT_RIGHT] = DryGain * ListenerGain; - ALSource->Params.DryGains[BACK_LEFT] = DryGain * ListenerGain; - ALSource->Params.DryGains[BACK_RIGHT] = DryGain * ListenerGain; - ALSource->Params.DryGains[SIDE_LEFT] = DryGain * ListenerGain; - ALSource->Params.DryGains[SIDE_RIGHT] = DryGain * ListenerGain; - break; + case AL_FORMAT_71CHN8: + case AL_FORMAT_71CHN16: + case AL_FORMAT_71CHN32: + DryGain *= aluSqrt(2.0f/6.0f); + ALSource->Params.DryGains[FRONT_LEFT] = DryGain * ListenerGain; + ALSource->Params.DryGains[FRONT_RIGHT] = DryGain * ListenerGain; + ALSource->Params.DryGains[BACK_LEFT] = DryGain * ListenerGain; + ALSource->Params.DryGains[BACK_RIGHT] = DryGain * ListenerGain; + ALSource->Params.DryGains[SIDE_LEFT] = DryGain * ListenerGain; + ALSource->Params.DryGains[SIDE_RIGHT] = DryGain * ListenerGain; + break; - default: - break; + default: + break; + } } } + else + { + for(i = 0;i < OUTPUTCHANNELS;i++) + ALSource->Params.DryGains[i] = DryGain * ListenerGain; + } for(i = 0;i < NumSends;i++) { |