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.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::dsp
27{
28
29//==============================================================================
30template <typename SampleType>
32{
33 auto oscFunction = [] (SampleType x) { return std::sin (x); };
34 osc.initialise (oscFunction);
35
36 dryWet.setMixingRule (DryWetMixingRule::linear);
37}
38
39template <typename SampleType>
40void Chorus<SampleType>::setRate (SampleType newRateHz)
41{
42 jassert (isPositiveAndBelow (newRateHz, static_cast<SampleType> (100.0)));
43
44 rate = newRateHz;
45 update();
46}
47
48template <typename SampleType>
49void Chorus<SampleType>::setDepth (SampleType newDepth)
50{
51 jassert (isPositiveAndNotGreaterThan (newDepth, maxDepth));
52
53 depth = newDepth;
54 update();
55}
56
57template <typename SampleType>
58void Chorus<SampleType>::setCentreDelay (SampleType newDelayMs)
59{
60 jassert (isPositiveAndBelow (newDelayMs, maxCentreDelayMs));
61
62 centreDelay = jlimit (static_cast<SampleType> (1.0), maxCentreDelayMs, newDelayMs);
63}
64
65template <typename SampleType>
66void Chorus<SampleType>::setFeedback (SampleType newFeedback)
67{
68 jassert (newFeedback >= static_cast<SampleType> (-1.0) && newFeedback <= static_cast<SampleType> (1.0));
69
70 feedback = newFeedback;
71 update();
72}
73
74template <typename SampleType>
75void Chorus<SampleType>::setMix (SampleType newMix)
76{
77 jassert (isPositiveAndNotGreaterThan (newMix, static_cast<SampleType> (1.0)));
78
79 mix = newMix;
80 update();
81}
82
83//==============================================================================
84template <typename SampleType>
86{
87 jassert (spec.sampleRate > 0);
88 jassert (spec.numChannels > 0);
89
90 sampleRate = spec.sampleRate;
91
92 const auto maxPossibleDelay = std::ceil ((maximumDelayModulation * maxDepth * oscVolumeMultiplier + maxCentreDelayMs)
93 * sampleRate / 1000.0);
94 delay = DelayLine<SampleType, DelayLineInterpolationTypes::Linear>{ static_cast<int> (maxPossibleDelay) };
95 delay.prepare (spec);
96
97 dryWet.prepare (spec);
98 feedbackVolume.resize (spec.numChannels);
99 lastOutput.resize (spec.numChannels);
100
101 osc.prepare (spec);
102 bufferDelayTimes.setSize (1, (int) spec.maximumBlockSize, false, false, true);
103
104 update();
105 reset();
106}
107
108template <typename SampleType>
110{
111 std::fill (lastOutput.begin(), lastOutput.end(), static_cast<SampleType> (0));
112
113 delay.reset();
114 osc.reset();
115 dryWet.reset();
116
117 oscVolume.reset (sampleRate, 0.05);
118
119 for (auto& vol : feedbackVolume)
120 vol.reset (sampleRate, 0.05);
121}
122
123template <typename SampleType>
125{
126 osc.setFrequency (rate);
127 oscVolume.setTargetValue (depth * oscVolumeMultiplier);
128 dryWet.setWetMixProportion (mix);
129
130 for (auto& vol : feedbackVolume)
131 vol.setTargetValue (feedback);
132}
133
134//==============================================================================
135template class Chorus<float>;
136template class Chorus<double>;
137
138} // namespace juce::dsp
T ceil(T... args)
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.
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,...
void prepare(const ProcessSpec &spec)
Initialises the processor.
T fill(T... args)
#define jassert(expression)
Platform-independent assertion macro.
Type jlimit(Type lowerLimit, Type upperLimit, Type valueToConstrain) noexcept
Constrains a value to keep it within a given range.
bool isPositiveAndNotGreaterThan(Type1 valueToTest, Type2 upperLimit) noexcept
Returns true if a value is at least zero, and also less than or equal to a specified upper limit.
bool isPositiveAndBelow(Type1 valueToTest, Type2 upperLimit) noexcept
Returns true if a value is at least zero, and also below a specified upper limit.
T sin(T... args)
This structure is passed into a DSP algorithm's prepare() method, and contains information about vari...
uint32 numChannels
The number of channels that the process() method will be expected to handle.
double sampleRate
The sample rate that will be used for the data that is sent to the processor.
uint32 maximumBlockSize
The maximum number of samples that will be in the blocks sent to process() method.