Optimization of r415, try to avoid the division if possible.

This commit is contained in:
David Henningsson 2011-04-03 09:36:37 +00:00
parent fa73a202af
commit 5166e24569
2 changed files with 8 additions and 1 deletions

View file

@ -97,7 +97,7 @@ fluid_iir_filter_apply(fluid_iir_filter_t* iir_filter,
dsp_b1 += dsp_b1_incr; dsp_b1 += dsp_b1_incr;
/* Compensate history to avoid the filter going havoc with large frequency changes */ /* Compensate history to avoid the filter going havoc with large frequency changes */
if (fabs(dsp_b02) > 0.001) { if (iir_filter->compensate_incr && fabs(dsp_b02) > 0.001) {
fluid_real_t compensate = old_b02 / dsp_b02; fluid_real_t compensate = old_b02 / dsp_b02;
dsp_centernode *= compensate; dsp_centernode *= compensate;
dsp_hist1 *= compensate; dsp_hist1 *= compensate;
@ -211,6 +211,8 @@ fluid_iir_filter_calculate_coefficients(fluid_iir_filter_t* iir_filter,
/* both b0 -and- b2 */ /* both b0 -and- b2 */
fluid_real_t b02_temp = b1_temp * 0.5f; fluid_real_t b02_temp = b1_temp * 0.5f;
iir_filter->compensate_incr = 0;
if (iir_filter->filter_startup || (transition_samples == 0)) if (iir_filter->filter_startup || (transition_samples == 0))
{ {
/* The filter is calculated, because the voice was started up. /* The filter is calculated, because the voice was started up.
@ -240,6 +242,10 @@ fluid_iir_filter_calculate_coefficients(fluid_iir_filter_t* iir_filter,
iir_filter->a2_incr = (a2_temp - iir_filter->a2) / transition_samples; iir_filter->a2_incr = (a2_temp - iir_filter->a2) / transition_samples;
iir_filter->b02_incr = (b02_temp - iir_filter->b02) / transition_samples; iir_filter->b02_incr = (b02_temp - iir_filter->b02) / transition_samples;
iir_filter->b1_incr = (b1_temp - iir_filter->b1) / transition_samples; iir_filter->b1_incr = (b1_temp - iir_filter->b1) / transition_samples;
if (fabs(iir_filter->b02) > 0.0001) {
fluid_real_t quota = b02_temp / iir_filter->b02;
iir_filter->compensate_incr = quota < 0.5 || quota > 2;
}
/* Have to add the increments filter_coeff_incr_count times. */ /* Have to add the increments filter_coeff_incr_count times. */
iir_filter->filter_coeff_incr_count = transition_samples; iir_filter->filter_coeff_incr_count = transition_samples;
} }

View file

@ -58,6 +58,7 @@ struct _fluid_iir_filter_t
fluid_real_t a1_incr; fluid_real_t a1_incr;
fluid_real_t a2_incr; fluid_real_t a2_incr;
int filter_coeff_incr_count; int filter_coeff_incr_count;
int compensate_incr; /* Flag: If set, must compensate history */
fluid_real_t hist1, hist2; /* Sample history for the IIR filter */ fluid_real_t hist1, hist2; /* Sample history for the IIR filter */
int filter_startup; /* Flag: If set, the filter will be set directly. int filter_startup; /* Flag: If set, the filter will be set directly.
Else it changes smoothly. */ Else it changes smoothly. */