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:
+8
-2
@@ -23,9 +23,13 @@ public:
|
||||
|
||||
// Single-sample version (used by the comb/naive paths where convenient).
|
||||
float processSample (float in, float cutoffHz, float res, float drive, int type, int slope) noexcept;
|
||||
static float getCutoffHz (float cutoffNorm, float keytrack, float noteHz) noexcept;
|
||||
|
||||
private:
|
||||
double sr = 44100.0;
|
||||
float lastCutoffHz = -1.0f, lastRes = -1.0f;
|
||||
int lastType = -1;
|
||||
double ladderG = 0.0;
|
||||
|
||||
// TPT SVF state (also reused by formant/screamer).
|
||||
double ic1eq = 0.0, ic2eq = 0.0;
|
||||
@@ -42,15 +46,17 @@ private:
|
||||
|
||||
// Formant: three parallel bandpass SVFs (state pairs).
|
||||
std::array<std::array<double, 2>, 3> formantState { { { { 0.0, 0.0 } }, { { 0.0, 0.0 } }, { { 0.0, 0.0 } } } };
|
||||
std::array<std::array<double, 3>, 3> formantCoefficients {};
|
||||
|
||||
void updateCoefficients (float cutoffHz, float res, int type) noexcept;
|
||||
void updateSvf (double g, double k) noexcept;
|
||||
double svfLow (double in, double g, double k) noexcept;
|
||||
double svfBand (double in, double g, double k) noexcept;
|
||||
double svfHigh (double in, double g, double k) noexcept;
|
||||
double ladder (double in, double g, double res, double drive, int stages, bool diode) noexcept;
|
||||
double comb (double in, double freqHz, double res, double drive) noexcept;
|
||||
double formant (double in, double morph, double res) noexcept;
|
||||
double screamer (double in, double cutoffHz, double res, double drive) noexcept;
|
||||
double formant (double in) noexcept;
|
||||
double screamer (double in, double drive) noexcept;
|
||||
};
|
||||
|
||||
} // namespace serum
|
||||
|
||||
Reference in New Issue
Block a user