diff --git a/modules/dsp/chowdsp_eq/EQ/chowdsp_EQProcessor.cpp b/modules/dsp/chowdsp_eq/EQ/chowdsp_EQProcessor.cpp index e04f3287c..b0875d98b 100644 --- a/modules/dsp/chowdsp_eq/EQ/chowdsp_EQProcessor.cpp +++ b/modules/dsp/chowdsp_eq/EQ/chowdsp_EQProcessor.cpp @@ -46,7 +46,7 @@ void EQProcessor::setBandOnOff (int band, bool } template -void EQProcessor::prepare (const juce::dsp::ProcessSpec& spec) +void EQProcessor::prepare (const juce::dsp::ProcessSpec& spec, bool useInternalArena) { for (size_t i = 0; i < numBands; ++i) { @@ -55,10 +55,11 @@ void EQProcessor::prepare (const juce::dsp::Pro } const auto paddedChannelSize = Math::round_to_next_multiple (static_cast (spec.maximumBlockSize), SIMDUtils::defaultSIMDAlignment); - const auto requiredMemoryBytes = paddedChannelSize * sizeof (FloatType) * 3 // per-band smoothed values - + paddedChannelSize * spec.numChannels * sizeof (FloatType) * 2 // per-band fade and bypass buffers - + 32; // extra padding - arena.reset (requiredMemoryBytes); + requiredMemoryBytes = paddedChannelSize * sizeof (FloatType) * 3 // per-band smoothed values + + paddedChannelSize * spec.numChannels * sizeof (FloatType) * 2; // per-band fade and bypass buffers + + if (useInternalArena) + internalArena.reset (requiredMemoryBytes + 32); } template @@ -70,6 +71,12 @@ void EQProcessor::reset() template void EQProcessor::processBlock (const BufferView& block) noexcept +{ + processBlock (block, internalArena); +} + +template +void EQProcessor::processBlock (const BufferView& block, ArenaAllocatorView arena) noexcept { for (size_t i = 0; i < numBands; ++i) { diff --git a/modules/dsp/chowdsp_eq/EQ/chowdsp_EQProcessor.h b/modules/dsp/chowdsp_eq/EQ/chowdsp_EQProcessor.h index a2605a3ee..3afa46558 100644 --- a/modules/dsp/chowdsp_eq/EQ/chowdsp_EQProcessor.h +++ b/modules/dsp/chowdsp_eq/EQ/chowdsp_EQProcessor.h @@ -51,20 +51,32 @@ class EQProcessor void setBandOnOff (int band, bool shouldBeOn); /** Prepares the EQ to process a new stream of audio */ - void prepare (const juce::dsp::ProcessSpec& spec); + void prepare (const juce::dsp::ProcessSpec& spec, bool useInternalArena = true); /** Resets the EQ state */ void reset(); + /** + * Returns the maximum amount of memory needed by the EQ processor in bytes + * If using the EQ with it's internal arena, then this memory will already be + * allocated, otherwise it is the user's responsibility to allocate this amount + * of memory ahead of time. + */ + [[nodiscard]] size_t getRequiredMemoryBytes() const noexcept { return requiredMemoryBytes; } + /** Processes an audio block */ void processBlock (const BufferView& block) noexcept; + /** Processes an audio block */ + void processBlock (const BufferView& block, ArenaAllocatorView arena) noexcept; + private: std::array bands; std::array, numBands> bypasses; std::array onOffs = { false }; - ArenaAllocator<> arena; + size_t requiredMemoryBytes = 0; + ArenaAllocator<> internalArena; JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (EQProcessor) };