JUCE-7.0.12-0-g4f43011b96 JUCE-7.0.12-0-g4f43011b96
JUCE — C++ application framework with suport for VST, VST3, LV2 audio plug-ins

« « « Anklang Documentation
Loading...
Searching...
No Matches
juce_Chorus.h
Go to the documentation of this file.
1 /*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11 Agreement and JUCE Privacy Policy.
12
13 End User License Agreement: www.juce.com/juce-7-licence
14 Privacy Policy: www.juce.com/juce-privacy-policy
15
16 Or: You may also use this code under the terms of the GPL v3 (see
17 www.gnu.org/licenses).
18
19 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
21 DISCLAIMED.
22
23 ==============================================================================
24*/
25
26namespace juce::dsp
27{
28
44template <typename SampleType>
45class Chorus
46{
47public:
48 //==============================================================================
50 Chorus();
51
52 //==============================================================================
56 void setRate (SampleType newRateHz);
57
60 void setDepth (SampleType newDepth);
61
65 void setCentreDelay (SampleType newDelayMs);
66
70 void setFeedback (SampleType newFeedback);
71
75 void setMix (SampleType newMix);
76
77 //==============================================================================
79 void prepare (const ProcessSpec& spec);
80
82 void reset();
83
84 //==============================================================================
86 template <typename ProcessContext>
87 void process (const ProcessContext& context) noexcept
88 {
89 const auto& inputBlock = context.getInputBlock();
90 auto& outputBlock = context.getOutputBlock();
91 const auto numChannels = outputBlock.getNumChannels();
92 const auto numSamples = outputBlock.getNumSamples();
93
94 jassert (inputBlock.getNumChannels() == numChannels);
95 jassert (inputBlock.getNumChannels() == lastOutput.size());
96 jassert (inputBlock.getNumSamples() == numSamples);
97
98 if (context.isBypassed)
99 {
100 outputBlock.copyFrom (inputBlock);
101 return;
102 }
103
104 auto delayValuesBlock = AudioBlock<SampleType> (bufferDelayTimes).getSubBlock (0, numSamples);
106 delayValuesBlock.clear();
107
108 osc.process (contextDelay);
109 delayValuesBlock.multiplyBy (oscVolume);
110
111 auto* delaySamples = bufferDelayTimes.getWritePointer (0);
112
113 for (size_t i = 0; i < numSamples; ++i)
114 {
115 auto lfo = jmax (static_cast<SampleType> (1.0), maximumDelayModulation * delaySamples[i] + centreDelay);
116 delaySamples[i] = static_cast<SampleType> (lfo * sampleRate / 1000.0);
117 }
118
119 dryWet.pushDrySamples (inputBlock);
120
121 for (size_t channel = 0; channel < numChannels; ++channel)
122 {
123 auto* inputSamples = inputBlock .getChannelPointer (channel);
124 auto* outputSamples = outputBlock.getChannelPointer (channel);
125
126 for (size_t i = 0; i < numSamples; ++i)
127 {
128 auto input = inputSamples[i];
129 auto output = input - lastOutput[channel];
130
131 delay.pushSample ((int) channel, output);
132 delay.setDelay (delaySamples[i]);
133 output = delay.popSample ((int) channel);
134
135 outputSamples[i] = output;
136 lastOutput[channel] = output * feedbackVolume[channel].getNextValue();
137 }
138 }
139
140 dryWet.mixWetSamples (outputBlock);
141 }
142
143private:
144 //==============================================================================
145 void update();
146
147 //==============================================================================
152 DryWetMixer<SampleType> dryWet;
153 std::vector<SampleType> lastOutput { 2 };
154 AudioBuffer<SampleType> bufferDelayTimes;
155
156 double sampleRate = 44100.0;
157 SampleType rate = 1.0, depth = 0.25, feedback = 0.0, mix = 0.5,
158 centreDelay = 7.0;
159
160 static constexpr SampleType maxDepth = 1.0,
161 maxCentreDelayMs = 100.0,
162 oscVolumeMultiplier = 0.5,
163 maximumDelayModulation = 20.0;
164};
165
166} // namespace juce::dsp
Type * getWritePointer(int channelNumber) noexcept
Returns a writeable pointer to one of the buffer's channels.
A utility class for values that need smoothing to avoid audio glitches.
A simple chorus DSP widget that modulates the delay of a delay line in order to create sweeping notch...
Definition juce_Chorus.h:46
void setFeedback(SampleType newFeedback)
Sets the feedback volume (between -1 and 1) of the chorus delay line.
void setDepth(SampleType newDepth)
Sets the volume of the LFO modulating the chorus delay line (between 0 and 1).
void prepare(const ProcessSpec &spec)
Initialises the processor.
void setMix(SampleType newMix)
Sets the amount of dry and wet signal in the output of the chorus (between 0 for full dry and 1 for f...
void reset()
Resets the internal state variables of the processor.
void process(const ProcessContext &context) noexcept
Processes the input and output samples supplied in the processing context.
Definition juce_Chorus.h:87
Chorus()
Constructor.
void setRate(SampleType newRateHz)
Sets the rate (in Hz) of the LFO modulating the chorus delay line.
void setCentreDelay(SampleType newDelayMs)
Sets the centre delay in milliseconds of the chorus delay line modulation.
A delay line processor featuring several algorithms for the fractional delay calculation,...
Generates a signal based on a user-supplied function.
#define jassert(expression)
Platform-independent assertion macro.
constexpr Type jmax(Type a, Type b)
Returns the larger of two values.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
Definition juce_Memory.h:88
T size(T... args)
This structure is passed into a DSP algorithm's prepare() method, and contains information about vari...