blob: 5d8a95eda8f5d50cc4e90eb528d06f1740d213d9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
/*
* multiFilter.h
*
* Copyright 2014 Guillaume Riou, Aude Forcione-Lambert & Nicolas Hurtubise.
*
* This file is part of Llammas.
*
* Llammas is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Llammas is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Llammas. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef MultiFilter_H
# define MultiFilter_H
# include <StateVariable.h>
# include <LowPassFilter.h>
class Multifilter {
private:
//Current selected filter
int filterSelection;
//Current filter frequency
int freq;
//Current filter resonance.
int res;
//Mozzi's lowpass filter.
LowPassFilter lpf;
//Mozzi's multimode filter in notch mode
StateVariable <NOTCH> nf;
//Mozzi's multimode filter in highpass mode
StateVariable <HIGHPASS> hpf;
//Mozzi's multimode filter in bandpass mode
StateVariable <BANDPASS> bpf;
public:
//Constructor. The type parameter is the type of the filter used at first.
Multifilter(int type){
filterSelection = type;
}
/**
*Changes the filter type and sets the new filter to the right value.
* 0: Lowpass 1: Highpass, 2 : Bandpass, 3: Notch, 4 : Allpass.
*/
int changeFilter(int selection) {
if (filterSelection != selection){
filterSelection = selection;
setResonance(res);
setCutoffFreq(freq);
}
}
/**
*Sets the resonance of the filter. Takes care of the conversion if they are needed.
*/
int setResonance(int resonance) {
res = resonance;
switch (filterSelection) {
case 0:
lpf.setResonance(resonance);
break;
case 1:
// maps values from 0-255 to 147-20
hpf.setResonance(180 - (resonance>>1) -33);
break;
case 2:
bpf.setResonance(180 - (resonance>>1) -33);
break;
case 3:
nf.setResonance(180 - (resonance>>1) -33);
break;
}
}
/**
*Sets the cutoff of the filter. Takes care of the conversion if they are needed.
*/
int setCutoffFreq(int cutoff) {
freq = cutoff;
switch (filterSelection) {
case 0:
lpf.setCutoffFreq(cutoff);
break;
case 1:
// maps values from 0-255 to 20-4100
hpf.setCentreFreq((cutoff<<4)+20);
break;
case 2:
bpf.setCentreFreq((cutoff<<4)+20);
break;
case 3:
nf.setCentreFreq((cutoff<<4)+20);
break;
}
}
/**
*returns the signal affected by the selected filter.
*/
int next(int signal) {
switch (filterSelection) {
case 0:
return lpf.next(signal);
case 1:
return hpf.next(signal);
case 2:
return bpf.next(signal);
case 3:
return nf.next(signal);
case 4:
return signal;
}
}
};
#endif
|