diff options
author | Chris Robinson <[email protected]> | 2019-02-21 03:52:54 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2019-02-21 03:52:54 -0800 |
commit | 8d2d7c63da8f5f106f607f5b21ea08151217c58a (patch) | |
tree | ff5e35dff1279614ba9211f1381f47b789d42a3e | |
parent | 462e320847de3937a5b40a4ed22e3bd745360410 (diff) |
Get rid of the MAX_EFFECT_CHANNELS macro
-rw-r--r-- | Alc/effects/autowah.cpp | 20 | ||||
-rw-r--r-- | Alc/effects/compressor.cpp | 14 | ||||
-rw-r--r-- | Alc/effects/equalizer.cpp | 27 | ||||
-rw-r--r-- | Alc/effects/modulator.cpp | 18 | ||||
-rw-r--r-- | OpenAL32/Include/alAuxEffectSlot.h | 3 |
5 files changed, 39 insertions, 43 deletions
diff --git a/Alc/effects/autowah.cpp b/Alc/effects/autowah.cpp index c391da38..ad4daf8d 100644 --- a/Alc/effects/autowah.cpp +++ b/Alc/effects/autowah.cpp @@ -62,7 +62,7 @@ struct ALautowahState final : public EffectState { /* Effect gains for each output channel */ ALfloat CurrentGains[MAX_OUTPUT_CHANNELS]; ALfloat TargetGains[MAX_OUTPUT_CHANNELS]; - } mChans[MAX_EFFECT_CHANNELS]; + } mChans[MAX_AMBI_CHANNELS]; /* Effects buffers */ alignas(16) ALfloat mBufferOut[BUFFERSIZE]; @@ -105,25 +105,25 @@ ALboolean ALautowahState::deviceUpdate(const ALCdevice *UNUSED(device)) void ALautowahState::update(const ALCcontext *context, const ALeffectslot *slot, const ALeffectProps *props, const EffectTarget target) { - const ALCdevice *device = context->Device; - ALfloat ReleaseTime; - ALsizei i; + const ALCdevice *device{context->Device}; - ReleaseTime = clampf(props->Autowah.ReleaseTime, 0.001f, 1.0f); + const ALfloat ReleaseTime{clampf(props->Autowah.ReleaseTime, 0.001f, 1.0f)}; mAttackRate = expf(-1.0f / (props->Autowah.AttackTime*device->Frequency)); mReleaseRate = expf(-1.0f / (ReleaseTime*device->Frequency)); /* 0-20dB Resonance Peak gain */ - mResonanceGain = sqrtf(log10f(props->Autowah.Resonance)*10.0f / 3.0f); - mPeakGain = 1.0f - log10f(props->Autowah.PeakGain/AL_AUTOWAH_MAX_PEAK_GAIN); + mResonanceGain = std::sqrt(std::log10(props->Autowah.Resonance)*10.0f / 3.0f); + mPeakGain = 1.0f - std::log10(props->Autowah.PeakGain/AL_AUTOWAH_MAX_PEAK_GAIN); mFreqMinNorm = MIN_FREQ / device->Frequency; mBandwidthNorm = (MAX_FREQ-MIN_FREQ) / device->Frequency; mOutBuffer = target.FOAOut->Buffer; mOutChannels = target.FOAOut->NumChannels; - for(i = 0;i < MAX_EFFECT_CHANNELS;i++) - ComputePanGains(target.FOAOut, alu::Matrix::Identity()[i].data(), slot->Params.Gain, - mChans[i].TargetGains); + for(size_t i{0u};i < slot->WetBuffer.size();++i) + { + auto coeffs = GetAmbiIdentityRow(i); + ComputePanGains(target.FOAOut, coeffs.data(), slot->Params.Gain, mChans[i].TargetGains); + } } void ALautowahState::process(ALsizei samplesToDo, const ALfloat (*RESTRICT samplesIn)[BUFFERSIZE], const ALsizei numInput, ALfloat (*RESTRICT samplesOut)[BUFFERSIZE], const ALsizei numOutput) diff --git a/Alc/effects/compressor.cpp b/Alc/effects/compressor.cpp index 23069dd7..99507661 100644 --- a/Alc/effects/compressor.cpp +++ b/Alc/effects/compressor.cpp @@ -39,7 +39,7 @@ struct ALcompressorState final : public EffectState { /* Effect gains for each channel */ - ALfloat mGain[MAX_EFFECT_CHANNELS][MAX_OUTPUT_CHANNELS]{}; + ALfloat mGain[MAX_AMBI_CHANNELS][MAX_OUTPUT_CHANNELS]{}; /* Effect parameters */ ALboolean mEnabled{AL_TRUE}; @@ -66,8 +66,8 @@ ALboolean ALcompressorState::deviceUpdate(const ALCdevice *device) /* Calculate per-sample multipliers to attack and release at the desired * rates. */ - mAttackMult = powf(AMP_ENVELOPE_MAX/AMP_ENVELOPE_MIN, 1.0f/attackCount); - mReleaseMult = powf(AMP_ENVELOPE_MIN/AMP_ENVELOPE_MAX, 1.0f/releaseCount); + mAttackMult = std::pow(AMP_ENVELOPE_MAX/AMP_ENVELOPE_MIN, 1.0f/attackCount); + mReleaseMult = std::pow(AMP_ENVELOPE_MIN/AMP_ENVELOPE_MAX, 1.0f/releaseCount); return AL_TRUE; } @@ -78,9 +78,11 @@ void ALcompressorState::update(const ALCcontext* UNUSED(context), const ALeffect mOutBuffer = target.FOAOut->Buffer; mOutChannels = target.FOAOut->NumChannels; - for(ALsizei i{0};i < 4;i++) - ComputePanGains(target.FOAOut, alu::Matrix::Identity()[i].data(), - slot->Params.Gain, mGain[i]); + for(size_t i{0u};i < slot->WetBuffer.size();++i) + { + auto coeffs = GetAmbiIdentityRow(i); + ComputePanGains(target.FOAOut, coeffs.data(), slot->Params.Gain, mGain[i]); + } } void ALcompressorState::process(ALsizei samplesToDo, const ALfloat (*RESTRICT samplesIn)[BUFFERSIZE], const ALsizei numInput, ALfloat (*RESTRICT samplesOut)[BUFFERSIZE], const ALsizei numOutput) diff --git a/Alc/effects/equalizer.cpp b/Alc/effects/equalizer.cpp index 942d6139..9abac6ea 100644 --- a/Alc/effects/equalizer.cpp +++ b/Alc/effects/equalizer.cpp @@ -87,7 +87,7 @@ struct ALequalizerState final : public EffectState { /* Effect gains for each channel */ ALfloat CurrentGains[MAX_OUTPUT_CHANNELS]{}; ALfloat TargetGains[MAX_OUTPUT_CHANNELS]{}; - } mChans[MAX_EFFECT_CHANNELS]; + } mChans[MAX_AMBI_CHANNELS]; ALfloat mSampleBuffer[BUFFERSIZE]{}; @@ -113,9 +113,8 @@ ALboolean ALequalizerState::deviceUpdate(const ALCdevice *UNUSED(device)) void ALequalizerState::update(const ALCcontext *context, const ALeffectslot *slot, const ALeffectProps *props, const EffectTarget target) { const ALCdevice *device = context->Device; - ALfloat frequency = static_cast<ALfloat>(device->Frequency); + auto frequency = static_cast<ALfloat>(device->Frequency); ALfloat gain, f0norm; - ALuint i; /* Calculate coefficients for the each type of filter. Note that the shelf * filters' gain is for the reference frequency, which is the centerpoint @@ -124,29 +123,25 @@ void ALequalizerState::update(const ALCcontext *context, const ALeffectslot *slo gain = maxf(sqrtf(props->Equalizer.LowGain), 0.0625f); /* Limit -24dB */ f0norm = props->Equalizer.LowCutoff/frequency; mChans[0].filter[0].setParams(BiquadType::LowShelf, gain, f0norm, - calc_rcpQ_from_slope(gain, 0.75f) - ); + calc_rcpQ_from_slope(gain, 0.75f)); gain = maxf(props->Equalizer.Mid1Gain, 0.0625f); f0norm = props->Equalizer.Mid1Center/frequency; mChans[0].filter[1].setParams(BiquadType::Peaking, gain, f0norm, - calc_rcpQ_from_bandwidth(f0norm, props->Equalizer.Mid1Width) - ); + calc_rcpQ_from_bandwidth(f0norm, props->Equalizer.Mid1Width)); gain = maxf(props->Equalizer.Mid2Gain, 0.0625f); f0norm = props->Equalizer.Mid2Center/frequency; mChans[0].filter[2].setParams(BiquadType::Peaking, gain, f0norm, - calc_rcpQ_from_bandwidth(f0norm, props->Equalizer.Mid2Width) - ); + calc_rcpQ_from_bandwidth(f0norm, props->Equalizer.Mid2Width)); gain = maxf(sqrtf(props->Equalizer.HighGain), 0.0625f); f0norm = props->Equalizer.HighCutoff/frequency; mChans[0].filter[3].setParams(BiquadType::HighShelf, gain, f0norm, - calc_rcpQ_from_slope(gain, 0.75f) - ); + calc_rcpQ_from_slope(gain, 0.75f)); /* Copy the filter coefficients for the other input channels. */ - for(i = 1;i < MAX_EFFECT_CHANNELS;i++) + for(size_t i{1u};i < slot->WetBuffer.size();++i) { mChans[i].filter[0].copyParamsFrom(mChans[0].filter[0]); mChans[i].filter[1].copyParamsFrom(mChans[0].filter[1]); @@ -156,9 +151,11 @@ void ALequalizerState::update(const ALCcontext *context, const ALeffectslot *slo mOutBuffer = target.FOAOut->Buffer; mOutChannels = target.FOAOut->NumChannels; - for(i = 0;i < MAX_EFFECT_CHANNELS;i++) - ComputePanGains(target.FOAOut, alu::Matrix::Identity()[i].data(), slot->Params.Gain, - mChans[i].TargetGains); + for(size_t i{0u};i < slot->WetBuffer.size();++i) + { + auto coeffs = GetAmbiIdentityRow(i); + ComputePanGains(target.FOAOut, coeffs.data(), slot->Params.Gain, mChans[i].TargetGains); + } } void ALequalizerState::process(ALsizei samplesToDo, const ALfloat (*RESTRICT samplesIn)[BUFFERSIZE], const ALsizei numInput, ALfloat (*RESTRICT samplesOut)[BUFFERSIZE], const ALsizei numOutput) diff --git a/Alc/effects/modulator.cpp b/Alc/effects/modulator.cpp index 62d5a7ad..5786b708 100644 --- a/Alc/effects/modulator.cpp +++ b/Alc/effects/modulator.cpp @@ -85,7 +85,7 @@ struct ALmodulatorState final : public EffectState { ALfloat CurrentGains[MAX_OUTPUT_CHANNELS]{}; ALfloat TargetGains[MAX_OUTPUT_CHANNELS]{}; - } mChans[MAX_EFFECT_CHANNELS]; + } mChans[MAX_AMBI_CHANNELS]; ALboolean deviceUpdate(const ALCdevice *device) override; @@ -107,9 +107,7 @@ ALboolean ALmodulatorState::deviceUpdate(const ALCdevice *UNUSED(device)) void ALmodulatorState::update(const ALCcontext *context, const ALeffectslot *slot, const ALeffectProps *props, const EffectTarget target) { - const ALCdevice *device = context->Device; - ALfloat f0norm; - ALsizei i; + const ALCdevice *device{context->Device}; mStep = fastf2i(props->Modulator.Frequency / static_cast<ALfloat>(device->Frequency) * WAVEFORM_FRACONE); mStep = clampi(mStep, 0, WAVEFORM_FRACONE-1); @@ -123,19 +121,21 @@ void ALmodulatorState::update(const ALCcontext *context, const ALeffectslot *slo else /*if(Slot->Params.EffectProps.Modulator.Waveform == AL_RING_MODULATOR_SQUARE)*/ mGetSamples = Modulate<Square>; - f0norm = props->Modulator.HighPassCutoff / static_cast<ALfloat>(device->Frequency); + ALfloat f0norm{props->Modulator.HighPassCutoff / static_cast<ALfloat>(device->Frequency)}; f0norm = clampf(f0norm, 1.0f/512.0f, 0.49f); /* Bandwidth value is constant in octaves. */ mChans[0].Filter.setParams(BiquadType::HighPass, 1.0f, f0norm, calc_rcpQ_from_bandwidth(f0norm, 0.75f)); - for(i = 1;i < MAX_EFFECT_CHANNELS;i++) + for(size_t i{1u};i < slot->WetBuffer.size();++i) mChans[i].Filter.copyParamsFrom(mChans[0].Filter); mOutBuffer = target.FOAOut->Buffer; mOutChannels = target.FOAOut->NumChannels; - for(i = 0;i < MAX_EFFECT_CHANNELS;i++) - ComputePanGains(target.FOAOut, alu::Matrix::Identity()[i].data(), slot->Params.Gain, - mChans[i].TargetGains); + for(size_t i{0u};i < slot->WetBuffer.size();++i) + { + auto coeffs = GetAmbiIdentityRow(i); + ComputePanGains(target.FOAOut, coeffs.data(), slot->Params.Gain, mChans[i].TargetGains); + } } void ALmodulatorState::process(ALsizei samplesToDo, const ALfloat (*RESTRICT samplesIn)[BUFFERSIZE], const ALsizei numInput, ALfloat (*RESTRICT samplesOut)[BUFFERSIZE], const ALsizei numOutput) diff --git a/OpenAL32/Include/alAuxEffectSlot.h b/OpenAL32/Include/alAuxEffectSlot.h index 45c780ef..7360d264 100644 --- a/OpenAL32/Include/alAuxEffectSlot.h +++ b/OpenAL32/Include/alAuxEffectSlot.h @@ -44,9 +44,6 @@ struct EffectStateFactory { }; -#define MAX_EFFECT_CHANNELS (4) - - using ALeffectslotArray = al::FlexArray<ALeffectslot*>; |