Move a couple functions into its related class

This commit is contained in:
Chris Robinson 2019-05-25 11:54:51 -07:00
parent 5b5dee07b4
commit 8ca97a7d9a
7 changed files with 39 additions and 45 deletions

View File

@ -933,11 +933,9 @@ void CalcPanningAndFilters(ALvoice *voice, const ALfloat xpos, const ALfloat ypo
if(gainHF != 1.0f) voice->mDirect.FilterType |= AF_LowPass;
if(gainLF != 1.0f) voice->mDirect.FilterType |= AF_HighPass;
voice->mDirect.Params[0].LowPass.setParams(BiquadType::HighShelf,
gainHF, hfScale, calc_rcpQ_from_slope(gainHF, 1.0f)
);
gainHF, hfScale, BiquadFilter::rcpQFromSlope(gainHF, 1.0f));
voice->mDirect.Params[0].HighPass.setParams(BiquadType::LowShelf,
gainLF, lfScale, calc_rcpQ_from_slope(gainLF, 1.0f)
);
gainLF, lfScale, BiquadFilter::rcpQFromSlope(gainLF, 1.0f));
for(ALsizei c{1};c < num_channels;c++)
{
voice->mDirect.Params[c].LowPass.copyParamsFrom(voice->mDirect.Params[0].LowPass);
@ -955,11 +953,9 @@ void CalcPanningAndFilters(ALvoice *voice, const ALfloat xpos, const ALfloat ypo
if(gainHF != 1.0f) voice->mSend[i].FilterType |= AF_LowPass;
if(gainLF != 1.0f) voice->mSend[i].FilterType |= AF_HighPass;
voice->mSend[i].Params[0].LowPass.setParams(BiquadType::HighShelf,
gainHF, hfScale, calc_rcpQ_from_slope(gainHF, 1.0f)
);
gainHF, hfScale, BiquadFilter::rcpQFromSlope(gainHF, 1.0f));
voice->mSend[i].Params[0].HighPass.setParams(BiquadType::LowShelf,
gainLF, lfScale, calc_rcpQ_from_slope(gainLF, 1.0f)
);
gainLF, lfScale, BiquadFilter::rcpQFromSlope(gainLF, 1.0f));
for(ALsizei c{1};c < num_channels;c++)
{
voice->mSend[i].Params[c].LowPass.copyParamsFrom(voice->mSend[i].Params[0].LowPass);

View File

@ -79,15 +79,13 @@ void DistortionState::update(const ALCcontext *context, const ALeffectslot *slot
*/
auto frequency = static_cast<ALfloat>(device->Frequency);
mLowpass.setParams(BiquadType::LowPass, 1.0f, cutoff / (frequency*4.0f),
calc_rcpQ_from_bandwidth(cutoff / (frequency*4.0f), bandwidth)
);
mLowpass.rcpQFromBandwidth(cutoff / (frequency*4.0f), bandwidth));
cutoff = props->Distortion.EQCenter;
/* Convert bandwidth in Hz to octaves. */
bandwidth = props->Distortion.EQBandwidth / (cutoff * 0.67f);
mBandpass.setParams(BiquadType::BandPass, 1.0f, cutoff / (frequency*4.0f),
calc_rcpQ_from_bandwidth(cutoff / (frequency*4.0f), bandwidth)
);
mBandpass.rcpQFromBandwidth(cutoff / (frequency*4.0f), bandwidth));
ALfloat coeffs[MAX_AMBI_CHANNELS];
CalcDirectionCoeffs({0.0f, 0.0f, -1.0f}, 0.0f, coeffs);

View File

@ -102,7 +102,7 @@ void EchoState::update(const ALCcontext *context, const ALeffectslot *slot, cons
const ALfloat gainhf{maxf(1.0f - props->Echo.Damping, 0.0625f)}; /* Limit -24dB */
mFilter.setParams(BiquadType::HighShelf, gainhf, LOWPASSFREQREF/frequency,
calc_rcpQ_from_slope(gainhf, 1.0f));
mFilter.rcpQFromSlope(gainhf, 1.0f));
mFeedGain = props->Echo.Feedback;

View File

@ -123,22 +123,22 @@ void EqualizerState::update(const ALCcontext *context, const ALeffectslot *slot,
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));
BiquadFilter::rcpQFromSlope(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));
BiquadFilter::rcpQFromBandwidth(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));
BiquadFilter::rcpQFromBandwidth(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));
BiquadFilter::rcpQFromSlope(gain, 0.75f));
/* Copy the filter coefficients for the other input channels. */
for(ALsizei i{1};i < slot->Wet.NumChannels;++i)

View File

@ -128,7 +128,7 @@ void ModulatorState::update(const ALCcontext *context, const ALeffectslot *slot,
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));
BiquadFilter::rcpQFromBandwidth(f0norm, 0.75f));
for(ALsizei i{1};i < slot->Wet.NumChannels;++i)
mChans[i].Filter.copyParamsFrom(mChans[0].Filter);

View File

@ -705,9 +705,9 @@ void T60Filter::calcCoeffs(const ALfloat length, const ALfloat lfDecayTime,
MidGain[1] = mfGain;
LFFilter.setParams(BiquadType::LowShelf, lfGain/mfGain, lf0norm,
calc_rcpQ_from_slope(lfGain/mfGain, 1.0f));
LFFilter.rcpQFromSlope(lfGain/mfGain, 1.0f));
HFFilter.setParams(BiquadType::HighShelf, hfGain/mfGain, hf0norm,
calc_rcpQ_from_slope(hfGain/mfGain, 1.0f));
HFFilter.rcpQFromSlope(hfGain/mfGain, 1.0f));
}
/* Update the early reflection line lengths and gain coefficients. */
@ -916,11 +916,11 @@ void ReverbState::update(const ALCcontext *Context, const ALeffectslot *Slot, co
*/
ALfloat gainhf{maxf(props->Reverb.GainHF, 0.001f)};
mFilter[0].Lp.setParams(BiquadType::HighShelf, gainhf, hf0norm,
calc_rcpQ_from_slope(gainhf, 1.0f));
mFilter[0].Lp.rcpQFromSlope(gainhf, 1.0f));
ALfloat lf0norm{minf(props->Reverb.LFReference / frequency, 0.49f)};
ALfloat gainlf{maxf(props->Reverb.GainLF, 0.001f)};
mFilter[0].Hp.setParams(BiquadType::LowShelf, gainlf, lf0norm,
calc_rcpQ_from_slope(gainlf, 1.0f));
mFilter[0].Hp.rcpQFromSlope(gainlf, 1.0f));
for(ALsizei i{1};i < NUM_LINES;i++)
{
mFilter[i].Lp.copyParamsFrom(mFilter[0].Lp);

View File

@ -57,8 +57,8 @@ public:
* BandPass filter types, or the cutoff frequency for the
* LowPass and HighPass filter types.
* \param rcpQ The reciprocal of the Q coefficient for the filter's
* transition band. Can be generated from calc_rcpQ_from_slope
* or calc_rcpQ_from_bandwidth as needed.
* transition band. Can be generated from rcpQFromSlope or
* rcpQFromBandwidth as needed.
*/
void setParams(BiquadType type, Real gain, Real f0norm, Real rcpQ);
@ -100,29 +100,29 @@ public:
z2_ = in*b2 - out*a2;
return out;
}
/**
* Calculates the rcpQ (i.e. 1/Q) coefficient for shelving filters, using
* the reference gain and shelf slope parameter.
* \param gain 0 < gain
* \param slope 0 < slope <= 1
*/
static Real rcpQFromSlope(Real gain, Real slope)
{ return std::sqrt((gain + 1.0f/gain)*(1.0f/slope - 1.0f) + 2.0f); }
/**
* Calculates the rcpQ (i.e. 1/Q) coefficient for filters, using the
* normalized reference frequency and bandwidth.
* \param f0norm 0 < f0norm < 0.5.
* \param bandwidth 0 < bandwidth
*/
static Real rcpQFromBandwidth(Real f0norm, Real bandwidth)
{
const Real w0{al::MathDefs<Real>::Tau() * f0norm};
return 2.0f*std::sinh(std::log(Real{2.0f})/2.0f*bandwidth*w0/std::sin(w0));
}
};
using BiquadFilter = BiquadFilterR<float>;
/**
* Calculates the rcpQ (i.e. 1/Q) coefficient for shelving filters, using the
* reference gain and shelf slope parameter.
* \param gain 0 < gain
* \param slope 0 < slope <= 1
*/
inline float calc_rcpQ_from_slope(float gain, float slope)
{ return std::sqrt((gain + 1.0f/gain)*(1.0f/slope - 1.0f) + 2.0f); }
/**
* Calculates the rcpQ (i.e. 1/Q) coefficient for filters, using the normalized
* reference frequency and bandwidth.
* \param f0norm 0 < f0norm < 0.5.
* \param bandwidth 0 < bandwidth
*/
inline float calc_rcpQ_from_bandwidth(float f0norm, float bandwidth)
{
const float w0{al::MathDefs<float>::Tau() * f0norm};
return 2.0f*std::sinh(std::log(2.0f)/2.0f*bandwidth*w0/std::sin(w0));
}
#endif /* FILTERS_BIQUAD_H */