2 ZynAddSubFX - a software synthesizer
4 Filter.C - Filters, uses analog,formant,etc. filters
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
28 #include "filter_base.h"
29 #include "filter_parameters.h"
30 #include "analog_filter.h"
31 #include "sv_filter.h"
32 #include "formant_filter.h"
36 Filter::init(float sample_rate
, FilterParams
*pars
)
38 unsigned char Ftype
=pars
->Ptype
;
40 m_category
= pars
->m_category
;
44 case ZYN_FILTER_TYPE_FORMANT
:
45 m_formant_filter
.init(sample_rate
, pars
);
46 m_filter
= &m_formant_filter
;
48 case ZYN_FILTER_TYPE_STATE_VARIABLE
:
49 m_sv_filter
.init(sample_rate
, Ftype
, 1000.0, pars
->getq(), pars
->m_additional_stages
, pars
->m_gain
);
50 m_filter
= &m_sv_filter
;
52 case ZYN_FILTER_TYPE_ANALOG
:
53 m_analog_filter
.init(sample_rate
, Ftype
, 1000.0, pars
->getq(), pars
->m_additional_stages
, pars
->m_gain
);
54 m_filter
= &m_analog_filter
;
61 void Filter::filterout(REALTYPE
*smp
)
63 m_filter
->filterout(smp
);
66 void Filter::setfreq(REALTYPE frequency
)
68 m_filter
->setfreq(frequency
);
71 void Filter::setfreq_and_q(REALTYPE frequency
,REALTYPE q_
)
73 m_filter
->setfreq_and_q(frequency
,q_
);
76 void Filter::setq(REALTYPE q_
)
82 Filter::getrealfreq(REALTYPE freqpitch
)
84 if (m_category
== ZYN_FILTER_TYPE_ANALOG
||
85 m_category
== ZYN_FILTER_TYPE_STATE_VARIABLE
)
87 return pow(2.0,freqpitch
+9.96578428); // log2(1000)=9.95748