diff --git a/common/mix.hpp b/common/mix.hpp index 28d1712..8a4b186 100644 --- a/common/mix.hpp +++ b/common/mix.hpp @@ -4,13 +4,13 @@ #include // Use like `Householder::inPlace(data)` - size must be ≥ 1 -template +template class Householder { - static constexpr Sample multiplier{-2.0/size}; + static constexpr T multiplier{-2.0/size}; public: - static void inPlace(Sample *arr) + static void inPlace(T *arr) { double sum = 0; for (int i = 0; i < size; ++i) @@ -28,11 +28,11 @@ class Householder }; // Use like `Hadamard::inPlace(data)` - size must be a power of 2 -template +template class Hadamard { public: - static inline void recursiveUnscaled(Sample * data) + static inline void recursiveUnscaled(T * data) { if (size <= 1) { @@ -41,8 +41,8 @@ class Hadamard constexpr int hSize = size/2; // Two (unscaled) Hadamards of half the size - Hadamard::recursiveUnscaled(data); - Hadamard::recursiveUnscaled(data + hSize); + Hadamard::recursiveUnscaled(data); + Hadamard::recursiveUnscaled(data + hSize); // Combine the two halves using sum/difference for (int i = 0; i < hSize; ++i) @@ -54,11 +54,11 @@ class Hadamard } } - static inline void inPlace(Sample * data) + static inline void inPlace(T * data) { recursiveUnscaled(data); - Sample scalingFactor = std::sqrt(1.0/size); + T scalingFactor = std::sqrt(1.0/size); for (int c = 0; c < size; ++c) { data[c] *= scalingFactor; @@ -66,13 +66,13 @@ class Hadamard } }; -template +template class Shuffle { public: - static inline void outOfPlace(T *in, T *out, const int *shuffle_spec) + static inline void outOfPlace(T in[size], T out[size], const int shuffle_spec[size]) { - for (int c=0; c < numCh; c++) + for (int c=0; c < size; c++) { T sign = 1; int s = shuffle_spec[c]; @@ -81,7 +81,7 @@ class Shuffle sign = -1; s *= -1; } - if (s >= numCh) + if (s >= size) { s = 0; } @@ -90,15 +90,33 @@ class Shuffle } }; - static inline void inPlace(T *data, const int *shuffle_spec) + static inline void inPlace(T in_out[size], const int shuffle_spec[size]) { - T temp[numCh]; - for (int c=0; c < numCh; c++) + T temp[size]; + for (int c=0; c < size; c++) { - temp[c] = data[c]; + temp[c] = in_out[c]; } - Shuffle::outOfPlace(temp, data, shuffle_spec); + Shuffle::outOfPlace(temp, in_out, shuffle_spec); }; }; +template +class Mix +{ + public: + static inline void split(T in, T out[size]) + { + for (uint c=0; c < size; c++) + { + out[c] = in; + } + } + + static inline T combine(T in_out[size]) + { + Householder::inPlace(in_out); + return in_out[0]; + } +}; #endif diff --git a/reverb/reverb.hpp b/reverb/reverb.hpp index 9ac4e56..c04ef10 100644 --- a/reverb/reverb.hpp +++ b/reverb/reverb.hpp @@ -108,20 +108,6 @@ class Diffusor Shuffle::inPlace(in_out, m_shuffle_spec); Hadamard::inPlace(in_out); } - - static inline void split(T in, T out[numCh]) - { - for (uint c=0; c < numCh; c++) - { - out[c] = in; - } - } - - static inline T combine(T in_out[numCh]) - { - Householder::inPlace(in_out); - return in_out[0]; - } }; template @@ -147,7 +133,7 @@ class Reverb for (int i=0; i < numPoints; i++) { T temp[numCh]; - Diffusor::split(in[i], temp); + Mix::split(in[i], temp); for (auto diffusor: m_diffusors) { diffusor.process_multi(temp);