1 // Copyright 2007 "Gilles Degottex"
3 // This file is part of "Music"
5 // "Music" is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published by
7 // the Free Software Foundation; either version 2.1 of the License, or
8 // (at your option) any later version.
10 // "Music" is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Lesser General Public License for more details.
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 /**************************************************************************
30 * Parks-McClellan algorithm for FIR filter design (C version)
31 *-------------------------------------------------
32 * Copyright (c) 1995,1998 Jake Janovetz (janovetz@uiuc.edu)
34 * This library is free software; you can redistribute it and/or
35 * modify it under the terms of the GNU Library General Public
36 * License as published by the Free Software Foundation; either
37 * version 2 of the License, or (at your option) any later version.
39 * This library is distributed in the hope that it will be useful,
40 * but WITHOUT ANY WARRANTY; without even the implied warranty of
41 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
42 * Library General Public License for more details.
44 * You should have received a copy of the GNU Library General Public
45 * License along with this library; if not, write to the Free
46 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
48 *************************************************************************/
51 #define DIFFERENTIATOR 2
57 // #define Pi 3.1415926535897932
58 // #define Pi2 6.2831853071795865
60 #define GRIDDENSITY 16
61 #define MAXITERATIONS 40
63 /* Function prototype for remez() - the only function that should need be
64 * called from external code
66 void remez(double h[], int numtaps,
67 int numband, double bands[], double des[], double weight[],
70 std::vector<double> fir1_lowpass(int n, double cutoff);
71 std::vector<double> fir1_highpass(int n, double cutoff);
72 std::vector<double> fir1_bandpass(int n, double low_cutoff, double high_cutoff);
79 virtual double operator()(double v)=0;
81 virtual int getLength()=0;
86 class FIRRTFilter : public RTFilter
88 std::vector<double> m_imp_res;
89 std::deque<double> m_to_filter;
92 FIRRTFilter(){m_imp_res=std::vector<double>(1, 1.0);}
93 FIRRTFilter(std::vector<double>& imp_res);
94 void setImpulseResponse(std::vector<double> imp_res) {m_imp_res=imp_res;}
96 virtual int getLength() {return m_imp_res.size();}
98 virtual double operator()(double v);
101 class RectangularHighPassRTFilter : public RTFilter
104 std::deque<double> m_summed_values;
108 RectangularHighPassRTFilter(int N=0);
111 virtual int getLength() {return m_N;}
113 virtual double operator()(double v);
115 class RectangularLowPassRTFilter : public RTFilter
118 virtual double operator()(double v);
120 class RectangularBandPassRTFilter : public RTFilter
123 virtual double operator()(double v);
126 class DummyRTFilter : public RTFilter
131 virtual int getLength() {return 1;}
133 virtual double operator()(double v) {return v;}