LMMS
Loading...
Searching...
No Matches
juce_Chorus.cpp
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
31//==============================================================================
32template <typename SampleType>
34{
35 auto oscFunction = [] (SampleType x) { return std::sin (x); };
36 osc.initialise (oscFunction);
37
38 dryWet.setMixingRule (DryWetMixingRule::linear);
39}
40
41template <typename SampleType>
42void Chorus<SampleType>::setRate (SampleType newRateHz)
43{
44 jassert (isPositiveAndBelow (newRateHz, static_cast<SampleType> (100.0)));
45
46 rate = newRateHz;
47 update();
48}
49
50template <typename SampleType>
51void Chorus<SampleType>::setDepth (SampleType newDepth)
52{
54
55 depth = newDepth;
56 update();
57}
58
59template <typename SampleType>
60void Chorus<SampleType>::setCentreDelay (SampleType newDelayMs)
61{
63
64 centreDelay = jlimit (static_cast<SampleType> (1.0), maxCentreDelayMs, newDelayMs);
65}
66
67template <typename SampleType>
68void Chorus<SampleType>::setFeedback (SampleType newFeedback)
69{
70 jassert (newFeedback >= static_cast<SampleType> (-1.0) && newFeedback <= static_cast<SampleType> (1.0));
71
72 feedback = newFeedback;
73 update();
74}
75
76template <typename SampleType>
77void Chorus<SampleType>::setMix (SampleType newMix)
78{
79 jassert (isPositiveAndNotGreaterThan (newMix, static_cast<SampleType> (1.0)));
80
81 mix = newMix;
82 update();
83}
84
85//==============================================================================
86template <typename SampleType>
88{
89 jassert (spec.sampleRate > 0);
90 jassert (spec.numChannels > 0);
91
93
94 const auto maxPossibleDelay = std::ceil ((maximumDelayModulation * maxDepth * oscVolumeMultiplier + maxCentreDelayMs)
95 * sampleRate / 1000.0);
96 delay = DelayLine<SampleType, DelayLineInterpolationTypes::Linear>{ static_cast<int> (maxPossibleDelay) };
97 delay.prepare (spec);
98
99 dryWet.prepare (spec);
100 feedbackVolume.resize (spec.numChannels);
101 lastOutput.resize (spec.numChannels);
102
103 osc.prepare (spec);
104 bufferDelayTimes.setSize (1, (int) spec.maximumBlockSize, false, false, true);
105
106 update();
107 reset();
108}
109
110template <typename SampleType>
112{
113 std::fill (lastOutput.begin(), lastOutput.end(), static_cast<SampleType> (0));
114
115 delay.reset();
116 osc.reset();
117 dryWet.reset();
118
119 oscVolume.reset (sampleRate, 0.05);
120
121 for (auto& vol : feedbackVolume)
122 vol.reset (sampleRate, 0.05);
123}
124
125template <typename SampleType>
127{
128 osc.setFrequency (rate);
129 oscVolume.setTargetValue (depth * oscVolumeMultiplier);
130 dryWet.setWetMixProportion (mix);
131
132 for (auto& vol : feedbackVolume)
133 vol.setTargetValue (feedback);
134}
135
136//==============================================================================
137template class Chorus<float>;
138template class Chorus<double>;
139
140} // namespace dsp
141} // namespace juce
Chorus(bool insertion_, float *efxoutl_, float *efxoutr_, unsigned int srate, int bufsize)
Definition Chorus.cpp:29
Definition juce_Chorus.h:48
std::vector< SmoothedValue< SampleType, ValueSmoothingTypes::Linear > > feedbackVolume
Definition juce_Chorus.h:153
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
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
void update()
Definition juce_Chorus.cpp:126
SmoothedValue< SampleType, ValueSmoothingTypes::Linear > oscVolume
Definition juce_Chorus.h:152
Definition juce_DelayLine.h:95
unsigned x[BMAX+1]
Definition inflate.c:1586
#define jassert(expression)
Definition juce_AudioBlock.h:29
@ linear
Definition juce_DryWetMixer.h:33
Definition carla_juce.cpp:31
Type jlimit(Type lowerLimit, Type upperLimit, Type valueToConstrain) noexcept
Definition juce_MathsFunctions.h:262
bool isPositiveAndNotGreaterThan(Type1 valueToTest, Type2 upperLimit) noexcept
Definition juce_MathsFunctions.h:298
bool isPositiveAndBelow(Type1 valueToTest, Type2 upperLimit) noexcept
Definition juce_MathsFunctions.h:279
Definition juce_ProcessContext.h:38
uint32 numChannels
Definition juce_ProcessContext.h:46
double sampleRate
Definition juce_ProcessContext.h:40
uint32 maximumBlockSize
Definition juce_ProcessContext.h:43