-
Notifications
You must be signed in to change notification settings - Fork 1
/
Reverb.h
77 lines (70 loc) · 2.39 KB
/
Reverb.h
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
#ifndef REVERB_H
#define REVERB_H
#include <JuceHeader.h> // for JUCE classes
#include "Parameters.h" // for accessing parameters set by the user interface
/// Reverb class.
/// This class is a wrapper class around juce::Reverb that adds parameter
/// mapping so the effect can be controlled from the user interface.
class Reverb
{
public:
/// initialise parameters pointer
/// @param Parameters*, pointer to the parameters class
Reverb (Parameters* _param) :
param (_param)
{
}
/// initialise reverb
/// @param float, sample rate [Hz]
void prepareToPlay (float _sampleRate)
{
// reset reverb
resetReverb();
reverb.setSampleRate (_sampleRate);
}
/// apply reverb to an audio buffer
/// @param juce::AudioBuffer&, input audio buffer with samples
/// @param int, number of samples in the buffer
void processBlock (juce::AudioSampleBuffer& outputBuffer, int numSamples)
{
// check on/off switch
if (*param->reverbOnParam == false)
{
if (isReverbReset == false)
resetReverb();
return;
}
isReverbReset = false;
// process reverb
updateParameters();
int numChannels = outputBuffer.getNumChannels();
if (numChannels == 1)
reverb.processMono (outputBuffer.getWritePointer (0), numSamples);
else if (numChannels == 2)
reverb.processStereo (outputBuffer.getWritePointer (0), outputBuffer.getWritePointer (1), numSamples);
}
private:
// base members
juce::Reverb reverb; // reverb
Parameters* param; // pointer to parameters set by the user interface
bool isReverbReset; // flag for reseted reverb state
/// assign user interface parameters values to reverb
void updateParameters()
{
// set reverb parameters
juce::Reverb::Parameters reverbParameters;
reverbParameters.dryLevel = 1.0f - *param->reverbDryWetParam;
reverbParameters.wetLevel = 1.0f - reverbParameters.dryLevel;
reverbParameters.roomSize = *param->reverbRoomSizeParam;
reverbParameters.width = *param->reverbWidthParam;
reverbParameters.damping = *param->reverbDampingParam;
reverb.setParameters (reverbParameters);
}
/// reset reverb
void resetReverb()
{
reverb.reset();
isReverbReset = true;
}
};
#endif // REVERB_H