y@0
|
1 /*
|
y@0
|
2 ==============================================================================
|
y@0
|
3
|
y@0
|
4 This file was auto-generated!
|
y@0
|
5
|
y@0
|
6 It contains the basic startup code for a Juce application.
|
y@0
|
7
|
y@0
|
8 ==============================================================================
|
y@0
|
9 */
|
y@0
|
10
|
y@0
|
11 #include "PluginProcessor.h"
|
y@0
|
12 #include "PluginEditor.h"
|
y@0
|
13 #include "filter.h"
|
y@0
|
14
|
y@0
|
15
|
y@0
|
16 //==============================================================================
|
y@0
|
17 BassPedalRackProcessor::BassPedalRackProcessor()
|
y@0
|
18 {
|
y@0
|
19 // Set default values:
|
y@0
|
20
|
y@0
|
21 gain_ = 1.0; //Orignal volume set to one
|
y@0
|
22 index_ = 1.0; //Index is one by default
|
y@0
|
23 mix_ = 0.5; //as much low than high
|
y@0
|
24 gain1_ = 1.0; //fundamental =1
|
y@0
|
25 gain2_ = 0.0; //no other distortion
|
y@0
|
26 gain3_ = 0.0;
|
y@0
|
27 gain4_ = 0.0;
|
y@0
|
28 gain5_ = 0.0;
|
y@0
|
29 gain6_ = 0.0;
|
y@0
|
30 gain7_ = 0.0;
|
y@0
|
31 gain8_ = 0.0;
|
y@0
|
32 gain9_ = 0.0;
|
y@0
|
33
|
y@0
|
34 //neutral tone stack (even is it is not strictly an allpass filter)
|
y@0
|
35 trebleGain_ = 0.5;
|
y@0
|
36 bassGain_ = 0.5;
|
y@0
|
37 midGain_ = 0.5;
|
y@0
|
38 //filterLength
|
y@0
|
39 filterLength_ = 151;
|
y@0
|
40
|
y@0
|
41 toneStack_ = true;
|
y@0
|
42 shaper_ = false;
|
y@0
|
43
|
y@0
|
44 //circular buffers initialisation
|
y@0
|
45 currInd_ =0;
|
y@0
|
46 for (int i = 0; i < 3; i++)
|
y@0
|
47 {
|
y@0
|
48 memIn_[i] = 0;
|
y@0
|
49 memOut_[i] = 0;
|
y@0
|
50 }
|
y@0
|
51
|
y@0
|
52 for (int i = 0; i < 6; i++)
|
y@0
|
53 {
|
y@0
|
54 tonStackIn_[i] = 0;
|
y@0
|
55 tonStackIn_[i] = 0;
|
y@0
|
56 }
|
y@0
|
57
|
y@0
|
58
|
y@0
|
59 for (int i = 0; i < 2*filterLength_; i++)
|
y@0
|
60 inputMem_[i] = 0;
|
y@0
|
61
|
y@0
|
62
|
y@0
|
63 //Distortion coefficients initialisation
|
y@0
|
64 RC_ = 6.25*pow((double)10,-6);
|
y@0
|
65 RC2_ = RC_*RC_;
|
y@0
|
66 RC3_ = RC2_*RC_;
|
y@0
|
67
|
y@0
|
68 //allpass filter
|
y@0
|
69 highCut_ = 0;
|
y@0
|
70 lowCut_ = 0;
|
y@0
|
71
|
y@0
|
72 lastUIWidth_ = 550;
|
y@0
|
73 lastUIHeight_ = 350;
|
y@0
|
74
|
y@0
|
75 //initialise distortion
|
y@0
|
76 coeffs_[9] = 256*gain9_;
|
y@0
|
77 coeffs_[8] = 128*gain8_;
|
y@0
|
78 coeffs_[7] = -576*gain9_ + 64*gain7_;
|
y@0
|
79 coeffs_[6] = -256*gain8_ + 32*gain6_;
|
y@0
|
80 coeffs_[5] = 432*gain9_ -112*gain7_ + 16*gain5_;
|
y@0
|
81 coeffs_[4] = 160*gain8_ -48*gain6_ + 8*gain4_;
|
y@0
|
82 coeffs_[3] = -120*gain9_ + 56*gain7_ -20*gain5_ + 4*gain3_;
|
y@0
|
83 coeffs_[2] = -32*gain8_ + 18*gain6_ -8*gain4_ + 2*gain2_;
|
y@0
|
84 coeffs_[1] = 9*gain9_ -7*gain7_ + 5*gain5_ -3*gain3_ + gain1_;
|
y@0
|
85 coeffs_[0] = gain8_ - gain6_ + gain4_ - gain2_;
|
y@0
|
86 }
|
y@0
|
87
|
y@0
|
88 BassPedalRackProcessor::~BassPedalRackProcessor()
|
y@0
|
89 {
|
y@0
|
90 }
|
y@0
|
91
|
y@0
|
92 //==============================================================================
|
y@0
|
93 const String BassPedalRackProcessor::getName() const
|
y@0
|
94 {
|
y@0
|
95 return JucePlugin_Name;
|
y@0
|
96 }
|
y@0
|
97
|
y@0
|
98 int BassPedalRackProcessor::getNumParameters()
|
y@0
|
99 {
|
y@0
|
100 return kNumParameters;
|
y@0
|
101 }
|
y@0
|
102
|
y@0
|
103 float BassPedalRackProcessor::getParameter (int index)
|
y@0
|
104 {
|
y@0
|
105 // This method will be called by the host, probably on the audio thread, so
|
y@0
|
106 // it's absolutely time-critical. Don't use critical sections or anything
|
y@0
|
107 // UI-related, or anything at all that may block in any way!
|
y@0
|
108 switch (index)
|
y@0
|
109 {
|
y@0
|
110 case kMixParam: return mix_;
|
y@0
|
111 case kHighCutParam: return (float)highCut_;
|
y@0
|
112 case kIndexParam: return index_;
|
y@0
|
113 case kGainParam: return gain_;
|
y@0
|
114 case kLowCutParam: return (float)lowCut_;
|
y@0
|
115 case kGainLowParam: return bassGain_;
|
y@0
|
116 case kGainMidParam: return midGain_;
|
y@0
|
117 case kGainTreParam: return trebleGain_;
|
y@0
|
118 case kGain1Param: return gain1_;
|
y@0
|
119 case kGain2Param: return gain2_;
|
y@0
|
120 case kGain3Param: return gain3_;
|
y@0
|
121 case kGain4Param: return gain4_;
|
y@0
|
122 case kGain5Param: return gain5_;
|
y@0
|
123 case kGain6Param: return gain6_;
|
y@0
|
124 case kGain7Param: return gain7_;
|
y@0
|
125 case kGain8Param: return gain8_;
|
y@0
|
126 case kGain9Param: return gain9_;
|
y@0
|
127 default: return 0.0f;
|
y@0
|
128 }
|
y@0
|
129 }
|
y@0
|
130
|
y@0
|
131 void BassPedalRackProcessor::setParameter (int index, float newValue)
|
y@0
|
132 {
|
y@0
|
133 // This method will be called by the host, probably on the audio thread, so
|
y@0
|
134 // it's absolutely time-critical. Don't use critical sections or anything
|
y@0
|
135 // UI-related, or anything at all that may block in any way!
|
y@0
|
136 switch (index)
|
y@0
|
137 {
|
y@0
|
138 case kMixParam:
|
y@0
|
139 mix_ = newValue;
|
y@0
|
140 break;
|
y@0
|
141 case kHighCutParam:
|
y@0
|
142 highCut_ = (int)newValue;
|
y@0
|
143 break;
|
y@0
|
144 case kIndexParam:
|
y@0
|
145 index_ = newValue;
|
y@0
|
146 break;
|
y@0
|
147 case kGainParam:
|
y@0
|
148 gain_ = newValue;
|
y@0
|
149 break;
|
y@0
|
150 case kLowCutParam:
|
y@0
|
151 lowCut_ = (int)newValue;
|
y@0
|
152 break;
|
y@0
|
153 case kGainTreParam:
|
y@0
|
154 trebleGain_ = newValue;
|
y@0
|
155 changeToneStack();
|
y@0
|
156 break;
|
y@0
|
157 case kGainLowParam:
|
y@0
|
158 bassGain_ = newValue;
|
y@0
|
159 changeToneStack();
|
y@0
|
160 break;
|
y@0
|
161 case kGainMidParam:
|
y@0
|
162 midGain_ = newValue;
|
y@0
|
163 changeToneStack();
|
y@0
|
164 break;
|
y@0
|
165 case kGain1Param:
|
y@0
|
166 gain1_ = newValue;
|
y@0
|
167 changeCoefficients(kGain1Param);
|
y@0
|
168 break;
|
y@0
|
169 case kGain2Param:
|
y@0
|
170 gain2_ = newValue;
|
y@0
|
171 changeCoefficients(kGain2Param);
|
y@0
|
172 break;
|
y@0
|
173 case kGain3Param:
|
y@0
|
174 gain3_ = newValue;
|
y@0
|
175 changeCoefficients(kGain3Param);
|
y@0
|
176 break;
|
y@0
|
177 case kGain4Param:
|
y@0
|
178 gain4_ = newValue;
|
y@0
|
179 changeCoefficients(kGain4Param);
|
y@0
|
180 break;
|
y@0
|
181 case kGain5Param:
|
y@0
|
182 gain5_ = newValue;
|
y@0
|
183 changeCoefficients(kGain5Param);
|
y@0
|
184 break;
|
y@0
|
185 case kGain6Param:
|
y@0
|
186 gain6_ = newValue;
|
y@0
|
187 changeCoefficients(kGain6Param);
|
y@0
|
188 break;
|
y@0
|
189 case kGain7Param:
|
y@0
|
190 gain7_ = newValue;
|
y@0
|
191 changeCoefficients(kGain7Param);
|
y@0
|
192 break;
|
y@0
|
193 case kGain8Param:
|
y@0
|
194 gain8_ = newValue;
|
y@0
|
195 changeCoefficients(kGain8Param);
|
y@0
|
196 break;
|
y@0
|
197 case kGain9Param:
|
y@0
|
198 gain9_ = newValue;
|
y@0
|
199 changeCoefficients(kGain9Param);
|
y@0
|
200 break;
|
y@0
|
201 default:
|
y@0
|
202 break;
|
y@0
|
203 }
|
y@0
|
204 }
|
y@0
|
205
|
y@0
|
206 const String BassPedalRackProcessor::getParameterName (int index)
|
y@0
|
207 {
|
y@0
|
208 switch (index)
|
y@0
|
209 {
|
y@0
|
210 case kMixParam: return "mix";
|
y@0
|
211 case kLowCutParam: return "lowcut";
|
y@0
|
212 case kIndexParam: return "index";
|
y@0
|
213 case kGainParam: return "gain";
|
y@0
|
214 case kHighCutParam: return "highcut";
|
y@0
|
215 case kGainLowParam: return "low";
|
y@0
|
216 case kGainMidParam: return "mid";
|
y@0
|
217 case kGainTreParam: return "treble";
|
y@0
|
218 case kGain1Param: return "gain1";
|
y@0
|
219 case kGain2Param: return "gain2";
|
y@0
|
220 case kGain3Param: return "gain3";
|
y@0
|
221 case kGain4Param: return "gain4";
|
y@0
|
222 case kGain5Param: return "gain5";
|
y@0
|
223 case kGain6Param: return "gain6";
|
y@0
|
224 case kGain7Param: return "gain7";
|
y@0
|
225 case kGain8Param: return "gain8";
|
y@0
|
226 case kGain9Param: return "gain9";
|
y@0
|
227 default: break;
|
y@0
|
228 }
|
y@0
|
229
|
y@0
|
230 return String::empty;
|
y@0
|
231 }
|
y@0
|
232
|
y@0
|
233 const String BassPedalRackProcessor::getParameterText (int index)
|
y@0
|
234 {
|
y@0
|
235 return String (getParameter (index), 2);
|
y@0
|
236 }
|
y@0
|
237
|
y@0
|
238 const String BassPedalRackProcessor::getInputChannelName (int channelIndex) const
|
y@0
|
239 {
|
y@0
|
240 return String (channelIndex + 1);
|
y@0
|
241 }
|
y@0
|
242
|
y@0
|
243 const String BassPedalRackProcessor::getOutputChannelName (int channelIndex) const
|
y@0
|
244 {
|
y@0
|
245 return String (channelIndex + 1);
|
y@0
|
246 }
|
y@0
|
247
|
y@0
|
248 bool BassPedalRackProcessor::isInputChannelStereoPair (int index) const
|
y@0
|
249 {
|
y@0
|
250 return true;
|
y@0
|
251 }
|
y@0
|
252
|
y@0
|
253 bool BassPedalRackProcessor::isOutputChannelStereoPair (int index) const
|
y@0
|
254 {
|
y@0
|
255 return true;
|
y@0
|
256 }
|
y@0
|
257
|
y@0
|
258 bool BassPedalRackProcessor::silenceInProducesSilenceOut() const
|
y@0
|
259 {
|
y@0
|
260 #if JucePlugin_SilenceInProducesSilenceOut
|
y@0
|
261 return true;
|
y@0
|
262 #else
|
y@0
|
263 return false;
|
y@0
|
264 #endif
|
y@0
|
265 }
|
y@0
|
266
|
y@0
|
267 bool BassPedalRackProcessor::acceptsMidi() const
|
y@0
|
268 {
|
y@0
|
269 #if JucePlugin_WantsMidiInput
|
y@0
|
270 return true;
|
y@0
|
271 #else
|
y@0
|
272 return false;
|
y@0
|
273 #endif
|
y@0
|
274 }
|
y@0
|
275
|
y@0
|
276 bool BassPedalRackProcessor::producesMidi() const
|
y@0
|
277 {
|
y@0
|
278 #if JucePlugin_ProducesMidiOutput
|
y@0
|
279 return true;
|
y@0
|
280 #else
|
y@0
|
281 return false;
|
y@0
|
282 #endif
|
y@0
|
283 }
|
y@0
|
284
|
y@0
|
285 double BassPedalRackProcessor::getTailLengthSeconds() const
|
y@0
|
286 {
|
y@0
|
287 return 0;
|
y@0
|
288 }
|
y@0
|
289
|
y@0
|
290 int BassPedalRackProcessor::getNumPrograms()
|
y@0
|
291 {
|
y@0
|
292 return 0;
|
y@0
|
293 }
|
y@0
|
294
|
y@0
|
295 int BassPedalRackProcessor::getCurrentProgram()
|
y@0
|
296 {
|
y@0
|
297 return 0;
|
y@0
|
298 }
|
y@0
|
299
|
y@0
|
300 void BassPedalRackProcessor::setCurrentProgram (int index)
|
y@0
|
301 {
|
y@0
|
302 }
|
y@0
|
303
|
y@0
|
304 const String BassPedalRackProcessor::getProgramName (int index)
|
y@0
|
305 {
|
y@0
|
306 return String::empty;
|
y@0
|
307 }
|
y@0
|
308
|
y@0
|
309 void BassPedalRackProcessor::changeProgramName (int index, const String& newName)
|
y@0
|
310 {
|
y@0
|
311 }
|
y@0
|
312
|
y@0
|
313 //==============================================================================
|
y@0
|
314 void BassPedalRackProcessor::prepareToPlay (double sampleRate, int samplesPerBlock)
|
y@0
|
315 {
|
y@0
|
316 //initialise sampling frequency
|
y@0
|
317 fsd_ = 2*sampleRate;
|
y@0
|
318 fsd2_ = fsd_*fsd_;
|
y@0
|
319 fsd3_ = fsd2_*fsd_;
|
y@0
|
320
|
y@0
|
321 //initilise tone control
|
y@0
|
322 a0_ = 1;
|
y@0
|
323 changeToneStack();
|
y@0
|
324 }
|
y@0
|
325
|
y@0
|
326 void BassPedalRackProcessor::releaseResources()
|
y@0
|
327 {
|
y@0
|
328
|
y@0
|
329 }
|
y@0
|
330
|
y@0
|
331 void BassPedalRackProcessor::changeToneStack()
|
y@0
|
332 {
|
y@0
|
333 if (trebleGain_ + midGain_ + bassGain_ < 0.01 )
|
y@0
|
334 toneStack_ = false;
|
y@0
|
335 else
|
y@0
|
336 {
|
y@0
|
337 toneStack_ = true;
|
y@0
|
338 //Transfer function update
|
y@0
|
339 b1_ = (10*trebleGain_+80*midGain_+3240*bassGain_+81)*RC_;
|
y@0
|
340 b2_ = 16*(1120*trebleGain_-2025*midGain_*midGain_+81000*bassGain_*midGain_+2275*midGain_+14480*bassGain_+362)*RC2_*0.2;
|
y@0
|
341 b3_ = -512*(midGain_-40*bassGain_-1)*(280*trebleGain_+153*midGain_)*RC3_;
|
y@0
|
342 a1_ = (400*midGain_+16200*bassGain_+2247)*RC_*0.2;
|
y@0
|
343 a2_ = -16*(2025*midGain_*midGain_-81000*bassGain_*midGain_+2205*midGain_-193680*bassGain_-5962)*RC2_*0.2;
|
y@0
|
344 a3_ = -512*(midGain_-40*bassGain_-1)*(153*midGain_+280)*RC3_;
|
y@0
|
345
|
y@0
|
346 //Filter coefficient update
|
y@0
|
347 B0 = -b1_*fsd_ - b2_*fsd2_ - b3_*fsd3_;
|
y@0
|
348 B1 = -b1_*fsd_ + b2_*fsd2_ + 3*b3_*fsd3_;
|
y@0
|
349 B2 = b1_*fsd_ + b2_*fsd2_ - 3*b3_*fsd3_;
|
y@0
|
350 B3 = b1_*fsd_ - b2_*fsd2_ + b3_*fsd3_;
|
y@0
|
351 A0 = 1/( -a0_ - a1_*fsd_ - a2_*fsd2_ - a3_*fsd3_);
|
y@0
|
352 A1 = -3*a0_ - a1_*fsd_ + a2_*fsd2_ + 3*a3_*fsd3_;
|
y@0
|
353 A2 = -3*a0_ + a1_*fsd_ + a2_*fsd2_ - 3*a3_*fsd3_;
|
y@0
|
354 A3 = -a0_ + a1_*fsd_ - a2_*fsd2_ + a3_*fsd3_;
|
y@0
|
355 }
|
y@0
|
356
|
y@0
|
357 }
|
y@0
|
358
|
y@0
|
359 void BassPedalRackProcessor::changeCoefficients(int kcase)
|
y@0
|
360 {
|
y@0
|
361 if (abs(gain1_-1)<0.01 && (gain2_ + gain3_ + gain4_ + gain5_ + gain6_ + gain7_ + gain8_ + gain9_)<0.01)
|
y@0
|
362 {
|
y@0
|
363 shaper_ = false;
|
y@0
|
364 scale_ = 1;
|
y@0
|
365 }
|
y@0
|
366 else
|
y@0
|
367 {
|
y@0
|
368 shaper_ = true;
|
y@0
|
369 //scale by the sum of the gains time the distortion index
|
y@0
|
370 scale_ = (gain1_ + gain2_ + gain3_ + gain4_ + gain5_ + gain6_ + gain7_ + gain8_ + gain9_)*index_;
|
y@0
|
371 if (scale_>1)
|
y@0
|
372 scale_ = 1/scale_;
|
y@0
|
373 else
|
y@0
|
374 scale_ = 1;
|
y@0
|
375 //switch to avoid unecessary editing (even/odd and bigger indices that degree)
|
y@0
|
376 switch(kcase)
|
y@0
|
377 {
|
y@0
|
378 case 0: //Update all (initialisation)
|
y@0
|
379 coeffs_[9] = 256*gain9_;
|
y@0
|
380 coeffs_[8] = 128*gain8_;
|
y@0
|
381 coeffs_[7] = -576*gain9_ + 64*gain7_;
|
y@0
|
382 coeffs_[6] = -256*gain8_ + 32*gain6_;
|
y@0
|
383 coeffs_[5] = 432*gain9_ -112*gain7_ + 16*gain5_;
|
y@0
|
384 coeffs_[4] = 160*gain8_ -48*gain6_ + 8*gain4_;
|
y@0
|
385 coeffs_[3] = -120*gain9_ + 56*gain7_ -20*gain5_ + 4*gain3_;
|
y@0
|
386 coeffs_[2] = -32*gain8_ + 18*gain6_ -8*gain4_ + 2*gain2_;
|
y@0
|
387 coeffs_[1] = 9*gain9_ -7*gain7_ + 5*gain5_ -3*gain3_ + gain1_;
|
y@0
|
388 coeffs_[0] = gain8_ - gain6_ + gain4_ - gain2_;
|
y@0
|
389 break;
|
y@0
|
390 case kGain1Param:
|
y@0
|
391 coeffs_[1] = 9*gain9_ -7*gain7_ + 5*gain5_ -3*gain3_ + gain1_;
|
y@0
|
392 break;
|
y@0
|
393 case kGain2Param:
|
y@0
|
394 coeffs_[2] = -32*gain8_ + 18*gain6_ -8*gain4_ + 2*gain2_;
|
y@0
|
395 coeffs_[0] = gain8_ - gain6_ + gain4_ - gain2_;
|
y@0
|
396 break;
|
y@0
|
397 case kGain3Param:
|
y@0
|
398 coeffs_[3] = -120*gain9_ + 56*gain7_ -20*gain5_ + 4*gain3_;
|
y@0
|
399 coeffs_[1] = 9*gain9_ -7*gain7_ + 5*gain5_ -3*gain3_ + gain1_;
|
y@0
|
400 break;
|
y@0
|
401 case kGain4Param:
|
y@0
|
402 coeffs_[4] = 160*gain8_ -48*gain6_ + 8*gain4_;
|
y@0
|
403 coeffs_[2] = -32*gain8_ + 18*gain6_ -8*gain4_ + 2*gain2_;
|
y@0
|
404 coeffs_[0] = gain8_ - gain6_ + gain4_ - gain2_;
|
y@0
|
405 break;
|
y@0
|
406 case kGain5Param:
|
y@0
|
407 coeffs_[5] = 432*gain9_ -112*gain7_ + 16*gain5_;
|
y@0
|
408 coeffs_[3] = -120*gain9_ + 56*gain7_ -20*gain5_ + 4*gain3_;
|
y@0
|
409 coeffs_[1] = 9*gain9_ -7*gain7_ + 5*gain5_ -3*gain3_ + gain1_;
|
y@0
|
410 break;
|
y@0
|
411 case kGain6Param:
|
y@0
|
412 coeffs_[6] = -256*gain8_ + 32*gain6_;
|
y@0
|
413 coeffs_[4] = 160*gain8_ -48*gain6_ + 8*gain4_;
|
y@0
|
414 coeffs_[2] = -32*gain8_ + 18*gain6_ -8*gain4_ + 2*gain2_;
|
y@0
|
415 coeffs_[0] = gain8_ - gain6_ + gain4_ - gain2_;
|
y@0
|
416 break;
|
y@0
|
417 case kGain7Param:
|
y@0
|
418 coeffs_[7] = -576*gain9_ + 64*gain7_;
|
y@0
|
419 coeffs_[5] = 432*gain9_ -112*gain7_ + 16*gain5_;
|
y@0
|
420 coeffs_[3] = -120*gain9_ + 56*gain7_ -20*gain5_ + 4*gain3_;
|
y@0
|
421 coeffs_[1] = 9*gain9_ -7*gain7_ + 5*gain5_ -3*gain3_ + gain1_;
|
y@0
|
422 break;
|
y@0
|
423 case kGain8Param:
|
y@0
|
424 coeffs_[8] = 128*gain8_;
|
y@0
|
425 coeffs_[6] = -256*gain8_ + 32*gain6_;
|
y@0
|
426 coeffs_[4] = 160*gain8_ -48*gain6_ + 8*gain4_;
|
y@0
|
427 coeffs_[2] = -32*gain8_ + 18*gain6_ -8*gain4_ + 2*gain2_;
|
y@0
|
428 coeffs_[0] = gain8_ - gain6_ + gain4_ - gain2_;
|
y@0
|
429 break;
|
y@0
|
430 case kGain9Param:
|
y@0
|
431 coeffs_[9] = 256*gain9_;
|
y@0
|
432 coeffs_[7] = -576*gain9_ + 64*gain7_;
|
y@0
|
433 coeffs_[5] = 432*gain9_ -112*gain7_ + 16*gain5_;
|
y@0
|
434 coeffs_[3] = -120*gain9_ + 56*gain7_ -20*gain5_ + 4*gain3_;
|
y@0
|
435 coeffs_[1] = 9*gain9_ -7*gain7_ + 5*gain5_ -3*gain3_ + gain1_;
|
y@0
|
436 break;
|
y@0
|
437 }
|
y@0
|
438 }
|
y@0
|
439 }
|
y@0
|
440
|
y@0
|
441 double* BassPedalRackProcessor::applyFilter(float input)
|
y@0
|
442 {
|
y@0
|
443 double final[2]; //output
|
y@0
|
444 final[0] = 0;
|
y@0
|
445 final[1] = 0;
|
y@0
|
446 double output = 0; // temp output
|
y@0
|
447 lastIn_[filterInd_] = (double)input; //update the circular buffer with the new index
|
y@0
|
448 int firstMax = filterLength_ - filterInd_; //when indice reaches the end of the circular buffer
|
y@0
|
449 switch(highCut_)
|
y@0
|
450 { //switch for the index of the HIgh Pass filter
|
y@0
|
451 case 0:
|
y@0
|
452 output = input; //allpass
|
y@0
|
453 break;
|
y@0
|
454 case 1:
|
y@0
|
455 for (int i = 0; i< firstMax; i++) //until the end of the circular buffer
|
y@0
|
456 output += lastIn_[i+filterInd_]*filter_high_1[i];
|
y@0
|
457 for (int i = firstMax; i< filterLength_; i++) //from the beginning of the circular buffer
|
y@0
|
458 output += lastIn_[i+filterInd_-filterLength_]*filter_high_1[i];
|
y@0
|
459 break;
|
y@0
|
460 case 2:
|
y@0
|
461 for (int i = 0; i< firstMax; i++)
|
y@0
|
462 output += lastIn_[i+filterInd_]*filter_high_2[i];
|
y@0
|
463 for (int i = firstMax; i< filterLength_; i++)
|
y@0
|
464 output += lastIn_[i+filterInd_-filterLength_]*filter_high_2[i];
|
y@0
|
465 break;
|
y@0
|
466 case 3:
|
y@0
|
467 for (int i = 0; i< firstMax; i++)
|
y@0
|
468 output += lastIn_[i+filterInd_]*filter_high_3[i];
|
y@0
|
469 for (int i = firstMax; i< filterLength_; i++)
|
y@0
|
470 output += lastIn_[i+filterInd_-filterLength_]*filter_high_3[i];
|
y@0
|
471 break;
|
y@0
|
472 case 4:
|
y@0
|
473 for (int i = 0; i< firstMax; i++)
|
y@0
|
474 output += lastIn_[i+filterInd_]*filter_high_4[i];
|
y@0
|
475 for (int i = firstMax; i< filterLength_; i++)
|
y@0
|
476 output += lastIn_[i+filterInd_-filterLength_]*filter_high_4[i];
|
y@0
|
477 break;
|
y@0
|
478 case 5:
|
y@0
|
479 for (int i = 0; i< firstMax; i++)
|
y@0
|
480 output += lastIn_[i+filterInd_]*filter_high_5[i];
|
y@0
|
481 for (int i = firstMax; i< filterLength_; i++)
|
y@0
|
482 output += lastIn_[i+filterInd_-filterLength_]*filter_high_5[i];
|
y@0
|
483 break;
|
y@0
|
484 case 6:
|
y@0
|
485 for (int i = 0; i< firstMax; i++)
|
y@0
|
486 output += lastIn_[i+filterInd_]*filter_high_6[i];
|
y@0
|
487 for (int i = firstMax; i< filterLength_; i++)
|
y@0
|
488 output += lastIn_[i+filterInd_-filterLength_]*filter_high_6[i];
|
y@0
|
489 break;
|
y@0
|
490 case 7:
|
y@0
|
491 for (int i = 0; i< firstMax; i++)
|
y@0
|
492 output += lastIn_[i+filterInd_]*filter_high_7[i];
|
y@0
|
493 for (int i = firstMax; i< filterLength_; i++)
|
y@0
|
494 output += lastIn_[i+filterInd_-filterLength_]*filter_high_7[i];
|
y@0
|
495 break;
|
y@0
|
496 case 8:
|
y@0
|
497 for (int i = 0; i< firstMax; i++)
|
y@0
|
498 output += lastIn_[i+filterInd_]*filter_high_8[i];
|
y@0
|
499 for (int i = firstMax; i< filterLength_; i++)
|
y@0
|
500 output += lastIn_[i+filterInd_-filterLength_]*filter_high_8[i];
|
y@0
|
501 break;
|
y@0
|
502
|
y@0
|
503 case 9:
|
y@0
|
504 for (int i = 0; i< firstMax; i++)
|
y@0
|
505 output += lastIn_[i+filterInd_]*filter_high_9[i];
|
y@0
|
506 for (int i = firstMax; i< filterLength_; i++)
|
y@0
|
507 output += lastIn_[i+filterInd_-filterLength_]*filter_high_9[i];
|
y@0
|
508 break;
|
y@0
|
509 default:
|
y@0
|
510 break;
|
y@0
|
511 }
|
y@0
|
512 final[0] = output; //store the output
|
y@0
|
513 output = 0; //new output
|
y@0
|
514 switch(lowCut_)
|
y@0
|
515 { //switch over the Low pass Filter
|
y@0
|
516 case 0:
|
y@0
|
517 output = input;
|
y@0
|
518 break;
|
y@0
|
519 case 1:
|
y@0
|
520 for (int i = 0; i< firstMax; i++)
|
y@0
|
521 output += lastIn_[i+filterInd_]*filter_low_1[i];
|
y@0
|
522 for (int i = firstMax; i< filterLength_; i++)
|
y@0
|
523 output += lastIn_[i+filterInd_-filterLength_]*filter_low_1[i];
|
y@0
|
524 break;
|
y@0
|
525 case 2:
|
y@0
|
526 for (int i = 0; i< firstMax; i++)
|
y@0
|
527 output += lastIn_[i+filterInd_]*filter_low_2[i];
|
y@0
|
528 for (int i = firstMax; i< filterLength_; i++)
|
y@0
|
529 output += lastIn_[i+filterInd_-filterLength_]*filter_low_2[i];
|
y@0
|
530 break;
|
y@0
|
531 case 3:
|
y@0
|
532 for (int i = 0; i< firstMax; i++)
|
y@0
|
533 output += lastIn_[i+filterInd_]*filter_low_3[i];
|
y@0
|
534 for (int i = firstMax; i< filterLength_; i++)
|
y@0
|
535 output += lastIn_[i+filterInd_-filterLength_]*filter_low_3[i];
|
y@0
|
536 break;
|
y@0
|
537 case 4:
|
y@0
|
538 for (int i = 0; i< firstMax; i++)
|
y@0
|
539 output += lastIn_[i+filterInd_]*filter_low_4[i];
|
y@0
|
540 for (int i = firstMax; i< filterLength_; i++)
|
y@0
|
541 output += lastIn_[i+filterInd_-filterLength_]*filter_low_4[i];
|
y@0
|
542 break;
|
y@0
|
543 case 5:
|
y@0
|
544 for (int i = 0; i< firstMax; i++)
|
y@0
|
545 output += lastIn_[i+filterInd_]*filter_low_5[i];
|
y@0
|
546 for (int i = firstMax; i< filterLength_; i++)
|
y@0
|
547 output += lastIn_[i+filterInd_-filterLength_]*filter_low_5[i];
|
y@0
|
548 break;
|
y@0
|
549 case 6:
|
y@0
|
550 for (int i = 0; i< firstMax; i++)
|
y@0
|
551 output += lastIn_[i+filterInd_]*filter_low_6[i];
|
y@0
|
552 for (int i = firstMax; i< filterLength_; i++)
|
y@0
|
553 output += lastIn_[i+filterInd_-filterLength_]*filter_low_6[i];
|
y@0
|
554 break;
|
y@0
|
555 case 7:
|
y@0
|
556 for (int i = 0; i< firstMax; i++)
|
y@0
|
557 output += lastIn_[i+filterInd_]*filter_low_7[i];
|
y@0
|
558 for (int i = firstMax; i< filterLength_; i++)
|
y@0
|
559 output += lastIn_[i+filterInd_-filterLength_]*filter_low_7[i];
|
y@0
|
560 break;
|
y@0
|
561 case 8:
|
y@0
|
562 for (int i = 0; i< firstMax; i++)
|
y@0
|
563 output += lastIn_[i+filterInd_]*filter_low_8[i];
|
y@0
|
564 for (int i = firstMax; i< filterLength_; i++)
|
y@0
|
565 output += lastIn_[i+filterInd_-filterLength_]*filter_low_8[i];
|
y@0
|
566 break;
|
y@0
|
567 case 9:
|
y@0
|
568 for (int i = 0; i< firstMax; i++)
|
y@0
|
569 output += lastIn_[i+filterInd_]*filter_low_9[i];
|
y@0
|
570 for (int i = firstMax; i< filterLength_; i++)
|
y@0
|
571 output += lastIn_[i+filterInd_-filterLength_]*filter_low_9[i];
|
y@0
|
572 break;
|
y@0
|
573 default:
|
y@0
|
574 break;
|
y@0
|
575 }
|
y@0
|
576 final[1] = output; //update output
|
y@0
|
577 if (filterInd_==0) //update circular buffer indice (with modulo)
|
y@0
|
578 filterInd_=filterLength_-1;
|
y@0
|
579 else
|
y@0
|
580 filterInd_--;
|
y@0
|
581 return final;
|
y@0
|
582 }
|
y@0
|
583
|
y@0
|
584 float BassPedalRackProcessor::shaper(float x)
|
y@0
|
585 {
|
y@0
|
586 double output;
|
y@0
|
587 if(shaper_)
|
y@0
|
588 {
|
y@0
|
589 double dx = (double)x * index_; //distorted input
|
y@0
|
590 //efficient polynomial computation
|
y@0
|
591 output = coeffs_[9];
|
y@0
|
592 for (int ind = 8; ind > -1; ind--)
|
y@0
|
593 {
|
y@0
|
594 output = output*dx + coeffs_[ind];
|
y@0
|
595 }
|
y@0
|
596 output *=scale_;
|
y@0
|
597 }
|
y@0
|
598 else
|
y@0
|
599 output = (double)x;
|
y@0
|
600
|
y@0
|
601 return (float)output;
|
y@0
|
602 }
|
y@0
|
603
|
y@0
|
604 void BassPedalRackProcessor::saveMem(int channel)
|
y@0
|
605 {
|
y@0
|
606 //Store the information of this channel
|
y@0
|
607
|
y@0
|
608 //divided for the cirular buffer in config indice = 0;
|
y@0
|
609 int firstMax = filterLength_ - filterInd_;
|
y@0
|
610 for (int i=0; i < firstMax; i++)
|
y@0
|
611 {
|
y@0
|
612 //offset of the size of the buffer to have both buffer stored in inputMem;
|
y@0
|
613 inputMem_[channel*filterLength_ + i] = lastIn_[filterInd_ +i];
|
y@0
|
614 }
|
y@0
|
615 for (int i=firstMax; i < filterLength_; i++)
|
y@0
|
616 {
|
y@0
|
617 inputMem_[channel*filterLength_ + i] = lastIn_[filterInd_ + i - filterLength_];
|
y@0
|
618 }
|
y@0
|
619
|
y@0
|
620 //Switch for the little (3) circular buffers in configuration index = 2
|
y@0
|
621 switch(currInd_)
|
y@0
|
622 {
|
y@0
|
623 case 0:
|
y@0
|
624 tonStackIn_[channel*3] = memIn_[1];
|
y@0
|
625 tonStackIn_[channel*3+1] = memIn_[2];
|
y@0
|
626 tonStackIn_[channel*3+2] = memIn_[0];
|
y@0
|
627 tonStackOut_[channel*3] = memOut_[1];
|
y@0
|
628 tonStackOut_[channel*3+1] = memOut_[2];
|
y@0
|
629 tonStackOut_[channel*3+2] = memOut_[0];
|
y@0
|
630 break;
|
y@0
|
631 case 1:
|
y@0
|
632 tonStackOut_[channel*3] = memOut_[2];
|
y@0
|
633 tonStackOut_[channel*3+1] = memOut_[0];
|
y@0
|
634 tonStackOut_[channel*3+2] = memOut_[1];
|
y@0
|
635
|
y@0
|
636 tonStackIn_[channel*3] = memIn_[2];
|
y@0
|
637 tonStackIn_[channel*3+1] = memIn_[0];
|
y@0
|
638 tonStackIn_[channel*3+2] = memIn_[1];
|
y@0
|
639 break;
|
y@0
|
640 case 2:
|
y@0
|
641 tonStackOut_[channel*3] = memOut_[0];
|
y@0
|
642 tonStackOut_[channel*3+1] = memOut_[1];
|
y@0
|
643 tonStackOut_[channel*3+2] = memOut_[2];
|
y@0
|
644
|
y@0
|
645 tonStackIn_[channel*3] = memIn_[0];
|
y@0
|
646 tonStackIn_[channel*3+1] = memIn_[1];
|
y@0
|
647 tonStackIn_[channel*3+2] = memIn_[2];
|
y@0
|
648 break;
|
y@0
|
649 default:
|
y@0
|
650 break;
|
y@0
|
651 }
|
y@0
|
652 }
|
y@0
|
653
|
y@0
|
654 void BassPedalRackProcessor::loadMem(int channel)
|
y@0
|
655 {
|
y@0
|
656 //Relaod the information af the new channel
|
y@0
|
657 //Circular buffer for high and low pass filter
|
y@0
|
658 for (int i=0; i < filterLength_; i++)
|
y@0
|
659 {
|
y@0
|
660 lastIn_[i] = inputMem_[channel*filterLength_+i];
|
y@0
|
661 }
|
y@0
|
662 filterInd_ = 0;
|
y@0
|
663
|
y@0
|
664 //Circular buffers for Tone control
|
y@0
|
665 memIn_[0] = tonStackIn_[channel*3];
|
y@0
|
666 memIn_[1] = tonStackIn_[channel*3+1];
|
y@0
|
667 memIn_[2] = tonStackIn_[channel*3+2];
|
y@0
|
668 memOut_[0] = tonStackOut_[channel*3];
|
y@0
|
669 memOut_[1] = tonStackOut_[channel*3+1];
|
y@0
|
670 memOut_[2] = tonStackOut_[channel*3+2];
|
y@0
|
671 currInd_ = 2;
|
y@0
|
672 }
|
y@0
|
673
|
y@0
|
674 float BassPedalRackProcessor::applyToneStack(float input)
|
y@0
|
675 {
|
y@0
|
676 double di = (double)input;
|
y@0
|
677 double output = di;
|
y@0
|
678 switch(currInd_)
|
y@0
|
679 {
|
y@0
|
680
|
y@0
|
681 case 0:
|
y@0
|
682 if (toneStack_)
|
y@0
|
683 output = A0*(di*B0 + memIn_[1]*B1 + memIn_[2]*B2 + memIn_[0]*B3 -( memOut_[1]*A1 + memOut_[2]*A2 + memOut_[0]*A3));
|
y@0
|
684 memOut_[currInd_] = output;
|
y@0
|
685 memIn_[currInd_] = di;
|
y@0
|
686 currInd_ = 2;
|
y@0
|
687 break;
|
y@0
|
688 case 1:
|
y@0
|
689 if (toneStack_)
|
y@0
|
690 output = A0*(di*B0 + memIn_[2]*B1 + memIn_[0]*B2 + memIn_[1]*B3 -( memOut_[2]*A1 + memOut_[0]*A2 + memOut_[1]*A3));
|
y@0
|
691 memOut_[currInd_] = output;
|
y@0
|
692 memIn_[currInd_] = di;
|
y@0
|
693 currInd_ = 0;
|
y@0
|
694 break;
|
y@0
|
695 case 2:
|
y@0
|
696 if (toneStack_)
|
y@0
|
697 output = A0*(di*B0 + memIn_[0]*B1 + memIn_[1]*B2 + memIn_[2]*B3 -( memOut_[0]*A1 + memOut_[1]*A2 + memOut_[2]*A3));
|
y@0
|
698 memOut_[currInd_] = output;
|
y@0
|
699 memIn_[currInd_] = di;
|
y@0
|
700 currInd_ = 1;
|
y@0
|
701 break;
|
y@0
|
702 default:
|
y@0
|
703 break;
|
y@0
|
704 }
|
y@0
|
705
|
y@0
|
706 return (float)output;
|
y@0
|
707 }
|
y@0
|
708
|
y@0
|
709
|
y@0
|
710 void BassPedalRackProcessor::processBlock (AudioSampleBuffer& buffer, MidiBuffer& midiMessages)
|
y@0
|
711 {
|
y@0
|
712 // Helpful information about this block of samples:
|
y@0
|
713 const int numInputChannels = getNumInputChannels(); // How many input channels for our effect?
|
y@0
|
714 const int numOutputChannels = getNumOutputChannels(); // How many output channels for our effect?
|
y@0
|
715 const int numSamples = buffer.getNumSamples(); // How many samples in the buffer for this block?
|
y@0
|
716 // Go through each channel of audio that's passed in
|
y@0
|
717 double* filtered; //output of the high/low pass filter
|
y@0
|
718 float mixed; //mix of both
|
y@0
|
719 for (int channel = 0; channel < numInputChannels; ++channel)
|
y@0
|
720 {
|
y@0
|
721 // channelData is an array of length numSamples which contains the audio for one channel
|
y@0
|
722 float* channelData = buffer.getSampleData(channel);
|
y@0
|
723 loadMem(channel); //load the buffers for this channel
|
y@0
|
724 for (int i = 0; i < numSamples; ++i)
|
y@0
|
725 {
|
y@0
|
726 const float in = channelData[i];
|
y@0
|
727
|
y@0
|
728 filtered = applyFilter(in); //Apply Low and High Pass Filter
|
y@0
|
729
|
y@0
|
730 //mix the signal while adding distortion the scaled high frequencies
|
y@0
|
731 mixed = (1-mix_)*filtered[1] + mix_*shaper(filtered[0]);
|
y@0
|
732
|
y@0
|
733 //Apply the tone control and the final gain
|
y@0
|
734 channelData[i] = applyToneStack(mixed)*gain_;
|
y@0
|
735
|
y@0
|
736
|
y@0
|
737 }
|
y@0
|
738 saveMem(channel);
|
y@0
|
739
|
y@0
|
740 }
|
y@0
|
741
|
y@0
|
742 // In case we have more outputs than inputs, we'll clear any output
|
y@0
|
743 // channels that didn't contain input data, (because these aren't
|
y@0
|
744 // guaranteed to be empty - they may contain garbage).
|
y@0
|
745 for (int i = numInputChannels; i < numOutputChannels; ++i)
|
y@0
|
746 {
|
y@0
|
747 buffer.clear (i, 0, buffer.getNumSamples());
|
y@0
|
748 }
|
y@0
|
749 }
|
y@0
|
750
|
y@0
|
751 //==============================================================================
|
y@0
|
752 bool BassPedalRackProcessor::hasEditor() const
|
y@0
|
753 {
|
y@0
|
754 return true; // (change this to false if you choose to not supply an editor)
|
y@0
|
755 }
|
y@0
|
756
|
y@0
|
757 AudioProcessorEditor* BassPedalRackProcessor::createEditor()
|
y@0
|
758 {
|
y@0
|
759 return new BassPedalRackProcessorEditor (this);
|
y@0
|
760 }
|
y@0
|
761
|
y@0
|
762 //==============================================================================
|
y@0
|
763 void BassPedalRackProcessor::getStateInformation (MemoryBlock& destData)
|
y@0
|
764 {
|
y@0
|
765 // You should use this method to store your parameters in the memory block.
|
y@0
|
766 // You could do that either as raw data, or use the XML or ValueTree classes
|
y@0
|
767 // as intermediaries to make it easy to save and load complex data.
|
y@0
|
768
|
y@0
|
769 // Create an outer XML element..
|
y@0
|
770 XmlElement xml("C4DMPLUGINSETTINGS");
|
y@0
|
771
|
y@0
|
772 // add some attributes to it..
|
y@0
|
773 xml.setAttribute("uiWidth", lastUIWidth_);
|
y@0
|
774 xml.setAttribute("uiHeight", lastUIHeight_);
|
y@0
|
775 xml.setAttribute("mix", mix_);
|
y@0
|
776 xml.setAttribute("index", index_);
|
y@0
|
777 xml.setAttribute("gain", gain_);
|
y@0
|
778 xml.setAttribute("highcut", highCut_);
|
y@0
|
779 xml.setAttribute("treble", trebleGain_);
|
y@0
|
780 xml.setAttribute("lowcut", lowCut_);
|
y@0
|
781 xml.setAttribute("mid", midGain_);
|
y@0
|
782 xml.setAttribute("bass", bassGain_);
|
y@0
|
783 xml.setAttribute("gain1", gain1_);
|
y@0
|
784 xml.setAttribute("gain2", gain2_);
|
y@0
|
785 xml.setAttribute("gain3", gain3_);
|
y@0
|
786 xml.setAttribute("gain4", gain4_);
|
y@0
|
787 xml.setAttribute("gain5", gain5_);
|
y@0
|
788 xml.setAttribute("gain6", gain6_);
|
y@0
|
789 xml.setAttribute("gain7", gain7_);
|
y@0
|
790 xml.setAttribute("gain8", gain8_);
|
y@0
|
791 xml.setAttribute("gain9", gain9_);
|
y@0
|
792
|
y@0
|
793
|
y@0
|
794 // then use this helper function to stuff it into the binary blob and return it..
|
y@0
|
795 copyXmlToBinary(xml, destData);
|
y@0
|
796 }
|
y@0
|
797
|
y@0
|
798 void BassPedalRackProcessor::setStateInformation (const void* data, int sizeInBytes)
|
y@0
|
799 {
|
y@0
|
800 // You should use this method to restore your parameters from this memory block,
|
y@0
|
801 // whose contents will have been created by the getStateInformation() call.
|
y@0
|
802
|
y@0
|
803 // This getXmlFromBinary() helper function retrieves our XML from the binary blob..
|
y@0
|
804 ScopedPointer<XmlElement> xmlState (getXmlFromBinary (data, sizeInBytes));
|
y@0
|
805
|
y@0
|
806 if(xmlState != 0)
|
y@0
|
807 {
|
y@0
|
808 // make sure that it's actually our type of XML object..
|
y@0
|
809 if(xmlState->hasTagName("C4DMPLUGINSETTINGS"))
|
y@0
|
810 {
|
y@0
|
811 // ok, now pull out our parameters..
|
y@0
|
812 lastUIWidth_ = xmlState->getIntAttribute("uiWidth", lastUIWidth_);
|
y@0
|
813 lastUIHeight_ = xmlState->getIntAttribute("uiHeight", lastUIHeight_);
|
y@0
|
814
|
y@0
|
815 mix_ = (float)xmlState->getDoubleAttribute("mix", mix_);
|
y@0
|
816 index_ = (float)xmlState->getDoubleAttribute("index", index_);
|
y@0
|
817 gain_ = (float)xmlState->getDoubleAttribute("gain", gain_);
|
y@0
|
818 bassGain_ = (float)xmlState->getDoubleAttribute("bass", bassGain_);
|
y@0
|
819 midGain_ = (float)xmlState->getDoubleAttribute("mid", midGain_);
|
y@0
|
820 trebleGain_ = (float)xmlState->getDoubleAttribute("tre", trebleGain_);
|
y@0
|
821 highCut_ = (int)xmlState->getDoubleAttribute("highcut", highCut_);
|
y@0
|
822 lowCut_ = (int)xmlState->getDoubleAttribute("lowcut", lowCut_);
|
y@0
|
823 gain1_ = (float)xmlState->getDoubleAttribute("gain1", gain1_);
|
y@0
|
824 gain2_ = (float)xmlState->getDoubleAttribute("gain2", gain2_);
|
y@0
|
825 gain3_ = (float)xmlState->getDoubleAttribute("gain3", gain3_);
|
y@0
|
826 gain4_ = (float)xmlState->getDoubleAttribute("gain4", gain4_);
|
y@0
|
827 gain5_ = (float)xmlState->getDoubleAttribute("gain5", gain5_);
|
y@0
|
828 gain6_ = (float)xmlState->getDoubleAttribute("gain6", gain6_);
|
y@0
|
829 gain7_ = (float)xmlState->getDoubleAttribute("gain7", gain7_);
|
y@0
|
830 gain8_ = (float)xmlState->getDoubleAttribute("gain8", gain8_);
|
y@0
|
831 gain9_ = (float)xmlState->getDoubleAttribute("gain9", gain9_);
|
y@0
|
832 }
|
y@0
|
833 }
|
y@0
|
834 }
|
y@0
|
835
|
y@0
|
836 //==============================================================================
|
y@0
|
837 // This creates new instances of the plugin..
|
y@0
|
838 AudioProcessor* JUCE_CALLTYPE createPluginFilter()
|
y@0
|
839 {
|
y@0
|
840 return new BassPedalRackProcessor();
|
y@0
|
841 }
|