@@ -78,6 +78,10 @@ static inline void fluid_iir_filter_calculate_coefficients(R fres,
78
78
* bandwidth readjustment'. */
79
79
80
80
unsigned tab_idx = (fres - 1500 ) / CENTS_STEP;
81
+ R rem = (fres - 1500 ) / (unsigned int )CENTS_STEP;
82
+ LOG_FILTER (" %f hz vs. %f hz" ,
83
+ fluid_ct2hz ((tab_idx * CENTS_STEP) + 1500 ),
84
+ fluid_ct2hz (fres));
81
85
R sin_coeff = sincos_table[tab_idx].sin ;
82
86
R cos_coeff = sincos_table[tab_idx].cos ;
83
87
R alpha_coeff = sin_coeff / (2 .0f * q);
@@ -181,15 +185,6 @@ fluid_iir_filter_apply_local(fluid_iir_filter_t *iir_filter, fluid_real_t *dsp_b
181
185
/* IIR filter sample history */
182
186
fluid_real_t dsp_hist1 = iir_filter->hist1 ;
183
187
fluid_real_t dsp_hist2 = iir_filter->hist2 ;
184
-
185
- /* IIR filter coefficients */
186
- enum { N_COEFFS =
187
- #ifdef DBG_FILTER
188
- 1
189
- #else
190
- 16
191
- #endif
192
- };
193
188
194
189
/* IIR filter coefficients */
195
190
float dsp_a1 = iir_filter->a1 ;
@@ -204,6 +199,11 @@ fluid_iir_filter_apply_local(fluid_iir_filter_t *iir_filter, fluid_real_t *dsp_b
204
199
fluid_real_t dsp_amp_incr = iir_filter->amp_incr ;
205
200
float fres = iir_filter->last_fres ;
206
201
float q = iir_filter->last_q ;
202
+ float filter_gain = 1 .0f ;
203
+ if (GAIN_NORM)
204
+ {
205
+ filter_gain /= std::sqrt (q);
206
+ }
207
207
208
208
const float fres_incr = iir_filter->fres_incr ;
209
209
const float q_incr = iir_filter->q_incr ;
@@ -253,15 +253,27 @@ fluid_iir_filter_apply_local(fluid_iir_filter_t *iir_filter, fluid_real_t *dsp_b
253
253
--fres_incr_count;
254
254
fres += fres_incr;
255
255
}
256
- if (q_incr_count > 0 )
256
+ if (q_incr_count > 0 )
257
257
{
258
258
--q_incr_count;
259
259
q += q_incr;
260
+ if (GAIN_NORM)
261
+ {
262
+ filter_gain = 1 .0f / std::sqrt (q);
263
+ }
264
+ }
265
+
266
+ // Recalculate the filter coefficients without computing the inverse sqrt for the filter gain.
267
+ // Recalculating the filter gain is only required, when the Q value changes. When only fres changes, use the last filter gain.
268
+ fluid_iir_filter_calculate_coefficients<IIR_COEFF_T, false /* GAIN_NORM*/ , TYPE>(fres, q, output_rate, &dsp_a1, &dsp_a2, &dsp_b02, &dsp_b1);
269
+ if (GAIN_NORM)
270
+ {
271
+ // b1 must always be written back to global memory with the gain factor multiplied in
272
+ dsp_b1 *= filter_gain;
260
273
}
261
274
262
275
LOG_FILTER (" last_fres: %.2f Hz | target_fres: %.2f Hz |---| last_q: %.4f | target_q: %.4f" , iir_filter->last_fres , iir_filter->target_fres , iir_filter->last_q , iir_filter->target_q );
263
276
264
- fluid_iir_filter_calculate_coefficients<IIR_COEFF_T, GAIN_NORM, TYPE>(fres, q, output_rate, &dsp_a1, &dsp_a2, &dsp_b02, &dsp_b1);
265
277
}
266
278
}
267
279
0 commit comments