- refactored

- BufferMulti numChannels is template parameter
This commit is contained in:
2025-11-09 13:20:16 +01:00
parent 01d644b76e
commit 681290c9ae
13 changed files with 318 additions and 221 deletions
+35
View File
@@ -0,0 +1,35 @@
/*
* jayDSP, A cross-platform Digital Signal Processing library written in modern C++.
* Copyright (C) 2025 Jens Ahrensfeld, All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* File: dsp_types.hpp
* Author Jens Ahrensfeld on 26.10.2025.
*/
#ifndef DSP_TYPES_HPP
#define DSP_TYPES_HPP
namespace dsp {
}
#endif // DSP_TYPES_HPP
+94
View File
@@ -0,0 +1,94 @@
#ifndef MIX_HPP
#define MIX_HPP
#include <cmath>
// Use like `Householder<double, 8>::inPlace(data)` - size must be ≥ 1
template<typename Sample, int size>
class Householder
{
static constexpr Sample multiplier{-2.0/size};
public:
static void inPlace(Sample *arr)
{
double sum = 0;
for (int i = 0; i < size; ++i)
{
sum += arr[i];
}
sum *= multiplier;
for (int i = 0; i < size; ++i)
{
arr[i] += sum;
}
};
};
// Use like `Hadamard<double, 8>::inPlace(data)` - size must be a power of 2
template<typename Sample, int size>
class Hadamard
{
public:
static inline void recursiveUnscaled(Sample * data)
{
if (size <= 1)
{
return;
}
constexpr int hSize = size/2;
// Two (unscaled) Hadamards of half the size
Hadamard<Sample, hSize>::recursiveUnscaled(data);
Hadamard<Sample, hSize>::recursiveUnscaled(data + hSize);
// Combine the two halves using sum/difference
for (int i = 0; i < hSize; ++i)
{
double a = data[i];
double b = data[i + hSize];
data[i] = (a + b);
data[i + hSize] = (a - b);
}
}
static inline void inPlace(Sample * data)
{
recursiveUnscaled(data);
Sample scalingFactor = std::sqrt(1.0/size);
for (int c = 0; c < size; ++c)
{
data[c] *= scalingFactor;
}
}
};
template<typename T, uint numCh>
class Shuffle
{
public:
static inline void outOfPlace(T *in, T *out, const int *shuffle_spec)
{
for (int c=0; c < numCh; c++)
{
T sign = 1;
int s = shuffle_spec[c];
if (s < 0)
{
sign = -1;
s *= -1;
}
if (s >= numCh)
{
s = 0;
}
out[s] = sign * in[c];
}
};
};
#endif