Browse Source

Update to latest math.hpp API

tags/v0.6.0
Andrew Belt 7 years ago
parent
commit
c4819e67f3
6 changed files with 27 additions and 27 deletions
  1. +1
    -1
      src/ABC.cpp
  2. +2
    -2
      src/DualAtenuverter.cpp
  3. +5
    -5
      src/EvenVCO.cpp
  4. +9
    -9
      src/Rampage.cpp
  5. +2
    -2
      src/SlewLimiter.cpp
  6. +8
    -8
      src/SpringReverb.cpp

+ 1
- 1
src/ABC.cpp View File

@@ -38,7 +38,7 @@ struct ABC : Module {


static float clip(float x) {
x = clampf(x, -2.0, 2.0);
x = clamp(x, -2.0f, 2.0f);
return x / powf(1.0 + powf(x, 24.0), 1/24.0);
}



+ 2
- 2
src/DualAtenuverter.cpp View File

@@ -35,8 +35,8 @@ struct DualAtenuverter : Module {
void DualAtenuverter::step() {
float out1 = inputs[IN1_INPUT].value * params[ATEN1_PARAM].value + params[OFFSET1_PARAM].value;
float out2 = inputs[IN2_INPUT].value * params[ATEN2_PARAM].value + params[OFFSET2_PARAM].value;
out1 = clampf(out1, -10.0, 10.0);
out2 = clampf(out2, -10.0, 10.0);
out1 = clamp(out1, -10.0f, 10.0f);
out2 = clamp(out2, -10.0f, 10.0f);

outputs[OUT1_OUTPUT].value = out1;
outputs[OUT2_OUTPUT].value = out2;


+ 5
- 5
src/EvenVCO.cpp View File

@@ -70,15 +70,15 @@ void EvenVCO::step() {
pitch += inputs[PITCH1_INPUT].value + inputs[PITCH2_INPUT].value;
pitch += inputs[FM_INPUT].value / 4.0;
float freq = 261.626 * powf(2.0, pitch);
freq = clampf(freq, 0.0, 20000.0);
freq = clamp(freq, 0.0f, 20000.0f);

// Pulse width
float pw = params[PWM_PARAM].value + inputs[PWM_INPUT].value / 5.0;
const float minPw = 0.05;
pw = rescalef(clampf(pw, -1.0, 1.0), -1.0, 1.0, minPw, 1.0-minPw);
pw = rescale(clamp(pw, -1.0f, 1.0f), -1.0f, 1.0f, minPw, 1.0f - minPw);

// Advance phase
float deltaPhase = clampf(freq / engineGetSampleRate(), 1e-6, 0.5);
float deltaPhase = clamp(freq * engineGetSampleTime(), 1e-6f, 0.5f);
float oldPhase = phase;
phase += deltaPhase;

@@ -110,8 +110,8 @@ void EvenVCO::step() {
triSquare += triSquareMinBLEP.shift();

// Integrate square for triangle
tri += 4.0 * triSquare * freq / engineGetSampleRate();
tri *= (1.0 - 40.0 / engineGetSampleRate());
tri += 4.0 * triSquare * freq * engineGetSampleTime();
tri *= (1.0 - 40.0 * engineGetSampleTime());

float sine = -cosf(2*M_PI * phase);
float doubleSaw = (phase < 0.5) ? (-1.0 + 4.0*phase) : (-1.0 + 4.0*(phase - 0.5));


+ 9
- 9
src/Rampage.cpp View File

@@ -76,14 +76,14 @@ struct Rampage : Module {


static float shapeDelta(float delta, float tau, float shape) {
float lin = sgnf(delta) * 10.0 / tau;
float lin = sgn(delta) * 10.0 / tau;
if (shape < 0.0) {
float log = sgnf(delta) * 40.0 / tau / (fabsf(delta) + 1.0);
return crossf(lin, log, -shape * 0.95);
float log = sgn(delta) * 40.0 / tau / (fabsf(delta) + 1.0);
return crossfade(lin, log, -shape * 0.95f);
}
else {
float exp = M_E * delta / tau;
return crossf(lin, exp, shape * 0.90);
return crossfade(lin, exp, shape * 0.90f);
}
}

@@ -114,9 +114,9 @@ void Rampage::step() {
if (delta > 0) {
// Rise
float riseCv = params[RISE_A_PARAM + c].value - inputs[EXP_CV_A_INPUT + c].value / 10.0 + inputs[RISE_CV_A_INPUT + c].value / 10.0;
riseCv = clampf(riseCv, 0.0, 1.0);
riseCv = clamp(riseCv, 0.0f, 1.0f);
float rise = minTime * powf(2.0, riseCv * 10.0);
out[c] += shapeDelta(delta, rise, shape) / engineGetSampleRate();
out[c] += shapeDelta(delta, rise, shape) * engineGetSampleTime();
rising = (in - out[c] > 1e-3);
if (!rising) {
gate[c] = false;
@@ -125,9 +125,9 @@ void Rampage::step() {
else if (delta < 0) {
// Fall
float fallCv = params[FALL_A_PARAM + c].value - inputs[EXP_CV_A_INPUT + c].value / 10.0 + inputs[FALL_CV_A_INPUT + c].value / 10.0;
fallCv = clampf(fallCv, 0.0, 1.0);
fallCv = clamp(fallCv, 0.0f, 1.0f);
float fall = minTime * powf(2.0, fallCv * 10.0);
out[c] += shapeDelta(delta, fall, shape) / engineGetSampleRate();
out[c] += shapeDelta(delta, fall, shape) * engineGetSampleTime();
falling = (in - out[c] < -1e-3);
if (!falling) {
// End of cycle, check if we should turn the gate back on (cycle mode)
@@ -149,7 +149,7 @@ void Rampage::step() {
outputs[FALLING_A_OUTPUT + c].value = (falling ? 10.0 : 0.0);
lights[RISING_A_LIGHT + c].value = (rising ? 1.0 : 0.0);
lights[FALLING_A_LIGHT + c].value = (falling ? 1.0 : 0.0);
outputs[EOC_A_OUTPUT + c].value = (endOfCyclePulse[c].process(1.0 / engineGetSampleRate()) ? 10.0 : 0.0);
outputs[EOC_A_OUTPUT + c].value = (endOfCyclePulse[c].process(engineGetSampleTime()) ? 10.0 : 0.0);
outputs[OUT_A_OUTPUT + c].value = out[c];
lights[OUT_A_LIGHT + c].value = out[c] / 10.0;
}


+ 2
- 2
src/SlewLimiter.cpp View File

@@ -40,7 +40,7 @@ void ::SlewLimiter::step() {
if (in > out) {
float rise = inputs[RISE_INPUT].value / 10.0 + params[RISE_PARAM].value;
float slew = slewMax * powf(slewMin / slewMax, rise);
out += slew * crossf(1.0, shapeScale * (in - out), shape) / engineGetSampleRate();
out += slew * crossfade(1.0f, shapeScale * (in - out), shape) * engineGetSampleTime();
if (out > in)
out = in;
}
@@ -48,7 +48,7 @@ void ::SlewLimiter::step() {
else if (in < out) {
float fall = inputs[FALL_INPUT].value / 10.0 + params[FALL_PARAM].value;
float slew = slewMax * powf(slewMin / slewMax, fall);
out -= slew * crossf(1.0, shapeScale * (out - in), shape) / engineGetSampleRate();
out -= slew * crossfade(1.0f, shapeScale * (out - in), shape) * engineGetSampleTime();
if (out < in)
out = in;
}


+ 8
- 8
src/SpringReverb.cpp View File

@@ -86,7 +86,7 @@ struct RealTimeConvolver {
for (size_t i = 0; i < kernelBlocks; i++) {
// Pad each block with zeros
memset(tmpBlock, 0, sizeof(float) * blockSize*2);
size_t len = mini(blockSize, length - i*blockSize);
size_t len = min(blockSize, length - i*blockSize);
memcpy(tmpBlock, &kernel[i*blockSize], sizeof(float)*len);
// Compute fft
pffft_transform(pffft, tmpBlock, &kernelFfts[blockSize*2 * i], NULL, PFFFT_FORWARD);
@@ -200,7 +200,7 @@ void SpringReverb::step() {
float dry = in1 * level1 + in2 * level2;

// HPF on dry
float dryCutoff = 200.0 * powf(20.0, params[HPF_PARAM].value) / engineGetSampleRate();
float dryCutoff = 200.0 * powf(20.0, params[HPF_PARAM].value) * engineGetSampleTime();
dryFilter.setCutoff(dryCutoff);
dryFilter.process(dry);

@@ -241,14 +241,14 @@ void SpringReverb::step() {
if (outputBuffer.empty())
return;
float wet = outputBuffer.shift().samples[0];
float crossfade = clampf(params[WET_PARAM].value + inputs[MIX_CV_INPUT].value / 10.0, 0.0, 1.0);
float mix = crossf(in1, wet, crossfade);
float balance = clamp(params[WET_PARAM].value + inputs[MIX_CV_INPUT].value / 10.0f, 0.0f, 1.0f);
float mix = crossfade(in1, wet, balance);

outputs[WET_OUTPUT].value =clampf(wet, -10.0, 10.0);
outputs[MIX_OUTPUT].value =clampf(mix, -10.0, 10.0);
outputs[WET_OUTPUT].value = clamp(wet, -10.0f, 10.0f);
outputs[MIX_OUTPUT].value = clamp(mix, -10.0f, 10.0f);

// Set lights
float lightRate = 5.0 / engineGetSampleRate();
float lightRate = 5.0 * engineGetSampleTime();
vuFilter.setRate(lightRate);
vuFilter.process(fabsf(wet));
lightFilter.setRate(lightRate);
@@ -257,7 +257,7 @@ void SpringReverb::step() {
float vuValue = vuFilter.peak();
for (int i = 0; i < 7; i++) {
float light = powf(1.413, i) * vuValue / 10.0 - 1.0;
lights[VU1_LIGHT + i].value = clampf(light, 0.0, 1.0);
lights[VU1_LIGHT + i].value = clamp(light, 0.0f, 1.0f);
}
lights[PEAK_LIGHT].value = lightFilter.peak();
}


Loading…
Cancel
Save