diff --git a/dsp/fn529fe0.cpp b/dsp/fn529fe0.cpp index 87f8cc1..5fdc60a 100644 --- a/dsp/fn529fe0.cpp +++ b/dsp/fn529fe0.cpp @@ -9,9 +9,13 @@ namespace fn529fe0 { -void iir1(float* x, const double* A, const double* B, size_t nbin, double /*acc0*/) { +void iir1(float* x, const double* A, const double* B, size_t nbin, double acc0) { // leaky first-order: y = A*acc + B*x ; acc = y (B = 1-A from live tables) - double acc = 0.0; + // State persists across calls via static accumulator (per-thread). + static thread_local double acc = 0.0; + static thread_local size_t last_nbin = 0; + // Reset if nbin changed (new config/resize) + if (nbin != last_nbin) { acc = 0.0; last_nbin = nbin; } for (size_t i = 0; i < nbin; i++) { double y = A[i] * acc + B[i] * static_cast(x[i]); acc = y;