From fe50e81e5c9d74b94d3de92f8a7b3cb87c85e7ab Mon Sep 17 00:00:00 2001 From: martin-lueders <31972064+martin-lueders@users.noreply.github.com> Date: Thu, 20 Jun 2019 23:29:23 +0100 Subject: [PATCH] Code cleanup Signed-off-by: hemmer <915048+hemmer@users.noreply.github.com> --- src/ABC.cpp | 57 +++++++++++------------------- src/DualAtenuverter.cpp | 2 +- src/EvenVCO.cpp | 14 ++------ src/Mixer.cpp | 75 ++++++++++++++++----------------------- src/Rampage.cpp | 78 ++++++----------------------------------- src/SlewLimiter.cpp | 40 ++++----------------- src/simd_input.hpp | 24 +++++++++++++ src/simd_mask.hpp | 61 -------------------------------- 8 files changed, 94 insertions(+), 257 deletions(-) create mode 100644 src/simd_input.hpp delete mode 100644 src/simd_mask.hpp diff --git a/src/ABC.cpp b/src/ABC.cpp index 680f504..0c5efdc 100644 --- a/src/ABC.cpp +++ b/src/ABC.cpp @@ -1,17 +1,7 @@ #include "plugin.hpp" -#include "simd_mask.hpp" +#include "simd_input.hpp" -#define MAX(a,b) (a>b)?a:b -/* -static float clip(float x) { - // Pade approximant of x/(1 + x^12)^(1/12) - const float limit = 1.16691853009184; - x = clamp(x, -limit, limit); - return (x + 1.45833*std::pow(x, 13) + 0.559028*std::pow(x, 25) + 0.0427035*std::pow(x, 37)) - / (1. + 1.54167*std::pow(x, 12) + 0.642361*std::pow(x, 24) + 0.0579909*std::pow(x, 36)); -} -*/ static simd::float_4 clip4(simd::float_4 x) { // Pade approximant of x/(1 + x^12)^(1/12) @@ -67,8 +57,6 @@ struct ABC : Module { NUM_LIGHTS }; - ChannelMask channelMask; - ABC() { config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS); @@ -79,24 +67,23 @@ struct ABC : Module { } - - void process(const ProcessArgs &args) override { - simd::float_4 a1[4]; - simd::float_4 b1[4]; - simd::float_4 c1[4]; + simd::float_4 a1[4] = {}; + simd::float_4 b1[4] = {}; + simd::float_4 c1[4] = {}; simd::float_4 out1[4]; - simd::float_4 a2[4]; - simd::float_4 b2[4]; - simd::float_4 c2[4]; + simd::float_4 a2[4] = {}; + simd::float_4 b2[4] = {}; + simd::float_4 c2[4] = {}; simd::float_4 out2[4]; int channels_1 = 1; int channels_2 = 1; - + memset(out1, 0, sizeof(out1)); + memset(out2, 0, sizeof(out2)); // process upper section @@ -106,15 +93,15 @@ struct ABC : Module { int channels_B1 = inputs[B1_INPUT].getChannels(); int channels_C1 = inputs[C1_INPUT].getChannels(); - channels_1 = MAX(channels_1, channels_A1); - channels_1 = MAX(channels_1, channels_B1); - channels_1 = MAX(channels_1, channels_C1); + channels_1 = std::max(channels_1, channels_A1); + channels_1 = std::max(channels_1, channels_B1); + channels_1 = std::max(channels_1, channels_C1); float mult_B1 = (2.f/5.f)*exponentialBipolar80Pade_5_4(params[B1_LEVEL_PARAM].getValue()); float mult_C1 = exponentialBipolar80Pade_5_4(params[C1_LEVEL_PARAM].getValue()); - load_input(inputs[A1_INPUT], a1, channels_A1); - channelMask.apply(a1, channels_1); + if(inputs[A1_INPUT].isConnected()) load_input(inputs[A1_INPUT], a1, channels_A1); + else memset(a1, 0, sizeof(a1)); if(inputs[B1_INPUT].isConnected()) { load_input(inputs[B1_INPUT], b1, channels_B1); @@ -122,7 +109,6 @@ struct ABC : Module { } else { for(int c=0; cb)?a:b struct EvenVCO : Module { enum ParamIds { @@ -45,8 +44,6 @@ struct EvenVCO : Module { dsp::RCFilter triFilter; - ChannelMask channelMask; - EvenVCO() { config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS); configParam(OCTAVE_PARAM, -5.0, 4.0, 0.0, "Octave", "'", 0.5); @@ -78,9 +75,8 @@ struct EvenVCO : Module { int channels_pwm = inputs[PWM_INPUT].getChannels(); int channels = 1; - channels = MAX(channels, channels_pitch1); - channels = MAX(channels, channels_pitch2); - // channels = MAX(channels, channels_fm); + channels = std::max(channels, channels_pitch1); + channels = std::max(channels, channels_pitch2); float pitch_0 = 1.f + std::round(params[OCTAVE_PARAM].getValue()) + params[TUNE_PARAM].getValue() / 12.f; @@ -90,19 +86,16 @@ struct EvenVCO : Module { if(inputs[PITCH1_INPUT].isConnected()) { load_input(inputs[PITCH1_INPUT], pitch_1, channels_pitch1); - channelMask.apply(pitch_1, channels_pitch1); for(int c=0; cb)?a:b -#define MIN(a,b) (a(Vec(7, 324), module, Mixer::OUT1_OUTPUT)); addOutput(createOutput(Vec(43, 324), module, Mixer::OUT2_OUTPUT)); - addChild(createLight>(Vec(32.7, 310), module, Mixer::OUT_POS_LIGHT)); + addChild(createLight>(Vec(32.7, 310), module, Mixer::OUT_POS_LIGHT)); } }; diff --git a/src/Rampage.cpp b/src/Rampage.cpp index ecd4435..5e0321c 100644 --- a/src/Rampage.cpp +++ b/src/Rampage.cpp @@ -1,19 +1,17 @@ #include "plugin.hpp" -#include "simd_mask.hpp" +#include "simd_input.hpp" #include "PulseGenerator_4.hpp" -#define MAX(a,b) a>b?a:b - static simd::float_4 shapeDelta(simd::float_4 delta, simd::float_4 tau, float shape) { simd::float_4 lin = simd::sgn(delta) * 10.f / tau; if (shape < 0.f) { simd::float_4 log = simd::sgn(delta) * simd::float_4(40.f) / tau / (simd::fabs(delta) + simd::float_4(1.f)); - return crossfade_4(lin, log, -shape * 0.95f); + return simd::crossfade(lin, log, -shape * 0.95f); } else { simd::float_4 exp = M_E * delta / tau; - return crossfade_4(lin, exp, shape * 0.90f); + return simd::crossfade(lin, exp, shape * 0.90f); } } @@ -76,10 +74,6 @@ struct Rampage : Module { NUM_LIGHTS }; - /* - float out[2] = {}; - bool gate[2] = {}; - */ simd::float_4 out[2][4]; simd::float_4 gate[2][4]; // use simd __m128 logic instead of bool @@ -87,7 +81,7 @@ struct Rampage : Module { dsp::TSchmittTrigger trigger_4[2][4]; PulseGenerator_4 endOfCyclePulse[2][4]; - ChannelMask channelMask; + // ChannelMask channelMask; Rampage() { config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS); @@ -121,15 +115,15 @@ struct Rampage : Module { channels_in[part] = inputs[IN_A_INPUT+part].getChannels(); channels_trig[part] = inputs[TRIGG_A_INPUT+part].getChannels(); - channels[part] = MAX(channels_in[part], channels_trig[part]); - channels[part] = MAX(1, channels[part]); + channels[part] = std::max(channels_in[part], channels_trig[part]); + channels[part] = std::max(1, channels[part]); outputs[OUT_A_OUTPUT+part].setChannels(channels[part]); outputs[RISING_A_OUTPUT+part].setChannels(channels[part]); outputs[FALLING_A_OUTPUT+part].setChannels(channels[part]); outputs[EOC_A_OUTPUT+part].setChannels(channels[part]); } - int channels_max = MAX(channels[0], channels[1]); + int channels_max = std::max(channels[0], channels[1]); outputs[COMPARATOR_OUTPUT].setChannels(channels_max); outputs[MIN_OUTPUT].setChannels(channels_max); @@ -174,14 +168,14 @@ struct Rampage : Module { if(inputs[IN_A_INPUT + part].isConnected()) { load_input(inputs[IN_A_INPUT + part], in, channels_in[part]); - channelMask.apply_all(in, channels_in[part]); + // channelMask.apply_all(in, channels_in[part]); } else { memset(in, 0, sizeof(in)); } if(inputs[TRIGG_A_INPUT + part].isConnected()) { add_input(inputs[TRIGG_A_INPUT + part], in_trig, channels_trig[part]); - channelMask.apply_all(in_trig, channels_trig[part]); + // channelMask.apply_all(in_trig, channels_trig[part]); } if(inputs[EXP_CV_A_INPUT + part].isConnected()) { @@ -195,7 +189,7 @@ struct Rampage : Module { add_input(inputs[RISE_CV_A_INPUT + part], riseCV, channels[part]); add_input(inputs[FALL_CV_A_INPUT + part], fallCV, channels[part]); add_input(inputs[CYCLE_A_INPUT+part], cycle, channels[part]); - channelMask.apply(cycle, channels[part]); // check whether this is necessary + // channelMask.apply(cycle, channels[part]); // check whether this is necessary // start processing: @@ -272,61 +266,9 @@ struct Rampage : Module { lights[OUT_A_LIGHT + 3*part+2].setBrightness(10.0f); } - // Integrator - - // bool rising = false; - // bool falling = false; - - /* - if (delta > 0) { - // Rise - float riseCv = params[RISE_A_PARAM + c].getValue() - inputs[EXP_CV_A_INPUT + c].getVoltage() / 10.0 + inputs[RISE_CV_A_INPUT + c].getVoltage() / 10.0; - riseCv = clamp(riseCv, 0.0f, 1.0f); - float rise = minTime * std::pow(2.0, riseCv * 10.0); - out[c] += shapeDelta(delta, rise, shape) * args.sampleTime; - rising = (in - out[c] > 1e-3); - if (!rising) { - gate[c] = false; - } - } - else if (delta < 0) { - // Fall - float fallCv = params[FALL_A_PARAM + c].getValue() - inputs[EXP_CV_A_INPUT + c].getVoltage() / 10.0 + inputs[FALL_CV_A_INPUT + c].getVoltage() / 10.0; - fallCv = clamp(fallCv, 0.0f, 1.0f); - float fall = minTime * std::pow(2.0, fallCv * 10.0); - out[c] += shapeDelta(delta, fall, shape) * args.sampleTime; - falling = (in - out[c] < -1e-3); - if (!falling) { - // End of cycle, check if we should turn the gate back on (cycle mode) - endOfCyclePulse[c].trigger(1e-3); - if (params[CYCLE_A_PARAM + c].getValue() * 10.0 + inputs[CYCLE_A_INPUT + c].getVoltage() >= 4.0) { - gate[c] = true; - } - } - } - else { - gate[c] = false; - } - - - if (!rising && !falling) { - out[c] = in; - } - */ - - // outputs[RISING_A_OUTPUT + part].setVoltage((rising ? 10.0 : 0.0)); - // outputs[FALLING_A_OUTPUT + part].setVoltage((falling ? 10.0 : 0.0)); - // lights[RISING_A_LIGHT + part].setSmoothBrightness(rising ? 1.0 : 0.0, args.sampleTime); - // lights[FALLING_A_LIGHT + part].setSmoothBrightness(falling ? 1.0 : 0.0, args.sampleTime); - // outputs[EOC_A_OUTPUT + part].setVoltage((endOfCyclePulse[c].process(args.sampleTime) ? 10.0 : 0.0)); - // outputs[OUT_A_OUTPUT + part].setVoltage(out[c]); - // lights[OUT_A_LIGHT + part].setSmoothBrightness(out[c] / 10.0, args.sampleTime); - - } // for (int part, ... ) - // Logic float balance = params[BALANCE_PARAM].getValue(); diff --git a/src/SlewLimiter.cpp b/src/SlewLimiter.cpp index 68fc3e3..174f82e 100644 --- a/src/SlewLimiter.cpp +++ b/src/SlewLimiter.cpp @@ -1,5 +1,5 @@ #include "plugin.hpp" -#include "simd_mask.hpp" +#include "simd_input.hpp" struct SlewLimiter : Module { @@ -21,8 +21,6 @@ struct SlewLimiter : Module { }; simd::float_4 out[4]; - ChannelMask channelMask; - SlewLimiter() { config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS); @@ -42,7 +40,7 @@ struct SlewLimiter : Module { int channels = inputs[IN_INPUT].getChannels(); - // minimum and maximum slopes in volts per second + // minimum and std::maximum slopes in volts per second const float slewMin = 0.1; const float slewMax = 10000.f; // Amount of extra slew per voltage difference @@ -55,9 +53,9 @@ struct SlewLimiter : Module { outputs[OUT_OUTPUT].setChannels(channels); - load_input(inputs[IN_INPUT], in, channels); channelMask.apply(in, channels); - load_input(inputs[RISE_INPUT], riseCV, channels); channelMask.apply(riseCV, channels); - load_input(inputs[FALL_INPUT], fallCV, channels); channelMask.apply(fallCV, channels); + load_input(inputs[IN_INPUT], in, channels); + load_input(inputs[RISE_INPUT], riseCV, channels); + load_input(inputs[FALL_INPUT], fallCV, channels); for(int c=0; cin[c/4]), in[c/4], out[c/4]); out[c/4] = ifelse( delta_lt_0 & (out[c/4] out[c]) { - float rise = inputs[RISE_INPUT].getPolyVoltage(c) / 10.f + param_rise; - float slew = slewMax * std::pow(slewMin / slewMax, rise); - out[c] += slew * crossfade(1.f, shapeScale * (in - out[c]), shape) * args.sampleTime; - if (out[c] > in) - out[c] = in; - } - // Fall - else if (in < out[c]) { - float fall = inputs[FALL_INPUT].getPolyVoltage(c) / 10.f + param_fall; - float slew = slewMax * std::pow(slewMin / slewMax, fall); - out[c] -= slew * crossfade(1.f, shapeScale * (out[c] - in), shape) * args.sampleTime; - if (out[c] < in) - out[c] = in; - } - - } - outputs[OUT_OUTPUT].writeVoltages(out); - */ } }; diff --git a/src/simd_input.hpp b/src/simd_input.hpp new file mode 100644 index 0000000..2a54be8 --- /dev/null +++ b/src/simd_input.hpp @@ -0,0 +1,24 @@ +#pragma once + +#include "rack.hpp" + + + +inline void load_input(Input &in, simd::float_4 *v, int numChannels) { + int inChannels = in.getChannels(); + if(inChannels==1) { + for(int i=0; i