Browse Source

Add simd::crossfade. Make MinBlepGenerator generic.

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

+ 6
- 6
include/dsp/minblep.hpp View File

@@ -15,9 +15,9 @@ https://www.cs.cmu.edu/~eli/papers/icmc01-hardsync.pdf
void minBlepImpulse(int z, int o, float *output); void minBlepImpulse(int z, int o, float *output);




template <int Z, int O>
template <int Z, int O, typename T = float>
struct MinBlepGenerator { struct MinBlepGenerator {
float buf[2 * Z] = {};
T buf[2 * Z] = {};
int pos = 0; int pos = 0;
float impulse[2 * Z * O + 1]; float impulse[2 * Z * O + 1];


@@ -27,7 +27,7 @@ struct MinBlepGenerator {
} }


/** Places a discontinuity with magnitude `x` at -1 < p <= 0 relative to the current frame */ /** Places a discontinuity with magnitude `x` at -1 < p <= 0 relative to the current frame */
void insertDiscontinuity(float p, float x) {
void insertDiscontinuity(float p, T x) {
if (!(-1 < p && p <= 0)) if (!(-1 < p && p <= 0))
return; return;
for (int j = 0; j < 2 * Z; j++) { for (int j = 0; j < 2 * Z; j++) {
@@ -37,9 +37,9 @@ struct MinBlepGenerator {
} }
} }


float process() {
float v = buf[pos];
buf[pos] = 0.f;
T process() {
T v = buf[pos];
buf[pos] = T(0);
pos = (pos + 1) % (2 * Z); pos = (pos + 1) % (2 * Z);
return v; return v;
} }


+ 6
- 0
include/simd/functions.hpp View File

@@ -172,6 +172,12 @@ inline float_4 rescale(float_4 x, float_4 xMin, float_4 xMax, float_4 yMin, floa
return yMin + (x - xMin) / (xMax - xMin) * (yMax - yMin); return yMin + (x - xMin) / (xMax - xMin) * (yMax - yMin);
} }


using math::crossfade;

inline float_4 crossfade(float_4 a, float_4 b, float_4 p) {
return a + (b - a) * p;
}

using math::sgn; using math::sgn;


inline float_4 sgn(float_4 x) { inline float_4 sgn(float_4 x) {


Loading…
Cancel
Save