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

Tweaks so that we can use chowdsp_reverb without SIMD #485

Merged
merged 3 commits into from
Jan 24, 2024
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
43 changes: 35 additions & 8 deletions modules/dsp/chowdsp_math/Math/chowdsp_MatrixOps.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#if ! CHOWDSP_NO_XSIMD

#pragma once

#include <type_traits>
Expand All @@ -21,6 +19,7 @@ namespace MatrixOps
static constexpr NumericType multiplier = (NumericType) -2 / (NumericType) (size * SampleTypeHelpers::TypeTraits<FloatType>::Size);

public:
#if ! CHOWDSP_NO_XSIMD
/** Perform out-of-place Householder transform (scalar types) */
template <typename T = FloatType>
static inline std::enable_if_t<std::is_floating_point_v<T>, void>
Expand All @@ -46,8 +45,7 @@ namespace MatrixOps
scalarAccumulator += in[i];
}

static constexpr auto normMultiplier = (T) -2 / (T) size;
scalarAccumulator *= normMultiplier;
scalarAccumulator *= multiplier;

int j = 0;
for (; j < vec_loop_size; j += vec_size)
Expand Down Expand Up @@ -75,8 +73,28 @@ namespace MatrixOps
const auto sum = multiplier * xsimd::reduce_add (vecSum);

for (int i = 0; i < size; ++i)
out[i] += sum;
out[i] = in[i] + sum;
}
#else
/** Perform out-of-place Householder transform (scalar types) */
template <typename T = FloatType>
static inline std::enable_if_t<std::is_floating_point_v<T>, void>
outOfPlace (FloatType* out, const FloatType* in)
{
FloatType sum {};
for (int i = 0; i < size; ++i)
{
sum += in[i];
}

sum *= multiplier;

for (int i = 0; i < size; ++i)
{
out[i] = in[i] + sum;
}
}
#endif

/** Perform in-place Householder transform */
static inline void inPlace (FloatType* arr)
Expand Down Expand Up @@ -135,6 +153,7 @@ namespace MatrixOps
}
}

#if ! CHOWDSP_NO_XSIMD
/** Perform unscaled Hadamard transformation (SIMD fallback) */
template <typename T = FloatType>
static inline std::enable_if_t<SampleTypeHelpers::IsSIMDRegister<T> && size == 1, void>
Expand Down Expand Up @@ -190,9 +209,17 @@ namespace MatrixOps
for (int i = 0; i < size; ++i)
arr[i] *= scalingFactor;
}
#else
template <typename T = FloatType>
static inline std::enable_if_t<std::is_floating_point_v<T>, void>
inPlace (FloatType* arr)
{
recursiveUnscaled (arr, arr);

for (int i = 0; i < size; ++i)
arr[i] *= scalingFactor;
}
#endif
};
} // namespace MatrixOps

} // namespace chowdsp

#endif // ! CHOWDSP_NO_XSIMD
2 changes: 1 addition & 1 deletion modules/dsp/chowdsp_reverb/Reverb/chowdsp_Diffuser.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class Diffuser
int delayWritePointer = 0;
std::array<FloatType, (size_t) nChannels> delayReadPointers;

alignas (xsimd::default_arch::alignment()) std::array<FloatType, (size_t) nChannels> outData;
alignas (SIMDUtils::defaultSIMDAlignment) std::array<FloatType, (size_t) nChannels> outData;

FloatType fsOver1000 = FloatType (48000 / 1000);

Expand Down
4 changes: 2 additions & 2 deletions modules/dsp/chowdsp_reverb/Reverb/chowdsp_FDN.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ struct DefaultFDNConfig
static const FloatType* doFeedbackProcess (DefaultFDNConfig& fdnConfig, const FloatType* data);

protected:
alignas (xsimd::default_arch::alignment()) std::array<FloatType, (size_t) nChannels> fbData;
alignas (SIMDUtils::defaultSIMDAlignment) std::array<FloatType, (size_t) nChannels> fbData;

private:
std::array<ShelfFilter<FloatType>, (size_t) nChannels> shelfs;
Expand Down Expand Up @@ -112,7 +112,7 @@ class FDN

FDNConfig fdnConfig;

alignas (xsimd::default_arch::alignment()) std::array<FloatType, (size_t) nChannels> outData;
alignas (SIMDUtils::defaultSIMDAlignment) std::array<FloatType, (size_t) nChannels> outData;

FloatType fsOver1000 = FloatType (48000 / 1000);

Expand Down
2 changes: 2 additions & 0 deletions modules/dsp/chowdsp_reverb/chowdsp_reverb.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ namespace Reverb
} // namespace Reverb
} // namespace chowdsp

#if JUCE_MODULE_AVAILABLE_juce_dsp
#include "Reverb/chowdsp_ConvolutionDiffuser.h"
#endif
#include "Reverb/chowdsp_Diffuser.h"
#include "Reverb/chowdsp_FDN.h"

Expand Down