1 /* FluidSynth - A Software Synthesizer
3 * Copyright (C) 2003 Peter Hanappe and others.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public License
7 * as published by the Free Software Foundation; either version 2.1 of
8 * the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free
17 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 #ifndef _FLUID_IIR_FILTER_H
22 #define _FLUID_IIR_FILTER_H
24 #include "fluidsynth_priv.h"
26 typedef struct _fluid_iir_filter_t fluid_iir_filter_t;
28 DECLARE_FLUID_RVOICE_FUNCTION(fluid_iir_filter_init);
29 DECLARE_FLUID_RVOICE_FUNCTION(fluid_iir_filter_set_fres);
30 DECLARE_FLUID_RVOICE_FUNCTION(fluid_iir_filter_set_q);
32 void fluid_iir_filter_apply(fluid_iir_filter_t *iir_filter,
33 fluid_real_t *dsp_buf, int dsp_buf_count);
35 void fluid_iir_filter_reset(fluid_iir_filter_t *iir_filter);
37 void fluid_iir_filter_calc(fluid_iir_filter_t *iir_filter,
38 fluid_real_t output_rate,
39 fluid_real_t fres_mod);
41 /* We can't do information hiding here, as fluid_voice_t includes the struct
43 struct _fluid_iir_filter_t
45 enum fluid_iir_filter_type type; /* specifies the type of this filter */
46 enum fluid_iir_filter_flags flags; /* additional flags to customize this filter */
48 /* filter coefficients */
49 /* The coefficients are normalized to a0. */
50 /* b0 and b2 are identical => b02 */
51 fluid_real_t b02; /* b0 / a0 */
52 fluid_real_t b1; /* b1 / a0 */
53 fluid_real_t a1; /* a0 / a0 */
54 fluid_real_t a2; /* a1 / a0 */
56 fluid_real_t b02_incr;
60 int filter_coeff_incr_count;
61 int compensate_incr; /* Flag: If set, must compensate history */
62 fluid_real_t hist1, hist2; /* Sample history for the IIR filter */
63 int filter_startup; /* Flag: If set, the filter will be set directly.
64 Else it changes smoothly. */
66 fluid_real_t fres; /* the resonance frequency, in cents (not absolute cents) */
67 fluid_real_t last_fres; /* Current resonance frequency of the IIR filter */
68 /* Serves as a flag: A deviation between fres and last_fres */
69 /* indicates, that the filter has to be recalculated. */
70 fluid_real_t q_lin; /* the q-factor on a linear scale */
71 fluid_real_t filter_gain; /* Gain correction factor, depends on q */