commit 33f16b1d6550a28b023605ee7ff534a1d6909e28
parent bf45378ec123f8f1422807b6e01adfcf402a9007
Author: Ricard Wanderlof <polluxsynth@butoba.net>
Date: Mon, 14 Mar 2022 23:44:24 +0100
AnalogFilter: Only effect Q change if more than 10% (#347)
In a similar vein to setfreq(), only force recompute of Q if the
value is more than 10% from the previous value, in order to minimize
the number of coefficient recomputations needed.
Diffstat:
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/src/DSP/AnalogFilter.cpp b/src/DSP/AnalogFilter.cpp
@@ -301,7 +301,13 @@ void AnalogFilter::setfreq(float frequency)
void AnalogFilter::setfreq_and_q(float frequency, float q_)
{
- if (q != q_) { // TODO: Compare diff or ratio to some form of epsilon ?
+ /*
+ * Only recompute based on Q change if change is more than 10%
+ * from current value (or the old or new Q is 0, which normally
+ * won't occur, but better to handle it than potentially
+ * fail on division by zero or assert).
+ */
+ if (q == 0.0 || q_ == 0.0 || ((q > q_ ? q / q_ : q_ / q) > 1.1)) {
q = q_;
recompute = true;
}