Browse Source

Make dsp::Decimator compatible with SIMD types.

tags/v1.0.0
Andrew Belt 5 years ago
parent
commit
d750c456a7
2 changed files with 6 additions and 6 deletions
  1. +5
    -5
      include/dsp/resampler.hpp
  2. +1
    -1
      include/simd/functions.hpp

+ 5
- 5
include/dsp/resampler.hpp View File

@@ -103,9 +103,9 @@ struct SampleRateConverter {




/** Downsamples by an integer factor. */ /** Downsamples by an integer factor. */
template <int OVERSAMPLE, int QUALITY>
template <int OVERSAMPLE, int QUALITY, typename T = float>
struct Decimator { struct Decimator {
float inBuffer[OVERSAMPLE*QUALITY];
T inBuffer[OVERSAMPLE*QUALITY];
float kernel[OVERSAMPLE*QUALITY]; float kernel[OVERSAMPLE*QUALITY];
int inIndex; int inIndex;


@@ -119,14 +119,14 @@ struct Decimator {
std::memset(inBuffer, 0, sizeof(inBuffer)); std::memset(inBuffer, 0, sizeof(inBuffer));
} }
/** `in` must be length OVERSAMPLE */ /** `in` must be length OVERSAMPLE */
float process(float *in) {
T process(T *in) {
// Copy input to buffer // Copy input to buffer
std::memcpy(&inBuffer[inIndex], in, OVERSAMPLE*sizeof(float));
std::memcpy(&inBuffer[inIndex], in, OVERSAMPLE*sizeof(T));
// Advance index // Advance index
inIndex += OVERSAMPLE; inIndex += OVERSAMPLE;
inIndex %= OVERSAMPLE*QUALITY; inIndex %= OVERSAMPLE*QUALITY;
// Perform naive convolution // Perform naive convolution
float out = 0.f;
T out = 0.f;
for (int i = 0; i < OVERSAMPLE*QUALITY; i++) { for (int i = 0; i < OVERSAMPLE*QUALITY; i++) {
int index = inIndex - 1 - i; int index = inIndex - 1 - i;
index = (index + OVERSAMPLE*QUALITY) % (OVERSAMPLE*QUALITY); index = (index + OVERSAMPLE*QUALITY) % (OVERSAMPLE*QUALITY);


+ 1
- 1
include/simd/functions.hpp View File

@@ -123,7 +123,7 @@ inline float_4 pow(float a, float_4 b) {


template <typename T> template <typename T>
T pow(T a, int b) { T pow(T a, int b) {
// Optimal with `-O3 -ffast-math` when b is known at compile-time
// Optimal with `-O3 -funsafe-math-optimizations` when b is known at compile-time
T p = 1; T p = 1;
for (int i = 1; i <= b; i *= 2) { for (int i = 1; i <= b; i *= 2) {
if (i & b) if (i & b)


Loading…
Cancel
Save