diff options
-rw-r--r-- | Alc/alcDedicated.c | 17 | ||||
-rw-r--r-- | Alc/alcEcho.c | 29 | ||||
-rw-r--r-- | Alc/alcModulator.c | 46 | ||||
-rw-r--r-- | Alc/alcReverb.c | 60 |
4 files changed, 80 insertions, 72 deletions
diff --git a/Alc/alcDedicated.c b/Alc/alcDedicated.c index d12130f8..c812877a 100644 --- a/Alc/alcDedicated.c +++ b/Alc/alcDedicated.c @@ -55,38 +55,45 @@ static ALvoid DedicatedDLGUpdate(ALeffectState *effect, ALCcontext *Context, con ALdedicatedState *state = (ALdedicatedState*)effect; ALCdevice *device = Context->Device; const ALfloat *SpeakerGain; + ALfloat Gain; ALint pos; ALsizei s; pos = aluCart2LUTpos(1.0f, 0.0f); SpeakerGain = device->PanningLUT[pos]; + Gain = Slot->Gain * Slot->effect.Params.Dedicated.Gain; for(s = 0;s < MAXCHANNELS;s++) - state->gains[s] = SpeakerGain[s] * Slot->effect.Params.Dedicated.Gain; + state->gains[s] = SpeakerGain[s] * Gain; } static ALvoid DedicatedLFEUpdate(ALeffectState *effect, ALCcontext *Context, const ALeffectslot *Slot) { ALdedicatedState *state = (ALdedicatedState*)effect; + ALfloat Gain; ALsizei s; (void)Context; + Gain = Slot->Gain * Slot->effect.Params.Dedicated.Gain; for(s = 0;s < MAXCHANNELS;s++) state->gains[s] = 0.0f; - state->gains[LFE] = Slot->effect.Params.Dedicated.Gain; + state->gains[LFE] = Gain; } static ALvoid DedicatedProcess(ALeffectState *effect, const ALeffectslot *Slot, ALuint SamplesToDo, const ALfloat *SamplesIn, ALfloat (*SamplesOut)[MAXCHANNELS]) { ALdedicatedState *state = (ALdedicatedState*)effect; const ALfloat *gains = state->gains; - ALuint i; + ALuint i, s; + (void)Slot; for(i = 0;i < SamplesToDo;i++) { - ALsizei s; + ALfloat sample; + + sample = SamplesIn[i]; for(s = 0;s < MAXCHANNELS;s++) - SamplesOut[i][s] = SamplesIn[i] * gains[s] * Slot->Gain; + SamplesOut[i][s] = sample * gains[s]; } } diff --git a/Alc/alcEcho.c b/Alc/alcEcho.c index f60290f9..b62c124a 100644 --- a/Alc/alcEcho.c +++ b/Alc/alcEcho.c @@ -90,22 +90,16 @@ static ALboolean EchoDeviceUpdate(ALeffectState *effect, ALCdevice *Device) for(i = 0;i < state->BufferLength;i++) state->SampleBuffer[i] = 0.0f; - for(i = 0;i < MAXCHANNELS;i++) - state->Gain[i] = 0.0f; - for(i = 0;i < Device->NumChan;i++) - { - enum Channel chan = Device->Speaker2Chan[i]; - state->Gain[chan] = 1.0f; - } - return AL_TRUE; } static ALvoid EchoUpdate(ALeffectState *effect, ALCcontext *Context, const ALeffectslot *Slot) { ALechoState *state = (ALechoState*)effect; - ALuint frequency = Context->Device->Frequency; - ALfloat lrpan, cw, g; + ALCdevice *Device = Context->Device; + ALuint frequency = Device->Frequency; + ALfloat lrpan, cw, g, gain; + ALuint i; state->Tap[0].delay = (ALuint)(Slot->effect.Params.Echo.Delay * frequency) + 1; state->Tap[1].delay = (ALuint)(Slot->effect.Params.Echo.LRDelay * frequency); @@ -120,6 +114,15 @@ static ALvoid EchoUpdate(ALeffectState *effect, ALCcontext *Context, const ALeff cw = cos(2.0*M_PI * LOWPASSFREQCUTOFF / frequency); g = 1.0f - Slot->effect.Params.Echo.Damping; state->iirFilter.coeff = lpCoeffCalc(g, cw); + + gain = Slot->Gain; + for(i = 0;i < MAXCHANNELS;i++) + state->Gain[i] = 0.0f; + for(i = 0;i < Device->NumChan;i++) + { + enum Channel chan = Device->Speaker2Chan[i]; + state->Gain[chan] = gain; + } } static ALvoid EchoProcess(ALeffectState *effect, const ALeffectslot *Slot, ALuint SamplesToDo, const ALfloat *SamplesIn, ALfloat (*SamplesOut)[MAXCHANNELS]) @@ -129,9 +132,9 @@ static ALvoid EchoProcess(ALeffectState *effect, const ALeffectslot *Slot, ALuin const ALuint tap1 = state->Tap[0].delay; const ALuint tap2 = state->Tap[1].delay; ALuint offset = state->Offset; - const ALfloat gain = Slot->Gain; ALfloat samp[2], smp; ALuint i; + (void)Slot; for(i = 0;i < SamplesToDo;i++,offset++) { @@ -149,10 +152,6 @@ static ALvoid EchoProcess(ALeffectState *effect, const ALeffectslot *Slot, ALuin smp = lpFilter2P(&state->iirFilter, 0, smp+SamplesIn[i]); state->SampleBuffer[offset&mask] = smp * state->FeedGain; - // Apply slot gain - samp[0] *= gain; - samp[1] *= gain; - SamplesOut[i][FRONT_LEFT] += state->Gain[FRONT_LEFT] * samp[0]; SamplesOut[i][FRONT_RIGHT] += state->Gain[FRONT_RIGHT] * samp[1]; SamplesOut[i][SIDE_LEFT] += state->Gain[SIDE_LEFT] * samp[0]; diff --git a/Alc/alcModulator.c b/Alc/alcModulator.c index 1908007c..c4085fa3 100644 --- a/Alc/alcModulator.c +++ b/Alc/alcModulator.c @@ -82,11 +82,9 @@ static __inline ALfloat hpFilter1P(FILTER *iir, ALuint offset, ALfloat input) #define DECL_TEMPLATE(func) \ -static void Process##func(ALmodulatorState *state, const ALeffectslot *Slot, \ - ALuint SamplesToDo, const ALfloat *SamplesIn, \ - ALfloat (*SamplesOut)[MAXCHANNELS]) \ +static void Process##func(ALmodulatorState *state, ALuint SamplesToDo, \ + const ALfloat *SamplesIn, ALfloat (*SamplesOut)[MAXCHANNELS]) \ { \ - const ALfloat gain = Slot->Gain; \ const ALuint step = state->step; \ ALuint index = state->index; \ ALfloat samp; \ @@ -102,9 +100,6 @@ static void Process##func(ALmodulatorState *state, const ALeffectslot *Slot, \ \ samp = hpFilter1P(&state->iirFilter, 0, samp); \ \ - /* Apply slot gain */ \ - samp *= gain; \ - \ SamplesOut[i][FRONT_LEFT] += state->Gain[FRONT_LEFT] * samp; \ SamplesOut[i][FRONT_RIGHT] += state->Gain[FRONT_RIGHT] * samp; \ SamplesOut[i][FRONT_CENTER] += state->Gain[FRONT_CENTER] * samp; \ @@ -132,24 +127,17 @@ static ALvoid ModulatorDestroy(ALeffectState *effect) static ALboolean ModulatorDeviceUpdate(ALeffectState *effect, ALCdevice *Device) { - ALmodulatorState *state = (ALmodulatorState*)effect; - ALuint index; - - for(index = 0;index < MAXCHANNELS;index++) - state->Gain[index] = 0.0f; - for(index = 0;index < Device->NumChan;index++) - { - enum Channel chan = Device->Speaker2Chan[index]; - state->Gain[chan] = 1.0f; - } - return AL_TRUE; + (void)effect; + (void)Device; } static ALvoid ModulatorUpdate(ALeffectState *effect, ALCcontext *Context, const ALeffectslot *Slot) { ALmodulatorState *state = (ALmodulatorState*)effect; - ALfloat cw, a = 0.0f; + ALCdevice *Device = Context->Device; + ALfloat gain, cw, a = 0.0f; + ALuint index; if(Slot->effect.Params.Modulator.Waveform == AL_RING_MODULATOR_SINUSOID) state->Waveform = SINUSOID; @@ -159,32 +147,42 @@ static ALvoid ModulatorUpdate(ALeffectState *effect, ALCcontext *Context, const state->Waveform = SQUARE; state->step = Slot->effect.Params.Modulator.Frequency*(1<<WAVEFORM_FRACBITS) / - Context->Device->Frequency; + Device->Frequency; if(!state->step) state->step = 1; cw = cos(2.0*M_PI * Slot->effect.Params.Modulator.HighPassCutoff / - Context->Device->Frequency); + Device->Frequency); a = (2.0f-cw) - aluSqrt(aluPow(2.0f-cw, 2.0f) - 1.0f); state->iirFilter.coeff = a; + + gain = Slot->Gain; + for(index = 0;index < MAXCHANNELS;index++) + state->Gain[index] = 0.0f; + for(index = 0;index < Device->NumChan;index++) + { + enum Channel chan = Device->Speaker2Chan[index]; + state->Gain[chan] = gain; + } } static ALvoid ModulatorProcess(ALeffectState *effect, const ALeffectslot *Slot, ALuint SamplesToDo, const ALfloat *SamplesIn, ALfloat (*SamplesOut)[MAXCHANNELS]) { ALmodulatorState *state = (ALmodulatorState*)effect; + (void)Slot; switch(state->Waveform) { case SINUSOID: - ProcessSin(state, Slot, SamplesToDo, SamplesIn, SamplesOut); + ProcessSin(state, SamplesToDo, SamplesIn, SamplesOut); break; case SAWTOOTH: - ProcessSaw(state, Slot, SamplesToDo, SamplesIn, SamplesOut); + ProcessSaw(state, SamplesToDo, SamplesIn, SamplesOut); break; case SQUARE: - ProcessSquare(state, Slot, SamplesToDo, SamplesIn, SamplesOut); + ProcessSquare(state, SamplesToDo, SamplesIn, SamplesOut); break; } } diff --git a/Alc/alcReverb.c b/Alc/alcReverb.c index 4282e9ee..43197912 100644 --- a/Alc/alcReverb.c +++ b/Alc/alcReverb.c @@ -589,7 +589,7 @@ static ALvoid UpdateEchoLine(ALfloat reverbGain, ALfloat lateGain, ALfloat echoT } // Update the early and late 3D panning gains. -static ALvoid Update3DPanning(const ALCdevice *Device, const ALfloat *ReflectionsPan, const ALfloat *LateReverbPan, ALverbState *State) +static ALvoid Update3DPanning(const ALCdevice *Device, const ALfloat *ReflectionsPan, const ALfloat *LateReverbPan, ALfloat Gain, ALverbState *State) { ALfloat earlyPan[3] = { ReflectionsPan[0], ReflectionsPan[1], ReflectionsPan[2] }; @@ -635,7 +635,7 @@ static ALvoid Update3DPanning(const ALCdevice *Device, const ALfloat *Reflection for(index = 0;index < Device->NumChan;index++) { enum Channel chan = Device->Speaker2Chan[index]; - State->Early.PanGain[chan] = lerp(1.0, speakerGain[chan], dirGain); + State->Early.PanGain[chan] = lerp(1.0, speakerGain[chan], dirGain) * Gain; } @@ -648,7 +648,7 @@ static ALvoid Update3DPanning(const ALCdevice *Device, const ALfloat *Reflection for(index = 0;index < Device->NumChan;index++) { enum Channel chan = Device->Speaker2Chan[index]; - State->Late.PanGain[chan] = lerp(1.0, speakerGain[chan], dirGain); + State->Late.PanGain[chan] = lerp(1.0, speakerGain[chan], dirGain) * Gain; } } @@ -1014,14 +1014,6 @@ static ALboolean VerbDeviceUpdate(ALeffectState *effect, ALCdevice *Device) frequency); } - for(index = 0;index < MAXCHANNELS;index++) - State->Gain[index] = 0.0f; - for(index = 0;index < Device->NumChan;index++) - { - enum Channel chan = Device->Speaker2Chan[index]; - State->Gain[chan] = 1.0f; - } - return AL_TRUE; } @@ -1066,8 +1058,10 @@ static ALboolean EAXVerbDeviceUpdate(ALeffectState *effect, ALCdevice *Device) static ALvoid VerbUpdate(ALeffectState *effect, ALCcontext *Context, const ALeffectslot *Slot) { ALverbState *State = (ALverbState*)effect; - ALuint frequency = Context->Device->Frequency; - ALfloat cw, x, y, hfRatio; + ALCdevice *Device = Context->Device; + ALuint frequency = Device->Frequency; + ALfloat cw, x, y, hfRatio, gain; + ALuint index; // Calculate the master low-pass filter (from the master effect HF gain). cw = CalcI3DL2HFreq(Slot->effect.Params.Reverb.HFReference, frequency); @@ -1105,6 +1099,16 @@ static ALvoid VerbUpdate(ALeffectState *effect, ALCcontext *Context, const ALeff UpdateLateLines(Slot->effect.Params.Reverb.Gain, Slot->effect.Params.Reverb.LateReverbGain, x, Slot->effect.Params.Reverb.Density, Slot->effect.Params.Reverb.DecayTime, Slot->effect.Params.Reverb.Diffusion, hfRatio, cw, frequency, State); + + // Update channel gains + gain = Slot->Gain; + for(index = 0;index < MAXCHANNELS;index++) + State->Gain[index] = 0.0f; + for(index = 0;index < Device->NumChan;index++) + { + enum Channel chan = Device->Speaker2Chan[index]; + State->Gain[chan] = gain; + } } // This updates the EAX reverb state. This is called any time the EAX reverb @@ -1165,7 +1169,7 @@ static ALvoid EAXVerbUpdate(ALeffectState *effect, ALCcontext *Context, const AL // Update early and late 3D panning. Update3DPanning(Context->Device, Slot->effect.Params.Reverb.ReflectionsPan, - Slot->effect.Params.Reverb.LateReverbPan, State); + Slot->effect.Params.Reverb.LateReverbPan, Slot->Gain, State); } // This processes the reverb state, given the input samples and an output @@ -1175,8 +1179,8 @@ static ALvoid VerbProcess(ALeffectState *effect, const ALeffectslot *Slot, ALuin ALverbState *State = (ALverbState*)effect; ALuint index; ALfloat early[4], late[4], out[4]; - ALfloat gain = Slot->Gain; const ALfloat *panGain = State->Gain; + (void)Slot; for(index = 0;index < SamplesToDo;index++) { @@ -1184,10 +1188,10 @@ static ALvoid VerbProcess(ALeffectState *effect, const ALeffectslot *Slot, ALuin VerbPass(State, SamplesIn[index], early, late); // Mix early reflections and late reverb. - out[0] = (early[0] + late[0]) * gain; - out[1] = (early[1] + late[1]) * gain; - out[2] = (early[2] + late[2]) * gain; - out[3] = (early[3] + late[3]) * gain; + out[0] = (early[0] + late[0]); + out[1] = (early[1] + late[1]); + out[2] = (early[2] + late[2]); + out[3] = (early[3] + late[3]); // Output the results. SamplesOut[index][FRONT_LEFT] += panGain[FRONT_LEFT] * out[0]; @@ -1208,7 +1212,7 @@ static ALvoid EAXVerbProcess(ALeffectState *effect, const ALeffectslot *Slot, AL ALverbState *State = (ALverbState*)effect; ALuint index; ALfloat early[4], late[4]; - ALfloat gain = Slot->Gain; + (void)Slot; for(index = 0;index < SamplesToDo;index++) { @@ -1220,28 +1224,28 @@ static ALvoid EAXVerbProcess(ALeffectState *effect, const ALeffectslot *Slot, AL // reverb engine is not so scalable. SamplesOut[index][FRONT_LEFT] += (State->Early.PanGain[FRONT_LEFT]*early[0] + - State->Late.PanGain[FRONT_LEFT]*late[0]) * gain; + State->Late.PanGain[FRONT_LEFT]*late[0]); SamplesOut[index][FRONT_RIGHT] += (State->Early.PanGain[FRONT_RIGHT]*early[1] + - State->Late.PanGain[FRONT_RIGHT]*late[1]) * gain; + State->Late.PanGain[FRONT_RIGHT]*late[1]); SamplesOut[index][FRONT_CENTER] += (State->Early.PanGain[FRONT_CENTER]*early[3] + - State->Late.PanGain[FRONT_CENTER]*late[3]) * gain; + State->Late.PanGain[FRONT_CENTER]*late[3]); SamplesOut[index][SIDE_LEFT] += (State->Early.PanGain[SIDE_LEFT]*early[0] + - State->Late.PanGain[SIDE_LEFT]*late[0]) * gain; + State->Late.PanGain[SIDE_LEFT]*late[0]); SamplesOut[index][SIDE_RIGHT] += (State->Early.PanGain[SIDE_RIGHT]*early[1] + - State->Late.PanGain[SIDE_RIGHT]*late[1]) * gain; + State->Late.PanGain[SIDE_RIGHT]*late[1]); SamplesOut[index][BACK_LEFT] += (State->Early.PanGain[BACK_LEFT]*early[0] + - State->Late.PanGain[BACK_LEFT]*late[0]) * gain; + State->Late.PanGain[BACK_LEFT]*late[0]); SamplesOut[index][BACK_RIGHT] += (State->Early.PanGain[BACK_RIGHT]*early[1] + - State->Late.PanGain[BACK_RIGHT]*late[1]) * gain; + State->Late.PanGain[BACK_RIGHT]*late[1]); SamplesOut[index][BACK_CENTER] += (State->Early.PanGain[BACK_CENTER]*early[2] + - State->Late.PanGain[BACK_CENTER]*late[2]) * gain; + State->Late.PanGain[BACK_CENTER]*late[2]); } } |