-
Notifications
You must be signed in to change notification settings - Fork 30
/
PhaserPatch.hpp
149 lines (106 loc) · 4.02 KB
/
PhaserPatch.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
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
////////////////////////////////////////////////////////////////////////////////////////////////////
/*
LICENSE:
This program 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.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*
class: Phaser
implemented by: Ross Bencina <[email protected]>
date: 24/8/98
Phaser is a six stage phase shifter, intended to reproduce the
sound of a traditional analogue phaser effect.
This implementation uses six first order all-pass filters in
series, with delay time modulated by a sinusoidal.
This implementation was created to be clear, not efficient.
Obvious modifications include using a table lookup for the lfo,
not updating the filter delay times every sample, and not
tuning all of the filters to the same delay time.
Thanks to:
The nice folks on the music-dsp mailing list, including...
Chris Towsend and Marc Lindahl
...and Scott Lehman's Phase Shifting page at harmony central:
http://www.harmony-central.com/Effects/Articles/Phase_Shifting/
*/
////////////////////////////////////////////////////////////////////////////////////////////////////
#ifndef __PhaserPatch_hpp__
#define __PhaserPatch_hpp__
#include "StompBox.h"
class PhaserPatch : public Patch {
public:
//initialise to some usefull defaults...
PhaserPatch() : _lfoPhase( 0.f ), depth( 1.f ), feedback( .7f ), _zm1( 0.f ){
registerParameter(PARAMETER_A, "Rate");
registerParameter(PARAMETER_B, "Depth");
registerParameter(PARAMETER_C, "Feedback");
registerParameter(PARAMETER_D, "");
Range( 440.f, 1600.f );
Rate( .5f );
}
void Range( float fMin, float fMax ){ // Hz
_dmin = fMin / (getSampleRate()/2.f);
_dmax = fMax / (getSampleRate()/2.f);
}
float Rate( float rate ){ // cps
_lfoInc = 2.f * M_PI * (rate / getSampleRate());
return _lfoInc * 1000.f;
}
void processAudio(AudioBuffer &buffer) {
int size = buffer.getSize();
float y;
rate = Rate(getParameterValue(PARAMETER_A));
depth = getParameterValue(PARAMETER_B);
feedback = getParameterValue(PARAMETER_C);
//calculate and update phaser sweep lfo...
float d = _dmin + (_dmax-_dmin) * ((sin( _lfoPhase ) + 1.f)/2.f);
_lfoPhase += rate;
if( _lfoPhase >= M_PI * 2.f )
_lfoPhase -= M_PI * 2.f;
//update filter coeffs
for( int i=0; i<6; i++ )
_alps[i].Delay( d );
// for (int ch = 0; ch<buffer.getChannels(); ++ch) {
float* buf = buffer.getSamples(0);
for (int i = 0; i < size; i++) {
//calculate output
y = _alps[0].Update(_alps[1].Update(_alps[2].Update(_alps[3].Update(_alps[4].Update(
_alps[5].Update( buf[i] + _zm1 * feedback ))))));
_zm1 = y;
buf[i] = buf[i] + y * depth;
// }
}
}
private:
class AllpassDelay{
public:
AllpassDelay()
: _a1( 0.f )
, _zm1( 0.f )
{}
void Delay( float delay ){ //sample delay time
_a1 = (1.f - delay) / (1.f + delay);
}
float Update( float inSamp ){
float y = inSamp * -_a1 + _zm1;
_zm1 = y * _a1 + inSamp;
return y;
}
private:
float _a1, _zm1;
};
AllpassDelay _alps[6];
float _dmin, _dmax; //range
float _lfoPhase;
float _lfoInc;
float depth, rate, feedback;
float _zm1;
};
#endif /* __PhaserPatch_hpp__ */