Minot coding style fix
[zyn.git] / filter.cpp
blob95f4b448f688be36af28a374ee737d202fdc9b11
1 /*
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
23 #include <math.h>
24 #include <stdio.h>
25 #include <assert.h>
27 #include "globals.h"
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"
33 #include "filter.h"
35 void
36 Filter::init(float sample_rate, FilterParams *pars)
38 unsigned char Ftype=pars->Ptype;
40 m_category = pars->m_category;
42 switch (m_category)
44 case ZYN_FILTER_TYPE_FORMANT:
45 m_formant_filter.init(sample_rate, pars);
46 m_filter = &m_formant_filter;
47 break;
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;
51 break;
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;
55 break;
56 default:
57 assert(0);
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_)
78 m_filter->setq(q_);
81 REALTYPE
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
89 else
91 return freqpitch;