This repository has been archived by the owner on Jun 11, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPluginProcessor.cpp
491 lines (427 loc) · 15.9 KB
/
PluginProcessor.cpp
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
/*
==============================================================================
This file contains the basic framework code for a JUCE plugin processor.
==============================================================================
*/
#include "PluginProcessor.h"
#include "PluginEditor.h"
//==============================================================================
AndrewHp03delaySwitchAudioProcessor::AndrewHp03delaySwitchAudioProcessor()
#ifndef JucePlugin_PreferredChannelConfigurations
: AudioProcessor (BusesProperties()
#if ! JucePlugin_IsMidiEffect
#if ! JucePlugin_IsSynth
.withInput ("Input", juce::AudioChannelSet::stereo(), true)
#endif
.withOutput ("Output", juce::AudioChannelSet::stereo(), true)
#endif
)
#endif
{
addParameter(mDelayLMsecParam = new juce::AudioParameterFloat("Delay Left in M Sec",
"Delay L Time",
50.0f,
4000.0f,
1000.0f
));
addParameter(mDelayRMsecParam = new juce::AudioParameterFloat("Delay Right in M Sec",
"Delay R Time",
50.0f,
4000.0f,
1000.0f
));
addParameter(mWetDryMixParam = new juce::AudioParameterFloat("Wet/Dry Mix",
"Wet/Dry Mix",
0.0f,
100.0f,
50.0f
));
addParameter(mFeedbackDbParam = new juce::AudioParameterFloat("Feedback in db",
"Feedback",
0.0f,
100.0f,
100.0f
));
addParameter(mOffParam = new juce::AudioParameterBool("Delay Off",
"Off",
false
));
addParameter(mTappedParam = new juce::AudioParameterBool("Tapped Delay",
"Tapped",
false
));
addParameter(mPingPongParam = new juce::AudioParameterBool("Ping Pong Delay",
"Ping-Pong",
true
));
addParameter(mBothParam = new juce::AudioParameterBool("Both Delays",
"Both Delay",
false
));
addParameter(mFilterFcParamHigh = new juce::AudioParameterFloat("Filter Cutoff High (Hz)",
"High FC",
2000.0f,
20000.0f,
10000.0f
));
//Mid Params
addParameter(mFilterFcParamMid = new juce::AudioParameterFloat("Filter Cutoff Mid (Hz)",
"Mid FC",
200.0f,
2000.0f,
1000.0f
));
//Low params
addParameter(mFilterFcParamLow = new juce::AudioParameterFloat("Filter Cutoff Low (Hz)",
"Low FC",
20.0f,
200.0f,
100.0f
));
addParameter(mHighOnParam = new juce::AudioParameterBool("High On",
"High",
false
));
addParameter(mMidOnParam = new juce::AudioParameterBool("Mid On",
"Mid",
false
));
addParameter(mLowOnParam = new juce::AudioParameterBool("Low On",
"Low",
false
));
addParameter(mSyncParam = new juce::AudioParameterBool("Sync Echoes",
"Sync",
true
));
addParameter(mBothMixParam = new juce::AudioParameterFloat("Both delay mix",
"Both Mix",
0.0f,
100.0f,
50.0f
));
}
AndrewHp03delaySwitchAudioProcessor::~AndrewHp03delaySwitchAudioProcessor()
{
}
//==============================================================================
const juce::String AndrewHp03delaySwitchAudioProcessor::getName() const
{
return JucePlugin_Name;
}
bool AndrewHp03delaySwitchAudioProcessor::acceptsMidi() const
{
#if JucePlugin_WantsMidiInput
return true;
#else
return false;
#endif
}
bool AndrewHp03delaySwitchAudioProcessor::producesMidi() const
{
#if JucePlugin_ProducesMidiOutput
return true;
#else
return false;
#endif
}
bool AndrewHp03delaySwitchAudioProcessor::isMidiEffect() const
{
#if JucePlugin_IsMidiEffect
return true;
#else
return false;
#endif
}
double AndrewHp03delaySwitchAudioProcessor::getTailLengthSeconds() const
{
return 0.0;
}
int AndrewHp03delaySwitchAudioProcessor::getNumPrograms()
{
return 1; // NB: some hosts don't cope very well if you tell them there are 0 programs,
// so this should be at least 1, even if you're not really implementing programs.
}
int AndrewHp03delaySwitchAudioProcessor::getCurrentProgram()
{
return 0;
}
void AndrewHp03delaySwitchAudioProcessor::setCurrentProgram (int index)
{
}
const juce::String AndrewHp03delaySwitchAudioProcessor::getProgramName (int index)
{
return {};
}
void AndrewHp03delaySwitchAudioProcessor::changeProgramName (int index, const juce::String& newName)
{
}
int AndrewHp03delaySwitchAudioProcessor::calcMsecToSamps(float mSec)
{
return mSec * 0.001 * mFs;
}
//==============================================================================
void AndrewHp03delaySwitchAudioProcessor::prepareToPlay (double sampleRate, int samplesPerBlock)
{
// Use this method as the place to do any pre-playback
// initialisation that you need..
mFs = sampleRate;
//initialize with max delay length
int maxSamps = calcMsecToSamps(MAXDELAYMSEC);
mDelay1L.setMaximumDelay(maxSamps);
mDelay1R.setMaximumDelay(maxSamps);
//calcFilterCoeffs();
}
void AndrewHp03delaySwitchAudioProcessor::releaseResources()
{
// When playback stops, you can use this as an opportunity to free up any
// spare memory, etc.
}
#ifndef JucePlugin_PreferredChannelConfigurations
bool AndrewHp03delaySwitchAudioProcessor::isBusesLayoutSupported (const BusesLayout& layouts) const
{
#if JucePlugin_IsMidiEffect
juce::ignoreUnused (layouts);
return true;
#else
// This is the place where you check if the layout is supported.
// In this template code we only support mono or stereo.
if (layouts.getMainOutputChannelSet() != juce::AudioChannelSet::mono()
&& layouts.getMainOutputChannelSet() != juce::AudioChannelSet::stereo())
return false;
// This checks if the input layout matches the output layout
#if ! JucePlugin_IsSynth
if (layouts.getMainOutputChannelSet() != layouts.getMainInputChannelSet())
return false;
#endif
return true;
#endif
}
#endif
void AndrewHp03delaySwitchAudioProcessor::calcAlgorithmsParams()
{
//set gains
mWetGain = mWetDryMixParam->get() / 100.0;
mDryGain = 1.0 - mWetGain;
mPPGain = mBothMixParam->get() / 100.0;
mTGain = 1.0 - mPPGain;
mSync = mSyncParam->get();
//set delay time
//int samps = calcMsecToSamps(mDelayMsecParam->get());
int sampsL = calcMsecToSamps(mDelayLMsecParam->get());
int sampsR = calcMsecToSamps(mDelayRMsecParam->get());
if (mSync == true)
{
mDelay1L.setDelay(sampsL);
mDelay1R.setDelay(sampsL);
}
else
{
mDelay1L.setDelay(sampsL);
mDelay1R.setDelay(sampsR);
}
tapOffsetL = mDelayLMsecParam->get() / 1000;
tapOffsetR = mDelayRMsecParam->get() / 1000;
//set feedback gain
mFeedbackGainLin = mFeedbackDbParam->get() / 100;
mOff = mOffParam->get();
mTapped = mTappedParam->get();
mPingPong = mPingPongParam->get();
mBoth = mBothParam->get();
mHighOn = mHighOnParam->get();
mMidOn = mMidOnParam->get();
mLowOn = mLowOnParam->get();
//calc filter coefficients array of floats
float fcHigh = mFilterFcParamHigh->get();
float coeffs[5];
Mu45FilterCalc::calcCoeffsLPF(coeffs, fcHigh, 1.0, mFs);
//set coefficients for each filter
mFilterLHigh.setCoefficients(coeffs[0], coeffs[1], coeffs[2], coeffs[3], coeffs[4]);
mFilterRHigh.setCoefficients(coeffs[0], coeffs[1], coeffs[2], coeffs[3], coeffs[4]);
//calc peak filter
float fcMid = mFilterFcParamMid->get();
float gMid = -20.0;
Mu45FilterCalc::calcCoeffsPeak(coeffs, fcMid, gMid, 5.0, mFs);
//set coefficients for each filter
mFilterLMid.setCoefficients(coeffs[0], coeffs[1], coeffs[2], coeffs[3], coeffs[4]);
mFilterRMid.setCoefficients(coeffs[0], coeffs[1], coeffs[2], coeffs[3], coeffs[4]);
//calcHPF
float fcLow = mFilterFcParamLow->get();
Mu45FilterCalc::calcCoeffsHPF(coeffs, fcLow, 1.0, mFs);
//set coefficients for each filter
mFilterLLow.setCoefficients(coeffs[0], coeffs[1], coeffs[2], coeffs[3], coeffs[4]);
mFilterRLow.setCoefficients(coeffs[0], coeffs[1], coeffs[2], coeffs[3], coeffs[4]);
}
void AndrewHp03delaySwitchAudioProcessor::processBlock (juce::AudioBuffer<float>& buffer, juce::MidiBuffer& midiMessages)
{
juce::ScopedNoDenormals noDenormals;
auto totalNumInputChannels = getTotalNumInputChannels();
auto totalNumOutputChannels = getTotalNumOutputChannels();
// In case we have more outputs than inputs, this code clears any output
// channels that didn't contain input data, (because these aren't
// guaranteed to be empty - they may contain garbage).
// This is here to avoid people getting screaming feedback
// when they first compile a plugin, but obviously you don't need to keep
// this code if your algorithm always overwrites all the output channels.
for (auto i = totalNumInputChannels; i < totalNumOutputChannels; ++i)
buffer.clear(i, 0, buffer.getNumSamples());
//update params
calcAlgorithmsParams();
//process sample
auto* channelDataLeft = buffer.getWritePointer(0);
auto* channelDataRight = buffer.getWritePointer(1);
//temps
float outL, outR, tempL, tempR, tapSampL, tapSampR;
if (mOff == true)
{
mDelay1L.clear();
mDelay1R.clear();
for (int samp = 0; samp < buffer.getNumSamples(); samp++)
{
channelDataLeft[samp] = channelDataLeft[samp];
channelDataRight[samp] = channelDataRight[samp];
}
}
else if (mTapped == true)
{
for (int samp = 0; samp < buffer.getNumSamples(); samp++)
{
outL = channelDataLeft[samp];
outR = channelDataRight[samp];
tempL = mDelay1L.nextOut();
tempR = mDelay1R.nextOut();
//Feedback filters
if (mHighOn == true)
{
tempL = mFilterLHigh.tick(tempL);
tempR = mFilterRHigh.tick(tempR);
}
if (mMidOn == true)
{
tempL = mFilterLMid.tick(tempL);
tempR = mFilterRMid.tick(tempR);
}
if (mLowOn == true)
{
tempL = mFilterLLow.tick(tempL);
tempR = mFilterRLow.tick(tempR);
}
tapSampL = mDelay1L.tapOut(48000 * tapOffsetL) * .0625;
tapSampL += mDelay1L.tapOut(36000 * tapOffsetL) * .125;
tapSampL += mDelay1L.tapOut(24000 * tapOffsetL) * .25;
tapSampL += mDelay1L.tapOut(12000 * tapOffsetL) * .5;
tapSampR = mDelay1R.tapOut(48000 * tapOffsetR) * .0625;
tapSampR += mDelay1R.tapOut(36000 * tapOffsetR) * .125;
tapSampR += mDelay1R.tapOut(24000 * tapOffsetR) * .25;
tapSampR += mDelay1R.tapOut(12000 * tapOffsetR) * .5;
mDelay1L.tick(mWetGain * outL + mFeedbackGainLin * tempL);
mDelay1R.tick(mWetGain * outR + mFeedbackGainLin * tempR);
outL = (mDryGain * channelDataLeft[samp] + mWetGain * tempL) + tapSampL;
outR = (mDryGain * channelDataRight[samp] + mWetGain * tempR) + tapSampR;
//send to output
channelDataLeft[samp] = outL;
channelDataRight[samp] = outR;
}
}
else if (mPingPong == true)
{
for (int samp = 0; samp < buffer.getNumSamples(); samp++)
{
outL = (channelDataLeft[samp] + channelDataRight[samp]) / 2;
outR = channelDataRight[samp] / 2;
tempL = mDelay1R.nextOut();
tempR = mDelay1L.nextOut();
//Feedback filters
if (mHighOn == true)
{
tempL = mFilterLHigh.tick(tempL);
tempR = mFilterRHigh.tick(tempR);
}
if (mMidOn == true)
{
tempL = mFilterLMid.tick(tempL);
tempR = mFilterRMid.tick(tempR);
}
if (mLowOn == true)
{
tempL = mFilterLLow.tick(tempL);
tempR = mFilterRLow.tick(tempR);
}
mDelay1L.tick(mWetGain * outL + mFeedbackGainLin * tempL);
mDelay1R.tick(mWetGain * outR + mFeedbackGainLin * tempR);
outL = (mDryGain * outL + mWetGain * tempL);
outR = (mDryGain * outR + mWetGain * tempR);
//send to output
channelDataLeft[samp] = outL;
channelDataRight[samp] = outR;
}
}
else if (mBoth == true)
{
for (int samp = 0; samp < buffer.getNumSamples(); samp++)
{
outL = (channelDataLeft[samp] + channelDataRight[samp]) / 2;
outR = channelDataRight[samp] / 2;
tempL = mDelay1R.nextOut();
tempR = mDelay1L.nextOut();
//Feedback filters
if (mHighOn == true)
{
tempL = mFilterLHigh.tick(tempL);
tempR = mFilterRHigh.tick(tempR);
}
if (mMidOn == true)
{
tempL = mFilterLMid.tick(tempL);
tempR = mFilterRMid.tick(tempR);
}
if (mLowOn == true)
{
tempL = mFilterLLow.tick(tempL);
tempR = mFilterRLow.tick(tempR);
}
tapSampL = mDelay1L.tapOut(48000 * tapOffsetL) * .0625;
tapSampL += mDelay1L.tapOut(36000 * tapOffsetL) * .125;
tapSampL += mDelay1L.tapOut(24000 * tapOffsetL) * .25;
tapSampL += mDelay1L.tapOut(12000 * tapOffsetL) * .5;
tapSampR = mDelay1R.tapOut(48000 * tapOffsetR) * .0625;
tapSampR += mDelay1R.tapOut(36000 * tapOffsetR) * .125;
tapSampR += mDelay1R.tapOut(24000 * tapOffsetR) * .25;
tapSampR += mDelay1R.tapOut(12000 * tapOffsetR) * .5;
mDelay1L.tick(mWetGain * outL + mFeedbackGainLin * tempL);
mDelay1R.tick(mWetGain * outR + mFeedbackGainLin * tempR);
outL = (mDryGain * outL + mWetGain * tempL) + tapSampL;
outR = (mDryGain * outR + mWetGain * tempR) + tapSampR;
//send to output
channelDataLeft[samp] = outL;
channelDataRight[samp] = outR;
}
}
}
//==============================================================================
bool AndrewHp03delaySwitchAudioProcessor::hasEditor() const
{
return true; // (change this to false if you choose to not supply an editor)
}
juce::AudioProcessorEditor* AndrewHp03delaySwitchAudioProcessor::createEditor()
{
return new AndrewHp03delaySwitchAudioProcessorEditor (*this);
}
//==============================================================================
void AndrewHp03delaySwitchAudioProcessor::getStateInformation (juce::MemoryBlock& destData)
{
// You should use this method to store your parameters in the memory block.
// You could do that either as raw data, or use the XML or ValueTree classes
// as intermediaries to make it easy to save and load complex data.
}
void AndrewHp03delaySwitchAudioProcessor::setStateInformation (const void* data, int sizeInBytes)
{
// You should use this method to restore your parameters from this memory block,
// whose contents will have been created by the getStateInformation() call.
}
//==============================================================================
// This creates new instances of the plugin..
juce::AudioProcessor* JUCE_CALLTYPE createPluginFilter()
{
return new AndrewHp03delaySwitchAudioProcessor();
}