LMMS
Loading...
Searching...
No Matches
LatFilt.h
Go to the documentation of this file.
1/*
2 LatFilt.h
3
4 Copyright 2006 David Yeh <dtyeh@ccrma.stanford.edu>
5
6 Lattice digital filter.
7 Assumes order of b = order of a.
8 Assumes a0 = 1.
9
10*/
11/*
12 This program is free software; you can redistribute it and/or
13 modify it under the terms of the GNU General Public License
14 as published by the Free Software Foundation; either version 2
15 of the License, or (at your option) any later version.
16
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
25 02111-1307, USA or point your web browser to http://www.gnu.org.
26*/
27
28#ifndef _DSP_LatFilt_H_
29#define _DSP_LatFilt_H_
30
31namespace DSP {
32
33// ORDER is the highest power of s in the transfer function
34template <int ORDER>
36{
37 public:
38 double vcoef[ORDER+1];
39 double kcoef[ORDER];
40 double state[ORDER];
41 double y;
42
43 // fade factors
44 double vf[ORDER+1];
45 double kf[ORDER];
46
47
48 void reset()
49 {
50 for (int i = 0; i < ORDER; i++) {
51 state[i] = 0; // zero state
52 vf[i] = 1; // reset fade factor
53 kf[i] = 1;
54 }
55 vf[ORDER] = 1;
56 y = 0;
57 }
58
59 void init (double fs)
60 {
61 reset();
62 clearcoefs();
63 }
64
65 void clearcoefs() {
66 for (int i=0; i< ORDER; i++) {
67 vcoef[i] = 0;
68 kcoef[i] = 0;
69 }
70 vcoef[ORDER] = 0;
71 }
72
74 double tmp;
75
76 int i = ORDER-1;
77 tmp = -kcoef[i]*state[i] + s;
78 y = vcoef[i+1]*(state[i] + kcoef[i]*tmp);
79
80 for (i = ORDER-2; i >= 0; i--) {
81 tmp = -kcoef[i]*state[i] + tmp;
82 state[i+1] = kcoef[i]*tmp + state[i];
83 y = y + vcoef[i+1]*state[i+1];
84 }
85 state[0] = tmp;
86 y = y + vcoef[0]*tmp;
87
88 return (sample_t) y;
89 }
90
91 inline void set_vi(double coef, int i) {
92 vcoef[i] = coef;
93 }
94
95 inline void set_ki(double coef, int i) {
96 kcoef[i] = coef;
97 }
98};
99
100} /* namespace DSP */
101
102#endif /* _DSP_LatFilt_H_ */
LADSPA_Data sample_t
Definition basics.h:100
Definition LatFilt.h:36
double kcoef[ORDER]
Definition LatFilt.h:39
void init(double fs)
Definition LatFilt.h:59
void set_vi(double coef, int i)
Definition LatFilt.h:91
double vcoef[ORDER+1]
Definition LatFilt.h:38
void clearcoefs()
Definition LatFilt.h:65
void set_ki(double coef, int i)
Definition LatFilt.h:95
sample_t process(sample_t s)
Definition LatFilt.h:73
double y
Definition LatFilt.h:41
double state[ORDER]
Definition LatFilt.h:40
void reset()
Definition LatFilt.h:48
double vf[ORDER+1]
Definition LatFilt.h:44
double kf[ORDER]
Definition LatFilt.h:45
register unsigned i
Definition inflate.c:1575
unsigned s
Definition inflate.c:1555
Definition BiQuad.h:31