OpenShot Audio Library | OpenShotAudio 0.4.0
Loading...
Searching...
No Matches
juce_Chorus.cpp
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>
41{
42 jassert (isPositiveAndBelow (newRateHz, static_cast<SampleType> (100.0)));
43
44 rate = newRateHz;
45 update();
46}
47
48template <typename SampleType>
50{
51 jassert (isPositiveAndNotGreaterThan (newDepth, maxDepth));
52
53 depth = newDepth;
54 update();
55}
56
57template <typename SampleType>
59{
60 jassert (isPositiveAndBelow (newDelayMs, maxCentreDelayMs));
61
62 centreDelay = jlimit (static_cast<SampleType> (1.0), maxCentreDelayMs, newDelayMs);
63}
64
65template <typename SampleType>
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>
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);
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
void setFeedback(SampleType newFeedback)
void setDepth(SampleType newDepth)
void prepare(const ProcessSpec &spec)
void setMix(SampleType newMix)
void setRate(SampleType newRateHz)
void setCentreDelay(SampleType newDelayMs)