Skip to content

Commit

Permalink
BypassProcessor: constructor parameter to choose max delay size (#526)
Browse files Browse the repository at this point in the history
* BypassProcessor: constructor parameter to choose max delay size

* Apply clang-format

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
jatinchowdhury18 and github-actions[bot] authored Apr 20, 2024
1 parent 8847c1d commit 8253a93
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@ void BypassProcessor<SampleType,
}

//===========================================================
template <typename SampleType, typename DelayInterpType>
BypassProcessor<SampleType,
DelayInterpType,
std::enable_if_t<! std::is_same_v<DelayInterpType, NullType>>>::BypassProcessor (int maxLatencySamples)
: maximumLatencySamples (maxLatencySamples)
{
}

template <typename SampleType, typename DelayInterpType>
void BypassProcessor<SampleType,
DelayInterpType,
Expand All @@ -102,7 +110,8 @@ void BypassProcessor<SampleType,
if (useInternalBuffer)
fadeBuffer.setMaxSize ((int) spec.numChannels, (int) spec.maximumBlockSize);

compDelay.prepare (spec); // sample rate does not matter
compDelay.emplace (maximumLatencySamples + static_cast<int> (spec.maximumBlockSize));
compDelay->prepare (spec); // sample rate does not matter
}

template <typename SampleType, typename DelayInterpType>
Expand Down Expand Up @@ -130,10 +139,10 @@ void BypassProcessor<SampleType,
if (juce::approximatelyEqual (delaySamples, prevDelay))
return;

compDelay.setDelay ((NumericType) delaySamples);
compDelay->setDelay ((NumericType) delaySamples);

if (juce::approximatelyEqual (delaySamples, (NumericType) 0))
compDelay.reset();
compDelay->reset();

prevDelay = delaySamples;
}
Expand Down Expand Up @@ -179,11 +188,11 @@ bool BypassProcessor<SampleType,
}
};

doDelayOp (block, compDelay, DelayOp::Push);
doDelayOp (block, *compDelay, DelayOp::Push);

if (! onOffParam && ! prevOnOffParam)
{
doDelayOp (block, compDelay, DelayOp::Pop);
doDelayOp (block, *compDelay, DelayOp::Pop);
return false;
}

Expand All @@ -195,14 +204,14 @@ bool BypassProcessor<SampleType,
fadeBufferView = BufferView { fadeBuffer, 0, block.getNumSamples(), 0, block.getNumChannels() };

BufferMath::copyBufferData (block, fadeBufferView);
doDelayOp (fadeBufferView, compDelay, DelayOp::Pop);
doDelayOp (fadeBufferView, *compDelay, DelayOp::Pop);

if (onOffParam && latencySampleCount < 0)
latencySampleCount = (int) compDelay.getDelay();
latencySampleCount = (int) compDelay->getDelay();
}
else
{
doDelayOp (block, compDelay, DelayOp::Toss);
doDelayOp (block, *compDelay, DelayOp::Toss);
}

return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class BypassProcessor<SampleType, DelayInterpType, std::enable_if_t<! std::is_sa
public:
using NumericType = SampleTypeHelpers::NumericType<SampleType>;

BypassProcessor() = default;
explicit BypassProcessor (int maxLatencySamples = 1 << 18);

/** Converts a parameter handle to a boolean */
static bool toBool (const std::atomic<float>* param)
Expand Down Expand Up @@ -119,7 +119,8 @@ class BypassProcessor<SampleType, DelayInterpType, std::enable_if_t<! std::is_sa
Buffer<SampleType> fadeBuffer;
BufferView<SampleType> fadeBufferView;

DelayLine<SampleType, DelayInterpType> compDelay { 1 << 18 }; // max latency = 2^18 = 262144 samples
int maximumLatencySamples = 0;
std::optional<DelayLine<SampleType, DelayInterpType>> compDelay { std::nullopt };
NumericType prevDelay {};
int latencySampleCount = -1;

Expand Down
4 changes: 2 additions & 2 deletions tests/dsp_tests/chowdsp_dsp_utils_test/BypassTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ TEST_CASE ("Bypass Test", "[dsp][misc]")
auto arenaView = chowdsp::ArenaAllocatorView { arena };
for (auto& arenaPtr : std::vector<chowdsp::ArenaAllocatorView*> { nullptr, &arenaView })
{
chowdsp::BypassProcessor<float> bypass;
chowdsp::BypassProcessor<float> bypass {};
std::atomic<float> onOffParam { 0.0f };
bypass.prepare ({ fs,
(juce::uint32) nSamples,
Expand Down Expand Up @@ -123,7 +123,7 @@ TEST_CASE ("Bypass Test", "[dsp][misc]")
auto arenaView = chowdsp::ArenaAllocatorView { arena };
for (auto& arenaPtr : std::vector<chowdsp::ArenaAllocatorView*> { nullptr, &arenaView })
{
chowdsp::BypassProcessor<float, chowdsp::DelayLineInterpolationTypes::Linear> bypass;
chowdsp::BypassProcessor<float, chowdsp::DelayLineInterpolationTypes::Linear> bypass { static_cast<int> (std::ceil (delaySamp)) };
std::atomic<float> onOffParam { 0.0f };
bypass.prepare ({ fs,
(juce::uint32) nSamples,
Expand Down

0 comments on commit 8253a93

Please sign in to comment.