Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions shared/DSPFilters/include/DspFilters/Biquad.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,15 @@ class BiquadBase
}
}

template <class StateType, typename Sample>
void processInterleaved (int numSamples, Sample* dest, int stride, StateType& state) const
{
while (--numSamples >= 0) {
*dest = state.process (*dest, *this);
dest += stride;
}
}

protected:
//
// These are protected so you can't mess with RBJ biquads
Expand Down
9 changes: 9 additions & 0 deletions shared/DSPFilters/include/DspFilters/Cascade.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,15 @@ class Cascade
dest++;
}
}

template <class StateType, typename Sample>
void processInterleaved (int numSamples, Sample* dest, int stride, StateType& state) const
{
while (--numSamples >= 0) {
*dest = state.process (*dest, *this);
dest += stride;
}
}

protected:
Cascade ();
Expand Down
20 changes: 20 additions & 0 deletions shared/DSPFilters/include/DspFilters/Filter.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ class Filter
virtual void reset () = 0;
virtual void process (int numSamples, float* const* arrayOfChannels) = 0;
virtual void process (int numSamples, double* const* arrayOfChannels) = 0;
virtual void processInterleaved (int numSamples, float* arrayOfFrames) = 0;
virtual void processInterleaved (int numSamples, double* arrayOfFrames) = 0;

protected:
virtual void doSetParams (const Params& parameters) = 0;
Expand Down Expand Up @@ -222,6 +224,18 @@ class FilterDesign : public FilterDesignBase <DesignClass>
m_state.process (numSamples, arrayOfChannels,
FilterDesignBase<DesignClass>::m_design);
}

void processInterleaved (int numSamples, float* arrayOfFrames) override
{
m_state.processInterleaved (numSamples, arrayOfFrames,
FilterDesignBase<DesignClass>::m_design);
}

void processInterleaved (int numSamples, double* arrayOfFrames) override
{
m_state.processInterleaved (numSamples, arrayOfFrames,
FilterDesignBase<DesignClass>::m_design);
}

protected:
ChannelsState <Channels,
Expand Down Expand Up @@ -259,6 +273,12 @@ class SimpleFilter : public FilterClass
m_state.process (numSamples, arrayOfChannels, *((FilterClass*)this));
}

template <typename Sample>
void processInterleaved (int numSamples, Sample* arrayOfFrames)
{
m_state.processInterleaved (numSamples, arrayOfFrames, *((FilterClass*)this));
}

protected:
ChannelsState <Channels,
typename FilterClass::template State <StateType> > m_state;
Expand Down
63 changes: 63 additions & 0 deletions shared/DSPFilters/include/DspFilters/SmoothedFilter.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,59 @@ class SmoothedFilterDesign
}
}

template <typename Sample>
void processBlockInterleaved (int numSamples,
Sample* destFramesArray)
{
const int numChannels = this->getNumChannels();

// If this goes off it means setup() was never called
assert (m_remainingSamples >= 0);

// first handle any transition samples
int remainingSamples = std::min (m_remainingSamples, numSamples);

if (remainingSamples > 0)
{
// interpolate parameters for each sample
const double t = 1. / m_remainingSamples;
double dp[maxParameters];
for (int i = 0; i < DesignClass::NumParams; ++i)
dp[i] = (this->getParams()[i] - m_transitionParams[i]) * t;

for (int n = 0; n < remainingSamples; ++n)
{
for (int i = DesignClass::NumParams; --i >=0;)
m_transitionParams[i] += dp[i];

m_transitionFilter.setParams (m_transitionParams);

for (int i = numChannels; --i >= 0;)
{
Sample* dest = destFramesArray + i + n * numChannels;
*dest = this->m_state[i].process (*dest, m_transitionFilter);
}
}

m_remainingSamples -= remainingSamples;

if (m_remainingSamples == 0)
m_transitionParams = this->getParams();
}

// do what's left
if (numSamples - remainingSamples > 0)
{
// no transition
for (int i = 0; i < numChannels; ++i)
this->m_design.processInterleaved (numSamples - remainingSamples,
destFramesArray + i + remainingSamples * numChannels,
numChannels,
this->m_state[i]);
}

}

void process (int numSamples, float* const* arrayOfChannels)
{
processBlock (numSamples, arrayOfChannels);
Expand All @@ -124,6 +177,16 @@ class SmoothedFilterDesign
processBlock (numSamples, arrayOfChannels);
}

void processInterleaved (int numSamples, float* arrayOfFrames) override
{
processBlockInterleaved (numSamples, arrayOfFrames);
}

void processInterleaved (int numSamples, double* arrayOfFrames) override
{
processBlockInterleaved (numSamples, arrayOfFrames);
}

protected:
void doSetParams (const Params& parameters)
{
Expand Down
17 changes: 17 additions & 0 deletions shared/DSPFilters/include/DspFilters/State.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,15 @@ class ChannelsState
for (int i = 0; i < Channels; ++i)
filter.process (numSamples, arrayOfChannels[i], m_state[i]);
}

template <class Filter, typename Sample>
void processInterleaved (int numSamples,
Sample* arrayOfFrames,
Filter& filter)
{
for (int i = 0; i < Channels; ++i)
filter.processInterleaved (numSamples, arrayOfFrames + i, Channels, m_state[i]);
}

private:
StateType m_state[Channels];
Expand Down Expand Up @@ -314,6 +323,14 @@ class ChannelsState <0, StateType>
{
throw std::logic_error ("attempt to process empty ChannelState");
}

template <class FilterDesign, typename Sample>
void processInterleaved (int numSamples,
Sample* arrayOfFrames,
FilterDesign& filter)
{
throw std::logic_error ("attempt to process empty ChannelState");
}
};

//------------------------------------------------------------------------------
Expand Down