Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for FIR filter and BypassProcessor #467

Merged
merged 1 commit into from
Nov 9, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ void BypassProcessor<SampleType, DelayInterpType, std::enable_if_t<! std::is_sam
}

template <typename SampleType, typename DelayInterpType>
bool BypassProcessor<SampleType, DelayInterpType, std::enable_if_t<! std::is_same_v<DelayInterpType, std::nullptr_t>>>::processBlockIn (const BufferView<const SampleType>& block, bool onOffParam)
bool BypassProcessor<SampleType, DelayInterpType, std::enable_if_t<! std::is_same_v<DelayInterpType, std::nullptr_t>>>::processBlockIn (const BufferView<SampleType>& block, bool onOffParam)
{
enum class DelayOp
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class BypassProcessor<SampleType, DelayInterpType, std::enable_if_t<! std::is_sa
* If it returns false, you can safely skip all other
* processing.
*/
bool processBlockIn (const BufferView<const SampleType>& buffer, bool onOffParam);
bool processBlockIn (const BufferView<SampleType>& buffer, bool onOffParam);

/**
* Call this at the end of your processBlock().
Expand Down
16 changes: 12 additions & 4 deletions modules/dsp/chowdsp_filters/Other/chowdsp_FIRFilter.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#if ! CHOWDSP_NO_XSIMD

#include "chowdsp_FIRFilter.h"

#if defined(__APPLE_CPP__) || defined(__APPLE_CC__)
Expand Down Expand Up @@ -29,8 +27,12 @@ void FIRFilter<FloatType>::setOrder (int newOrder)
{
order = newOrder;

#if ! CHOWDSP_NO_XSIMD
static constexpr int batchSize = xsimd::batch<FloatType>::size;
paddedOrder = batchSize * Math::ceiling_divide (order, batchSize);
#else
paddedOrder = order;
#endif
coefficients.resize (paddedOrder, {});
prepare ((int) state.size());
}
Expand Down Expand Up @@ -82,6 +84,7 @@ inline FloatType FIRFilter<FloatType>::processSampleInternal (FloatType x, Float
return y;
}

#if ! CHOWDSP_NO_XSIMD
template <typename FloatType>
inline FloatType FIRFilter<FloatType>::simdInnerProduct (const FloatType* z, const FloatType* h, int N)
{
Expand All @@ -103,6 +106,13 @@ inline FloatType FIRFilter<FloatType>::simdInnerProduct (const FloatType* z, con

return xsimd::reduce_add (batch_y);
}
#else
template <typename FloatType>
inline FloatType FIRFilter<FloatType>::simdInnerProduct (const FloatType* z, const FloatType* h, int N)
{
return std::inner_product (z, z + N, h, FloatType {});
}
#endif

template <typename FloatType>
inline void FIRFilter<FloatType>::processSampleInternalBypassed (FloatType x, FloatType* z, int& zPtr, int order) noexcept
Expand All @@ -118,5 +128,3 @@ template class FIRFilter<double>;
} // namespace chowdsp

JUCE_END_IGNORE_WARNINGS_GCC_LIKE

#endif // ! CHOWDSP_NO_XSIMD
8 changes: 4 additions & 4 deletions modules/dsp/chowdsp_filters/Other/chowdsp_FIRFilter.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#if ! CHOWDSP_NO_XSIMD

#pragma once

JUCE_BEGIN_IGNORE_WARNINGS_GCC_LIKE ("-Wsign-conversion")
Expand Down Expand Up @@ -108,13 +106,15 @@ class FIRFilter
int paddedOrder = 0;
std::vector<int> zPtr;

#if CHOWDSP_NO_XSIMD
std::vector<FloatType> coefficients;
#else
std::vector<FloatType, xsimd::default_allocator<FloatType>> coefficients;
#endif
std::vector<std::vector<FloatType>> state;

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (FIRFilter)
};
} // namespace chowdsp

JUCE_END_IGNORE_WARNINGS_GCC_LIKE

#endif // ! CHOWDSP_NO_XSIMD
Loading