refactor(filter): cache coefficients and extract cutoff calculation
Add updateCoefficients() that short-circuits when cutoff, resonance, and type are unchanged. Cache ladderG and formantCoefficients so processSample() avoids redundant exp()/tan() calls per sample. Extract static getCutoffHz() from Filter::process() so FilterBank can compute the keytracked cutoff once per parallel branch instead of per sample. Simplify formant() and screamer() signatures to use cached state.
This commit is contained in:
@@ -39,6 +39,8 @@ void FilterBank::process (float* l, float* r, int numSamples, const FilterBankPa
|
||||
else if (p.route == (int) FilterRoute::Parallel)
|
||||
{
|
||||
// Run both filters on copies and crossfade.
|
||||
const float cutoff1 = p.f1On ? Filter::getCutoffHz (p.f1Cutoff, p.f1Key, noteHz) : 0.0f;
|
||||
const float cutoff2 = p.f2On ? Filter::getCutoffHz (p.f2Cutoff, p.f2Key, noteHz) : 0.0f;
|
||||
float f1l = 0.0f, f1r = 0.0f, f2l = 0.0f, f2r = 0.0f;
|
||||
for (int i = 0; i < numSamples; ++i)
|
||||
{
|
||||
@@ -46,13 +48,13 @@ void FilterBank::process (float* l, float* r, int numSamples, const FilterBankPa
|
||||
f2l = l[i]; f2r = r[i];
|
||||
if (p.f1On)
|
||||
{
|
||||
f1l = f1L.processSample (f1l, maps::cutoffToHz (p.f1Cutoff), p.f1Res, p.f1Drive, p.f1Type, p.f1Slope);
|
||||
f1r = f1R.processSample (f1r, maps::cutoffToHz (p.f1Cutoff), p.f1Res, p.f1Drive, p.f1Type, p.f1Slope);
|
||||
f1l = f1L.processSample (f1l, cutoff1, p.f1Res, p.f1Drive, p.f1Type, p.f1Slope);
|
||||
f1r = f1R.processSample (f1r, cutoff1, p.f1Res, p.f1Drive, p.f1Type, p.f1Slope);
|
||||
}
|
||||
if (p.f2On)
|
||||
{
|
||||
f2l = f2L.processSample (f2l, maps::cutoffToHz (p.f2Cutoff), p.f2Res, p.f2Drive, p.f2Type, p.f2Slope);
|
||||
f2r = f2R.processSample (f2r, maps::cutoffToHz (p.f2Cutoff), p.f2Res, p.f2Drive, p.f2Type, p.f2Slope);
|
||||
f2l = f2L.processSample (f2l, cutoff2, p.f2Res, p.f2Drive, p.f2Type, p.f2Slope);
|
||||
f2r = f2R.processSample (f2r, cutoff2, p.f2Res, p.f2Drive, p.f2Type, p.f2Slope);
|
||||
}
|
||||
const float m = p.mix;
|
||||
l[i] = f1l * (1.0f - m) + f2l * m;
|
||||
|
||||
Reference in New Issue
Block a user