aboutsummaryrefslogtreecommitdiffstats
path: root/multiFilter.h
blob: 3d80d3ffee1c9359030c987ff78d81a31e96e9e7 (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
/*
 * 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:
    int filterSelection;
    int freq;
    int res;
    LowPassFilter lpf;
    StateVariable <NOTCH> nf;
    StateVariable <HIGHPASS> hpf;
    StateVariable <BANDPASS> bpf;

  public:
    
    Multifilter(int type){
        filterSelection = type;
    }
    
    /**
    * 0: Lowpass 1: Highpass, 2 : Bandpass, 3: Notch, 4 : Allpass.
    */
    int changeFilter(int selection) {
        if (filterSelection != selection){
            filterSelection = selection;
            setResonance(res);
            setCutoffFreq(freq);
        }
    }

    int setResonance(int resonance) {
        res = resonance;
        switch (filterSelection) {
        case 0:
            lpf.setResonance(resonance);
            break;
        case 1:
            // Oh non, c'est trop louuurd.
            //hpf.setResonance(map(resonance, 180, 1, 0, 255));
            // Approximation d'un mappage de valeurs de 0 à 255 vers 20 à 147.
            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;
        }
    }

    int setCutoffFreq(int cutoff) {
        freq = cutoff;
        switch (filterSelection) {
        case 0:
            lpf.setCutoffFreq(cutoff);
            break;
        case 1:
            // Approximation de mappage de valeurs de 0 à 255 vers 20 à 4100.
            hpf.setCentreFreq((cutoff<<4)+20);
            break;
        case 2:
            
            bpf.setCentreFreq((cutoff<<4)+20);
            break;
        case 3:
            
            nf.setCentreFreq((cutoff<<4)+20);
            break;
        }
    }

    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