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_DelayLine.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, typename InterpolationType>
35
36template <typename SampleType, typename InterpolationType>
38{
40
41 sampleRate = 44100.0;
42
43 setMaximumDelayInSamples (maximumDelayInSamples);
44}
45
46//==============================================================================
47template <typename SampleType, typename InterpolationType>
49{
50 auto upperLimit = (SampleType) getMaximumDelayInSamples();
52
53 delay = jlimit ((SampleType) 0, upperLimit, newDelayInSamples);
54 delayInt = static_cast<int> (std::floor (delay));
55 delayFrac = delay - (SampleType) delayInt;
56
57 updateInternalVariables();
58}
59
60template <typename SampleType, typename InterpolationType>
62{
63 return delay;
64}
65
66//==============================================================================
67template <typename SampleType, typename InterpolationType>
69{
70 jassert (spec.numChannels > 0);
71
72 bufferData.setSize ((int) spec.numChannels, totalSize, false, false, true);
73
74 writePos.resize (spec.numChannels);
75 readPos.resize (spec.numChannels);
76
77 v.resize (spec.numChannels);
78 sampleRate = spec.sampleRate;
79
80 reset();
81}
82
83template <typename SampleType, typename InterpolationType>
85{
87 totalSize = jmax (4, maxDelayInSamples + 2);
88 bufferData.setSize ((int) bufferData.getNumChannels(), totalSize, false, false, true);
89 reset();
90}
91
92template <typename SampleType, typename InterpolationType>
94{
95 for (auto vec : { &writePos, &readPos })
96 std::fill (vec->begin(), vec->end(), 0);
98 std::fill (v.begin(), v.end(), static_cast<SampleType> (0));
99
100 bufferData.clear();
101}
102
103//==============================================================================
104template <typename SampleType, typename InterpolationType>
105void DelayLine<SampleType, InterpolationType>::pushSample (int channel, SampleType sample)
106{
107 bufferData.setSample (channel, writePos[(size_t) channel], sample);
108 writePos[(size_t) channel] = (writePos[(size_t) channel] + totalSize - 1) % totalSize;
109}
110
111template <typename SampleType, typename InterpolationType>
113{
114 if (delayInSamples >= 0)
115 setDelay (delayInSamples);
116
117 auto result = interpolateSample (channel);
118
120 readPos[(size_t) channel] = (readPos[(size_t) channel] + totalSize - 1) % totalSize;
121
122 return result;
123}
124
125//==============================================================================
A delay line processor featuring several algorithms for the fractional delay calculation,...
void prepare(const ProcessSpec &spec)
Initialises the processor.
void setDelay(SampleType newDelayInSamples)
Sets the delay in samples.
SampleType popSample(int channel, SampleType delayInSamples=-1, bool updateReadPointer=true)
Pops a single sample from one channel of the delay line.
DelayLine()
Default constructor.
void setMaximumDelayInSamples(int maxDelayInSamples)
Sets a new maximum delay in samples.
SampleType getDelay() const
Returns the current delay in samples.
void reset()
Resets the internal state variables of the processor.
void pushSample(int channel, SampleType sample)
Pushes a single sample into one channel of the delay line.
T fill(T... args)
T floor(T... args)
#define jassert(expression)
Platform-independent assertion macro.
constexpr Type jmax(Type a, Type b)
Returns the larger of two values.
Type jlimit(Type lowerLimit, Type upperLimit, Type valueToConstrain) noexcept
Constrains a value to keep it within a given range.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
Definition juce_Memory.h:88
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.
This structure is passed into a DSP algorithm's prepare() method, and contains information about vari...
typedef size_t