-
Notifications
You must be signed in to change notification settings - Fork 30
/
VidhaPatch.hpp
180 lines (125 loc) · 4.19 KB
/
VidhaPatch.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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
////////////////////////////////////////////////////////////////////////////////////////////////////
/*
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/>.
*/
/* created by the OWL team 2014 */
////////////////////////////////////////////////////////////////////////////////////////////////////
#ifndef __VidhaPatch_hpp__
#define __VidhaPatch_hpp__
#include "StompBox.h"
////////////////////////////////////////////////////////////////////////////////////////////////////
/*
Port of Vidha plugin by ArtyFX - http://openavproductions.com/artyfx/#vidha
*/
////////////////////////////////////////////////////////////////////////////////////////////////////
/** Widener
* A stereo width effect, which implements a mid-side width control, and
* right channel invert option.
**/
class Widener // : Effect
{
public:
Widener(int sr) :
samplerate( sr ),
/// dezipper init
w(10.0f / (sr * 0.02)),
a(0.70f),
b(1.0f / (1.0f - a)),
g1(0.0f),
g2(0.0f)
{
width = 0.5;
invertRight = false;
}
float getValue()
{
return width;
}
void setValue(float v)
{
if ( v < 0.f ) v = 0.f;
if ( v > 1.f ) v = 1.f;
// width parameters ranges from 0 (mono), to 2 (very-wide)
width = v*3;
}
void setInvert( bool i )
{
invertRight = i;
}
float getInvert()
{
return invertRight;
}
int getNumInputs() { return 2; }
int getNumOutputs(){ return 2; }
void process (long count, float* inL, float* inR, float* outL, float* outR)
{
/// smoothing algo is a lowpass, to de-zip movement
/// x^^4 approximates linear volume increase for human ears
g1 += w * (width - g1 - a * g2 - 1e-20f);
g2 += w * (b * g1 - g2 + 1e-20f);
float widthDeZip = g2;
// do mid-side width calculations
float tmp = 1 / max( 1 + widthDeZip , 2.f );
float mid = 1 * tmp;
float side = widthDeZip * tmp;
for (int i = 0; i < count; i++)
{
// apply mid / side coefficents
float m = ( *inL + *inR ) * mid;
float s = ( *inL - *inR ) * side;
// write output
*outL = m - s;
*outR = m + s;
if ( invertRight )
{
*outR = *outR * -1;
}
// move buffer pointers to next sample
inL++;
inR++;
outL++;
outR++;
}
}
private:
int samplerate;
float width;
bool invertRight;
/// dezipper filter state
float w, a, b, g1, g2;
};
////////////////////////////////////////////////////////////////////////////////////////////////////
class VidhaPatch : public Patch {
public:
float sampleRate;
Widener *wideMS;
bool invert;
VidhaPatch(){
sampleRate = 48000;
wideMS = new Widener(sampleRate);
invert = false;
registerParameter(PARAMETER_A, "Width");
registerParameter(PARAMETER_B, "Invert");
}
void processAudio(AudioBuffer &buffer){
if (PARAMETER_B < 0.5f) {invert = false;} else {invert = true;}
float size = buffer.getSize();
float* audioL = buffer.getSamples(0);
float* audioR = buffer.getSamples(1);
wideMS->setValue(getParameterValue(PARAMETER_A));
wideMS->setInvert(getParameterValue(PARAMETER_B));
wideMS->process(size, audioL, audioR, audioL, audioR);
}
};
#endif // __Vidha_Patch__