LMMS
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
27{
28namespace dsp
29{
30
31//==============================================================================
32template <typename SampleType, typename InterpolationType>
37
38template <typename SampleType, typename InterpolationType>
40{
41 jassert (maximumDelayInSamples >= 0);
42
43 sampleRate = 44100.0;
44
45 setMaximumDelayInSamples (maximumDelayInSamples);
46}
47
48//==============================================================================
49template <typename SampleType, typename InterpolationType>
50void DelayLine<SampleType, InterpolationType>::setDelay (SampleType newDelayInSamples)
51{
52 auto upperLimit = (SampleType) getMaximumDelayInSamples();
53 jassert (isPositiveAndNotGreaterThan (newDelayInSamples, upperLimit));
54
55 delay = jlimit ((SampleType) 0, upperLimit, newDelayInSamples);
56 delayInt = static_cast<int> (std::floor (delay));
57 delayFrac = delay - (SampleType) delayInt;
58
60}
61
62template <typename SampleType, typename InterpolationType>
64{
65 return delay;
66}
67
68//==============================================================================
69template <typename SampleType, typename InterpolationType>
71{
72 jassert (spec.numChannels > 0);
73
74 bufferData.setSize ((int) spec.numChannels, totalSize, false, false, true);
75
76 writePos.resize (spec.numChannels);
77 readPos.resize (spec.numChannels);
78
79 v.resize (spec.numChannels);
81
82 reset();
83}
84
85template <typename SampleType, typename InterpolationType>
87{
88 jassert (maxDelayInSamples >= 0);
89 totalSize = jmax (4, maxDelayInSamples + 1);
90 bufferData.setSize ((int) bufferData.getNumChannels(), totalSize, false, false, true);
91 reset();
92}
93
94template <typename SampleType, typename InterpolationType>
96{
97 for (auto vec : { &writePos, &readPos })
98 std::fill (vec->begin(), vec->end(), 0);
100 std::fill (v.begin(), v.end(), static_cast<SampleType> (0));
101
102 bufferData.clear();
103}
104
105//==============================================================================
106template <typename SampleType, typename InterpolationType>
108{
109 bufferData.setSample (channel, writePos[(size_t) channel], sample);
110 writePos[(size_t) channel] = (writePos[(size_t) channel] + totalSize - 1) % totalSize;
111}
112
113template <typename SampleType, typename InterpolationType>
114SampleType DelayLine<SampleType, InterpolationType>::popSample (int channel, SampleType delayInSamples, bool updateReadPointer)
115{
116 if (delayInSamples >= 0)
117 setDelay(delayInSamples);
118
119 auto result = interpolateSample (channel);
120
121 if (updateReadPointer)
122 readPos[(size_t) channel] = (readPos[(size_t) channel] + totalSize - 1) % totalSize;
123
124 return result;
125}
126
127//==============================================================================
Type jmax(const Type a, const Type b)
Definition MathsFunctions.h:48
DelayLine(const unsigned long lSampleRate, const LADSPA_Data fMaximumDelay)
Definition delay.cpp:89
Definition juce_DelayLine.h:95
std::enable_if< std::is_same< T, DelayLineInterpolationTypes::None >::value, void >::type updateInternalVariables()
Definition juce_DelayLine.h:292
int getMaximumDelayInSamples() const noexcept
Definition juce_DelayLine.h:128
void pushSample(int channel, SampleType sample)
Definition juce_DelayLine.cpp:107
std::vector< SampleType > v
Definition juce_DelayLine.h:331
AudioBuffer< SampleType > bufferData
Definition juce_DelayLine.h:330
DelayLine()
Definition juce_DelayLine.cpp:33
SampleType delayFrac
Definition juce_DelayLine.h:333
void setDelay(SampleType newDelayInSamples)
Definition juce_DelayLine.cpp:50
std::vector< int > readPos
Definition juce_DelayLine.h:332
void reset()
Definition juce_DelayLine.cpp:95
std::vector< int > writePos
Definition juce_DelayLine.h:332
double sampleRate
Definition juce_DelayLine.h:327
void setMaximumDelayInSamples(int maxDelayInSamples)
Definition juce_DelayLine.cpp:86
std::enable_if< std::is_same< T, DelayLineInterpolationTypes::None >::value, SampleType >::type interpolateSample(int channel) const
Definition juce_DelayLine.h:206
int delayInt
Definition juce_DelayLine.h:334
int totalSize
Definition juce_DelayLine.h:334
SampleType getDelay() const
Definition juce_DelayLine.cpp:63
void prepare(const ProcessSpec &spec)
Definition juce_DelayLine.cpp:70
SampleType delay
Definition juce_DelayLine.h:333
SampleType popSample(int channel, SampleType delayInSamples=-1, bool updateReadPointer=true)
Definition juce_DelayLine.cpp:114
#define jassert(expression)
Definition juce_AudioBlock.h:29
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
Definition juce_ProcessContext.h:38
uint32 numChannels
Definition juce_ProcessContext.h:46
double sampleRate
Definition juce_ProcessContext.h:40
signed int sample
Definition tap_dynamics_m.c:41
int result
Definition process.c:1455