Skip to content

Commit

Permalink
EQ: allow user to supply their own arena
Browse files Browse the repository at this point in the history
  • Loading branch information
jatinchowdhury18 committed Apr 23, 2024
1 parent 9a2333b commit d25c079
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
17 changes: 12 additions & 5 deletions modules/dsp/chowdsp_eq/EQ/chowdsp_EQProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void EQProcessor<FloatType, numBands, EQBandType>::setBandOnOff (int band, bool
}

template <typename FloatType, size_t numBands, typename EQBandType>
void EQProcessor<FloatType, numBands, EQBandType>::prepare (const juce::dsp::ProcessSpec& spec)
void EQProcessor<FloatType, numBands, EQBandType>::prepare (const juce::dsp::ProcessSpec& spec, bool useInternalArena)
{
for (size_t i = 0; i < numBands; ++i)
{
Expand All @@ -55,10 +55,11 @@ void EQProcessor<FloatType, numBands, EQBandType>::prepare (const juce::dsp::Pro
}

const auto paddedChannelSize = Math::round_to_next_multiple (static_cast<size_t> (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 <typename FloatType, size_t numBands, typename EQBandType>
Expand All @@ -70,6 +71,12 @@ void EQProcessor<FloatType, numBands, EQBandType>::reset()

template <typename FloatType, size_t numBands, typename EQBandType>
void EQProcessor<FloatType, numBands, EQBandType>::processBlock (const BufferView<FloatType>& block) noexcept
{
processBlock (block, internalArena);
}

template <typename FloatType, size_t numBands, typename EQBandType>
void EQProcessor<FloatType, numBands, EQBandType>::processBlock (const BufferView<FloatType>& block, ArenaAllocatorView arena) noexcept
{
for (size_t i = 0; i < numBands; ++i)
{
Expand Down
16 changes: 14 additions & 2 deletions modules/dsp/chowdsp_eq/EQ/chowdsp_EQProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<FloatType>& block) noexcept;

/** Processes an audio block */
void processBlock (const BufferView<FloatType>& block, ArenaAllocatorView arena) noexcept;

private:
std::array<EQBandType, numBands> bands;
std::array<BypassProcessor<FloatType>, numBands> bypasses;
std::array<bool, numBands> onOffs = { false };

ArenaAllocator<> arena;
size_t requiredMemoryBytes = 0;
ArenaAllocator<> internalArena;

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (EQProcessor)
};
Expand Down

0 comments on commit d25c079

Please sign in to comment.