LMMS
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
27{
28namespace dsp
29{
30
46template <typename SampleType>
47class Chorus
48{
49public:
50 //==============================================================================
52 Chorus();
53
54 //==============================================================================
58 void setRate (SampleType newRateHz);
59
62 void setDepth (SampleType newDepth);
63
67 void setCentreDelay (SampleType newDelayMs);
68
72 void setFeedback (SampleType newFeedback);
73
77 void setMix (SampleType newMix);
78
79 //==============================================================================
81 void prepare (const ProcessSpec& spec);
82
84 void reset();
85
86 //==============================================================================
88 template <typename ProcessContext>
89 void process (const ProcessContext& context) noexcept
90 {
91 const auto& inputBlock = context.getInputBlock();
92 auto& outputBlock = context.getOutputBlock();
93 const auto numChannels = outputBlock.getNumChannels();
94 const auto numSamples = outputBlock.getNumSamples();
95
96 jassert (inputBlock.getNumChannels() == numChannels);
97 jassert (inputBlock.getNumChannels() == lastOutput.size());
98 jassert (inputBlock.getNumSamples() == numSamples);
99
100 if (context.isBypassed)
101 {
102 outputBlock.copyFrom (inputBlock);
103 return;
104 }
105
106 auto delayValuesBlock = AudioBlock<SampleType>(bufferDelayTimes).getSubBlock (0, numSamples);
107 auto contextDelay = ProcessContextReplacing<SampleType> (delayValuesBlock);
108 delayValuesBlock.clear();
109
110 osc.process (contextDelay);
111 delayValuesBlock.multiplyBy (oscVolume);
112
113 auto* delaySamples = bufferDelayTimes.getWritePointer (0);
114
115 for (size_t i = 0; i < numSamples; ++i)
116 {
117 auto lfo = jmax (static_cast<SampleType> (1.0), maximumDelayModulation * delaySamples[i] + centreDelay);
118 delaySamples[i] = static_cast<SampleType> (lfo * sampleRate / 1000.0);
119 }
120
121 dryWet.pushDrySamples (inputBlock);
122
123 for (size_t channel = 0; channel < numChannels; ++channel)
124 {
125 auto* inputSamples = inputBlock .getChannelPointer (channel);
126 auto* outputSamples = outputBlock.getChannelPointer (channel);
127
128 for (size_t i = 0; i < numSamples; ++i)
129 {
130 auto input = inputSamples[i];
131 auto output = input - lastOutput[channel];
132
133 delay.pushSample ((int) channel, output);
134 delay.setDelay (delaySamples[i]);
135 output = delay.popSample ((int) channel);
136
137 outputSamples[i] = output;
138 lastOutput[channel] = output * feedbackVolume[channel].getNextValue();
139 }
140 }
141
142 dryWet.mixWetSamples (outputBlock);
143 }
144
145private:
146 //==============================================================================
147 void update();
148
149 //==============================================================================
153 std::vector<SmoothedValue<SampleType, ValueSmoothingTypes::Linear>> feedbackVolume { 2 };
155 std::vector<SampleType> lastOutput { 2 };
157
158 double sampleRate = 44100.0;
159 SampleType rate = 1.0, depth = 0.25, feedback = 0.0, mix = 0.5,
161
162 static constexpr SampleType maxDepth = 1.0,
166};
167
168} // namespace dsp
169} // namespace juce
Type jmax(const Type a, const Type b)
Definition MathsFunctions.h:48
Definition juce_AudioSampleBuffer.h:34
Definition juce_SmoothedValue.h:227
Definition juce_AudioBlock.h:70
AudioBlock getSubBlock(size_t newOffset, size_t newLength) const noexcept
Definition juce_AudioBlock.h:371
std::vector< SmoothedValue< SampleType, ValueSmoothingTypes::Linear > > feedbackVolume
Definition juce_Chorus.h:153
Chorus()
Definition juce_Chorus.cpp:33
void setCentreDelay(SampleType newDelayMs)
Definition juce_Chorus.cpp:60
void prepare(const ProcessSpec &spec)
Definition juce_Chorus.cpp:87
void setMix(SampleType newMix)
Definition juce_Chorus.cpp:77
Oscillator< SampleType > osc
Definition juce_Chorus.h:150
SampleType depth
Definition juce_Chorus.h:159
AudioBuffer< SampleType > bufferDelayTimes
Definition juce_Chorus.h:156
static constexpr SampleType maxCentreDelayMs
Definition juce_Chorus.h:163
double sampleRate
Definition juce_Chorus.h:158
SampleType feedback
Definition juce_Chorus.h:159
void process(const ProcessContext &context) noexcept
Definition juce_Chorus.h:89
static constexpr SampleType oscVolumeMultiplier
Definition juce_Chorus.h:164
SampleType rate
Definition juce_Chorus.h:159
DryWetMixer< SampleType > dryWet
Definition juce_Chorus.h:154
SampleType centreDelay
Definition juce_Chorus.h:160
DelayLine< SampleType, DelayLineInterpolationTypes::Linear > delay
Definition juce_Chorus.h:151
void reset()
Definition juce_Chorus.cpp:111
std::vector< SampleType > lastOutput
Definition juce_Chorus.h:155
SampleType mix
Definition juce_Chorus.h:159
void setDepth(SampleType newDepth)
Definition juce_Chorus.cpp:51
static constexpr SampleType maxDepth
Definition juce_Chorus.h:162
static constexpr SampleType maximumDelayModulation
Definition juce_Chorus.h:165
void setFeedback(SampleType newFeedback)
Definition juce_Chorus.cpp:68
void setRate(SampleType newRateHz)
Definition juce_Chorus.cpp:42
SmoothedValue< SampleType, ValueSmoothingTypes::Linear > oscVolume
Definition juce_Chorus.h:152
Definition juce_DelayLine.h:95
Definition juce_DryWetMixer.h:54
Definition juce_Oscillator.h:38
register unsigned i
Definition inflate.c:1575
#define jassert(expression)
Definition juce_AudioBlock.h:29
Definition carla_juce.cpp:31
Definition juce_ProcessContext.h:88
Definition juce_ProcessContext.h:38