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_Phaser.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 for (auto n = 0; n < numStages; ++n)
37 {
38 filters.add (new FirstOrderTPTFilter<SampleType>());
39 filters[n]->setType (FirstOrderTPTFilterType::allpass);
40 }
41
42 dryWet.setMixingRule (DryWetMixingRule::linear);
43}
44
45template <typename SampleType>
46void Phaser<SampleType>::setRate (SampleType newRateHz)
47{
48 jassert (isPositiveAndBelow (newRateHz, static_cast<SampleType> (100.0)));
49
50 rate = newRateHz;
51 update();
52}
53
54template <typename SampleType>
55void Phaser<SampleType>::setDepth (SampleType newDepth)
56{
57 jassert (isPositiveAndNotGreaterThan (newDepth, static_cast<SampleType> (1.0)));
58
59 depth = newDepth;
60 update();
61}
62
63template <typename SampleType>
64void Phaser<SampleType>::setCentreFrequency (SampleType newCentreHz)
65{
66 jassert (isPositiveAndBelow (newCentreHz, static_cast<SampleType> (sampleRate * 0.5)));
67
68 centreFrequency = newCentreHz;
69 normCentreFrequency = mapFromLog10 (centreFrequency, static_cast<SampleType> (20.0), static_cast<SampleType> (jmin (20000.0, 0.49 * sampleRate)));
70}
71
72template <typename SampleType>
73void Phaser<SampleType>::setFeedback (SampleType newFeedback)
74{
75 jassert (newFeedback >= static_cast<SampleType> (-1.0) && newFeedback <= static_cast<SampleType> (1.0));
76
77 feedback = newFeedback;
78 update();
79}
80
81template <typename SampleType>
82void Phaser<SampleType>::setMix (SampleType newMix)
83{
84 jassert (isPositiveAndNotGreaterThan (newMix, static_cast<SampleType> (1.0)));
85
86 mix = newMix;
87 update();
88}
89
90//==============================================================================
91template <typename SampleType>
93{
94 jassert (spec.sampleRate > 0);
95 jassert (spec.numChannels > 0);
96
97 sampleRate = spec.sampleRate;
98
99 for (auto n = 0; n < numStages; ++n)
100 filters[n]->prepare (spec);
101
102 dryWet.prepare (spec);
103 feedbackVolume.resize (spec.numChannels);
104 lastOutput.resize (spec.numChannels);
105
106 auto specDown = spec;
107 specDown.sampleRate /= (double) maxUpdateCounter;
108 specDown.maximumBlockSize = specDown.maximumBlockSize / (uint32) maxUpdateCounter + 1;
109
110 osc.prepare (specDown);
111 bufferFrequency.setSize (1, (int) specDown.maximumBlockSize, false, false, true);
112
113 update();
114 reset();
115}
116
117template <typename SampleType>
119{
120 std::fill (lastOutput.begin(), lastOutput.end(), static_cast<SampleType> (0));
121
122 for (auto n = 0; n < numStages; ++n)
123 filters[n]->reset();
124
125 osc.reset();
126 dryWet.reset();
127
128 oscVolume.reset (sampleRate / (double) maxUpdateCounter, 0.05);
129
130 for (auto& vol : feedbackVolume)
131 vol.reset (sampleRate, 0.05);
132
133 updateCounter = 0;
134}
135
136template <typename SampleType>
138{
139 osc.setFrequency (rate);
140 oscVolume.setTargetValue (depth * (SampleType) 0.5);
141 dryWet.setWetMixProportion (mix);
142
143 for (auto& vol : feedbackVolume)
144 vol.setTargetValue (feedback);
145}
146
147//==============================================================================
148template class Phaser<float>;
149template class Phaser<double>;
150
151} // namespace juce::dsp
A first order filter class using the TPT (Topology-Preserving Transform) structure.
A 6 stage phaser that modulates first order all-pass filters to create sweeping notches in the magnit...
Definition juce_Phaser.h:41
void prepare(const ProcessSpec &spec)
Initialises the processor.
Phaser()
Constructor.
void reset()
Resets the internal state variables of the processor.
void setDepth(SampleType newDepth)
Sets the volume (between 0 and 1) of the LFO modulating the phaser all-pass filters.
void setFeedback(SampleType newFeedback)
Sets the feedback volume (between -1 and 1) of the phaser.
void setMix(SampleType newMix)
Sets the amount of dry and wet signal in the output of the phaser (between 0 for full dry and 1 for f...
void setRate(SampleType newRateHz)
Sets the rate (in Hz) of the LFO modulating the phaser all-pass filters.
void setCentreFrequency(SampleType newCentreHz)
Sets the centre frequency (in Hz) of the phaser all-pass filters modulation.
T fill(T... args)
#define jassert(expression)
Platform-independent assertion macro.
typedef double
constexpr Type jmin(Type a, Type b)
Returns the smaller of two values.
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.
unsigned int uint32
A platform-independent 32-bit unsigned integer type.
Type mapFromLog10(Type valueInLogRange, Type logRangeMin, Type logRangeMax)
Remaps a logarithmic value in a target range to a normalised value (between 0 and 1).
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.