-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathZoelzerMultiFilterPatch.hpp
68 lines (64 loc) · 2.23 KB
/
ZoelzerMultiFilterPatch.hpp
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
#ifndef __ZoelzerMultiFilterPatch_hpp__
#define __ZoelzerMultiFilterPatch_hpp__
#include "StompBox.h"
#include "BiquadFilter.h"
/**
http://www.musicdsp.org/showArchiveComment.php?ArchiveID=37
http://www.earlevel.com/main/2013/10/13/biquad-calculator-v2/
Type : biquad IIR
References : Udo Zoelzer: Digital Audio Signal Processing (John Wiley & Sons, ISBN 0 471 97226 6), Chris Townsend, Nigel Redmon
*/
// #define ZOELZER_FILTER_STAGES 2 // 4-pole, 24dB filter
#define ZOELZER_FILTER_STAGES 4 // 8-pole, 48dB filter
#define ZOELZER_LOWPASS_FILTER_MODE 0
#define ZOELZER_HIGHSHELF_FILTER_MODE 1
#define ZOELZER_PEAK_FILTER_MODE 2
#define ZOELZER_LOWSHELF_FILTER_MODE 3
#define ZOELZER_HIGHPASS_FILTER_MODE 4
#define ZOELZER_NOTCH_FILTER_MODE 5
#define ZOELZER_BANDPASS_FILTER_MODE 6
#define ZOELZER_MODES 5 // ignore notch and bandpass
class ZoelzerMultiFilterPatch : public Patch {
private:
BiquadFilter* filter;
public:
ZoelzerMultiFilterPatch(){
registerParameter(PARAMETER_A, "Mode");
registerParameter(PARAMETER_B, "Frequency");
registerParameter(PARAMETER_C, "Resonance");
registerParameter(PARAMETER_D, "Gain");
filter = BiquadFilter::create(ZOELZER_FILTER_STAGES);
}
void processAudio(AudioBuffer &buffer){
int mode = getParameterValue(PARAMETER_A)*ZOELZER_MODES;
float fc = getParameterValue(PARAMETER_B);
float q = getParameterValue(PARAMETER_C)*4+0.0001;
float gain = getParameterValue(PARAMETER_D);
switch(mode){
case ZOELZER_LOWPASS_FILTER_MODE:
filter->setLowPass(fc, q);
break;
case ZOELZER_HIGHPASS_FILTER_MODE:
filter->setHighPass(fc, q);
break;
case ZOELZER_BANDPASS_FILTER_MODE:
filter->setBandPass(fc, q);
break;
case ZOELZER_NOTCH_FILTER_MODE:
filter->setNotch(fc, q);
break;
case ZOELZER_PEAK_FILTER_MODE:
filter->setPeak(fc, q, gain);
break;
case ZOELZER_LOWSHELF_FILTER_MODE:
filter->setLowShelf(fc, gain);
break;
case ZOELZER_HIGHSHELF_FILTER_MODE:
filter->setHighShelf(fc, gain);
break;
}
FloatArray samples = buffer.getSamples(0);
filter->process(samples);
}
};
#endif // __ZoelzerMultiFilterPatch_hpp__