-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathSimpleStereoDelayPatch.hpp
85 lines (71 loc) · 3.16 KB
/
SimpleStereoDelayPatch.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
////////////////////////////////////////////////////////////////////////////////////////////////////
/*
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 2013, modified by Silvere Letellier for stereo capabilities */
////////////////////////////////////////////////////////////////////////////////////////////////////
#ifndef __SimpleStereoDelayPatch_hpp__
#define __SimpleStereoDelayPatch_hpp__
#include "StompBox.h"
#include "CircularBuffer.hpp"
#include "BiquadFilter.h"
class SimpleStereoDelayPatch : public Patch {
private:
static const int REQUEST_BUFFER_SIZE = 64*1024;
CircularBuffer* delayBufferL;
CircularBuffer* delayBufferR;
int delay;
float alpha, dryWet;
StereoBiquadFilter* highpass;
public:
SimpleStereoDelayPatch() : delay(0), alpha(0.04), dryWet(0.f)
{
registerParameter(PARAMETER_A, "Delay");
registerParameter(PARAMETER_B, "Feedback");
registerParameter(PARAMETER_C, "Input Level");
registerParameter(PARAMETER_D, "Dry/Wet");
delayBufferL = CircularBuffer::create(REQUEST_BUFFER_SIZE);
delayBufferR = CircularBuffer::create(REQUEST_BUFFER_SIZE);
highpass = StereoBiquadFilter::create(1);
highpass->setHighPass(40/(getSampleRate()/2), FilterStage::BUTTERWORTH_Q); // dc filter
}
~SimpleStereoDelayPatch(){
CircularBuffer::destroy(delayBufferL);
CircularBuffer::destroy(delayBufferR);
StereoBiquadFilter::destroy(highpass);
}
void processAudio(AudioBuffer &buffer){
float gain = getParameterValue(PARAMETER_C)*2;
float delayTime = 0.05+0.95*getParameterValue(PARAMETER_A);
float feedback = getParameterValue(PARAMETER_B);
int32_t newDelay;
newDelay = alpha*delayTime*(delayBufferL->getSize()-1) + (1-alpha)*delay; // Smoothing
dryWet = alpha*getParameterValue(PARAMETER_D) + (1-alpha)*dryWet; // Smoothing
FloatArray left = buffer.getSamples(LEFT_CHANNEL);
FloatArray right = buffer.getSamples(RIGHT_CHANNEL);
int size = buffer.getSize();
highpass->process(buffer);
for (int n = 0; n < size; n++){
float sample = gain*left[n];
float dly = (delayBufferL->read(delay)*(size-1-n) + delayBufferL->read(newDelay)*n)/size;
delayBufferL->write(feedback * dly + sample);
left[n] = dly*dryWet + (1.f - dryWet) * sample; // dry/wet
sample = gain*right[n];
dly = (delayBufferR->read(delay)*(size-1-n) + delayBufferR->read(newDelay)*n)/size;
delayBufferR->write(feedback * dly + sample);
right[n] = dly*dryWet + (1.f - dryWet) * sample; // dry/wet
}
delay = newDelay;
}
};
#endif // __SimpleStereoDelayPatch_hpp__