Add some foaf and doap info to zynadd.ttl
[zyn.git] / analog_filter.h
blob1e3cd55fc0a1e0570206e255a1f804c0b499b492
1 /*
2 ZynAddSubFX - a software synthesizer
4 Analog Filter.h - Several analog filters (lowpass, highpass...)
5 Copyright (C) 2002-2005 Nasca Octavian Paul
6 Author: Nasca Octavian Paul
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of version 2 of the GNU General Public License
10 as published by the Free Software Foundation.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License (version 2) for more details.
17 You should have received a copy of the GNU General Public License (version 2)
18 along with this program; if not, write to the Free Software Foundation,
19 Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #ifndef ANALOG_FILTER_H
24 #define ANALOG_FILTER_H
26 struct analog_filter_stage
28 float c1;
29 float c2;
32 class AnalogFilter: public Filter_
34 public:
35 AnalogFilter() {};
36 ~AnalogFilter() {};
38 void init(float sample_rate, unsigned char type, float freq, float q_factor, unsigned char stages, float gain);
39 void filterout(float *smp);
40 void setfreq(float frequency);
41 void setfreq_and_q(float frequency,float q_);
42 void setq(float q_);
44 void settype(int type_);
45 void setgain(float dBgain);
46 void setstages(int stages_);
47 void cleanup();
49 // Obtains the response for a given frequency
50 float H(float freq);
52 private:
53 float m_sample_rate;
55 struct analog_filter_stage m_x[MAX_FILTER_STAGES + 1];
56 struct analog_filter_stage m_y[MAX_FILTER_STAGES + 1];
57 struct analog_filter_stage m_x_old[MAX_FILTER_STAGES + 1];
58 struct analog_filter_stage m_y_old[MAX_FILTER_STAGES + 1];
60 void
61 singlefilterout(
62 float * smp,
63 struct analog_filter_stage * x,
64 struct analog_filter_stage * y,
65 float * c,
66 float * d);
68 void computefiltercoefs();
70 int m_type; // The type of the filter, one of ZYN_FILTER_ANALOG_TYPE_XXX
71 int m_additional_stages; // how many times the filter is applied (0->1, 1->2, etc.)
72 float m_frequency; // Frequency given in Hz
73 float m_q_factor; // Q factor (resonance or Q factor)
74 float m_gain; // the gain of the filter (if are shelf/peak) filters
76 int m_order; // the order of the filter (number of poles)
78 // coefficients
79 float m_c[3];
80 float m_d[3];
82 // old coefficients(used only if some filter paremeters changes very fast, and it needs interpolation)
83 float m_c_old[3];
84 float m_d_old[3];
86 bool m_needs_interpolation;
87 bool m_first_time;
88 bool m_above_nq; // whether the frequency is above the nyquist
89 bool m_old_above_nq; // whether last time was above nyquist (used to see if it needs interpolation)
91 float m_interpolation_buffer[SOUND_BUFFER_SIZE];
94 #endif