quantumVERB  1.0.0
A FOSS convolution reverb plugin
Convolution.cpp
1 /*
2 ==============================================================================
3 
4 Convolution.cpp
5 
6 ==============================================================================
7 */
8 
9 #include "Convolution.h"
10 
11 namespace reverb
12 {
13 
14  //==============================================================================
15  /**
16  * @brief Constructor. Creates a Convolution object.
17  *
18  * @details Creates a Convolution object associated to an AudioProcessor.
19  *
20  * @param [in] processor Pointer to main processor.
21  */
22  Convolution::Convolution(juce::AudioProcessor* processor)
23  : Task(processor)
24  {
25  }
26 
27  //==============================================================================
28  /**
29  * @brief No parameters to update, do nothing
30  */
32  const juce::String&)
33  {
34  }
35 
36  //==============================================================================
37  /**
38  * @brief Main function of the Convolution class. Executes the convolution of
39  * the audio buffer with the IR.
40  *
41  * @details Creates a ProcessContext object that specifies the audio buffer to
42  * convolve and the buffer to contain the resulted signal. Calls the
43  * juce::dsp::Convolution::process() function to compute the
44  * convolution.
45  *
46  * @param [in,out] audio The audio buffer to be convolved with the IR.
47  */
49  {
50  juce::dsp::ProcessContextReplacing<float> context(audio);
51  process(context);
52 
53  return audio;
54  }
55 
56  //==============================================================================
57  /**
58  * @brief Defines the main characteristics of the convolution process and loads
59  * the IR into the juce::dsp::Convolution object.
60  *
61  * @details Calls JUCE Convolution class's functions prepare() and
62  * copyAndLoadImpulseResponseFromBuffer().
63  *
64  * @param [in] ir The IR signal to convolve with the audio buffer.
65  */
66  void Convolution::loadIR(AudioBlock ir)
67  {
68  juce::dsp::ProcessSpec spec;
69  spec.sampleRate = processor->getSampleRate();
70 
71  // If the block size is small, the overlap-add method requires a small amount of RAM
72  // at the expense of increasing computational load. If the block size is large, the
73  // overlap-add method is more efficient computationally, at the expense of the memory
74  // required. It is relatively difficult to find an optimal block size, since the
75  // implementation is machine-dependent.
76  // https://books.google.ca/books?id=VQs_Ly4DYDMC&pg=PA130&lpg=PA130&dq=convolution+algorithm+optimal+block+size&source=bl&ots=jImfjKud-t&sig=SjLhgdAnfac0_6He7RBl0O-Snu8&hl=en&sa=X&ved=0ahUKEwj4y9367IDZAhWL24MKHV28AXoQ6AEIOzAD#v=onepage&q=convolution%20algorithm%20optimal%20block%20size&f=false
77  spec.maximumBlockSize = 2048;
78  spec.numChannels = (juce::uint32)ir.getNumChannels();
79 
80  // Must be called before loading the impulse response to provide to the convolution
81  // the maximumBufferSize to handle and the sample rate for optional resampling.
82  prepare(spec);
83 
84  copyAndLoadImpulseResponseFromBlock(ir, spec.sampleRate,
85  ir.getNumChannels() == 2,
86  false, false, 0);
87  }
88 }
float getParam(const juce::AudioProcessorValueTreeState &params, const juce::String &blockId) const
Internal method used to get (and check) a parameter&#39;s value.
Definition: Task.h:111
void loadIR(AudioBlock ir)
Defines the main characteristics of the convolution process and loads the IR into the juce::dsp::Conv...
Definition: Convolution.cpp:66
virtual AudioBlock exec(AudioBlock audio) override
Main function of the Convolution class. Executes the convolution of the audio buffer with the IR...
Definition: Convolution.cpp:48
Convolution(juce::AudioProcessor *processor)
Constructor. Creates a Convolution object.
Definition: Convolution.cpp:22
virtual void updateParams(const juce::AudioProcessorValueTreeState &params, const juce::String &="") override
No parameters to update, do nothing.
Definition: Convolution.cpp:31