diff --git a/plugin.json b/plugin.json index 083e923..b8e6e33 100644 --- a/plugin.json +++ b/plugin.json @@ -1,6 +1,6 @@ { "slug": "Befaco", - "version": "1.0.1", + "version": "1.1.0", "license": "BSD-3-Clause", "name": "Befaco", "author": "VCV", diff --git a/src/ABC.cpp b/src/ABC.cpp index 0c5efdc..5393153 100644 --- a/src/ABC.cpp +++ b/src/ABC.cpp @@ -2,30 +2,19 @@ #include "simd_input.hpp" - -static simd::float_4 clip4(simd::float_4 x) { +template +static T clip4(T x) { // Pade approximant of x/(1 + x^12)^(1/12) - const simd::float_4 limit = simd::float_4(1.16691853009184); - const simd::float_4 cnst_10 = simd::float_4(10.0); - const simd::float_4 cnst_1 = simd::float_4(1.0); - const simd::float_4 cnst_01 = simd::float_4(0.1); - - const simd::float_4 coeff_1 = simd::float_4(1.45833); - const simd::float_4 coeff_2 = simd::float_4(0.559028); - const simd::float_4 coeff_3 = simd::float_4(0.0427035); - const simd::float_4 coeff_4 = simd::float_4(1.54167); - const simd::float_4 coeff_5 = simd::float_4(0.642361); - const simd::float_4 coeff_6 = simd::float_4(0.0579909); - - x = clamp(x*cnst_01, -limit, limit); - return cnst_10 * (x + coeff_1*simd::pow(x, 13) + coeff_2*simd::pow(x, 25) + coeff_3*simd::pow(x, 37)) - / (cnst_1 + coeff_4*simd::pow(x, 12) + coeff_5*simd::pow(x, 24) + coeff_6*simd::pow(x, 36)); + const T limit = 1.16691853009184f; + x = clamp(x * 0.1f, -limit, limit); + return 10.0f * (x + 1.45833f * simd::pow(x, 13) + 0.559028f * simd::pow(x, 25) + 0.0427035f * simd::pow(x, 37)) + / (1.0f + 1.54167f * simd::pow(x, 12) + 0.642361f * simd::pow(x, 24) + 0.0579909f * simd::pow(x, 36)); } static float exponentialBipolar80Pade_5_4(float x) { - return (0.109568*x + 0.281588*std::pow(x, 3) + 0.133841*std::pow(x, 5)) - / (1. - 0.630374*std::pow(x, 2) + 0.166271*std::pow(x, 4)); + return (0.109568 * x + 0.281588 * std::pow(x, 3) + 0.133841 * std::pow(x, 5)) + / (1. - 0.630374 * std::pow(x, 2) + 0.166271 * std::pow(x, 4)); } @@ -57,7 +46,6 @@ struct ABC : Module { NUM_LIGHTS }; - ABC() { config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS); configParam(B1_LEVEL_PARAM, -1.0, 1.0, 0.0, "B1 Level"); @@ -66,7 +54,6 @@ struct ABC : Module { configParam(C2_LEVEL_PARAM, -1.0, 1.0, 0.0, "C2 Level"); } - void process(const ProcessArgs &args) override { simd::float_4 a1[4] = {}; @@ -87,7 +74,7 @@ struct ABC : Module { // process upper section - if(outputs[OUT1_OUTPUT].isConnected() || outputs[OUT2_OUTPUT].isConnected() ) { + if (outputs[OUT1_OUTPUT].isConnected() || outputs[OUT2_OUTPUT].isConnected()) { int channels_A1 = inputs[A1_INPUT].getChannels(); int channels_B1 = inputs[B1_INPUT].getChannels(); @@ -97,33 +84,41 @@ struct ABC : Module { 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_B1 = (2.f / 5.f) * exponentialBipolar80Pade_5_4(params[B1_LEVEL_PARAM].getValue()); float mult_C1 = exponentialBipolar80Pade_5_4(params[C1_LEVEL_PARAM].getValue()); - if(inputs[A1_INPUT].isConnected()) load_input(inputs[A1_INPUT], a1, channels_A1); - else memset(a1, 0, sizeof(a1)); + if (inputs[A1_INPUT].isConnected()) + load_input(inputs[A1_INPUT], a1, channels_A1); + else + memset(a1, 0, sizeof(a1)); - if(inputs[B1_INPUT].isConnected()) { + if (inputs[B1_INPUT].isConnected()) { load_input(inputs[B1_INPUT], b1, channels_B1); - for(int c=0; c0?channels1:1; - int channels2 = inputs[IN2_INPUT].getChannels(); channels2 = channels2>0?channels2:1; + int channels1 = inputs[IN1_INPUT].getChannels(); + channels1 = channels1 > 0 ? channels1 : 1; + int channels2 = inputs[IN2_INPUT].getChannels(); + channels2 = channels2 > 0 ? channels2 : 1; - simd::float_4 att1 = simd::float_4(params[ATEN1_PARAM].getValue()); - simd::float_4 att2 = simd::float_4(params[ATEN2_PARAM].getValue()); + float att1 = params[ATEN1_PARAM].getValue(); + float att2 = params[ATEN2_PARAM].getValue(); - simd::float_4 offset1 = simd::float_4(params[OFFSET1_PARAM].getValue()); - simd::float_4 offset2 = simd::float_4(params[OFFSET2_PARAM].getValue()); + float offset1 = params[OFFSET1_PARAM].getValue(); + float offset2 = params[OFFSET2_PARAM].getValue(); + + for (int c = 0; c < channels1; c += 4) { + out1[c / 4] = clamp(float_4::load(inputs[IN1_INPUT].getVoltages(c)) * att1 + offset1, -10.f, 10.f); + } + for (int c = 0; c < channels2; c += 4) { + out2[c / 4] = clamp(float_4::load(inputs[IN2_INPUT].getVoltages(c)) * att2 + offset2, -10.f, 10.f); + } - for (int c = 0; c < channels1; c += 4) out1[c / 4] = clamp(simd::float_4::load(inputs[IN1_INPUT].getVoltages(c)) * att1 + offset1, -10.f, 10.f); - for (int c = 0; c < channels2; c += 4) out2[c / 4] = clamp(simd::float_4::load(inputs[IN2_INPUT].getVoltages(c)) * att2 + offset2, -10.f, 10.f); - outputs[OUT1_OUTPUT].setChannels(channels1); outputs[OUT2_OUTPUT].setChannels(channels2); - - for (int c = 0; c < channels1; c += 4) out1[c / 4].store(outputs[OUT1_OUTPUT].getVoltages(c)); - for (int c = 0; c < channels2; c += 4) out2[c / 4].store(outputs[OUT2_OUTPUT].getVoltages(c)); - - float light1 = outputs[OUT1_OUTPUT].getVoltageSum()/channels1; - float light2 = outputs[OUT2_OUTPUT].getVoltageSum()/channels2; - - if(channels1==1) { - lights[OUT1_LIGHT ].setSmoothBrightness(light1 / 5.f, args.sampleTime); - lights[OUT1_LIGHT+1].setSmoothBrightness(-light1 / 5.f, args.sampleTime); - lights[OUT1_LIGHT+2].setBrightness(0.0f); - } else { - lights[OUT1_LIGHT ].setBrightness(0.0f); - lights[OUT1_LIGHT+1].setBrightness(0.0f); - lights[OUT1_LIGHT+2].setBrightness(10.0f); - } - if(channels2==1) { - lights[OUT2_LIGHT ].setSmoothBrightness(light2 / 5.f, args.sampleTime); - lights[OUT2_LIGHT+1].setSmoothBrightness(-light2 / 5.f, args.sampleTime); - lights[OUT2_LIGHT+2].setBrightness(0.0f); - } else { - lights[OUT2_LIGHT ].setBrightness(0.0f); - lights[OUT2_LIGHT+1].setBrightness(0.0f); - lights[OUT2_LIGHT+2].setBrightness(10.0f); + for (int c = 0; c < channels1; c += 4) { + out1[c / 4].store(outputs[OUT1_OUTPUT].getVoltages(c)); + } + for (int c = 0; c < channels2; c += 4) { + out2[c / 4].store(outputs[OUT2_OUTPUT].getVoltages(c)); } + float light1 = outputs[OUT1_OUTPUT].getVoltageSum() / channels1; + float light2 = outputs[OUT2_OUTPUT].getVoltageSum() / channels2; + if (channels1 == 1) { + lights[OUT1_LIGHT + 0].setSmoothBrightness(light1 / 5.f, args.sampleTime); + lights[OUT1_LIGHT + 1].setSmoothBrightness(-light1 / 5.f, args.sampleTime); + lights[OUT1_LIGHT + 2].setBrightness(0.0f); + } + else { + lights[OUT1_LIGHT + 0].setBrightness(0.0f); + lights[OUT1_LIGHT + 1].setBrightness(0.0f); + lights[OUT1_LIGHT + 2].setBrightness(10.0f); + } + if (channels2 == 1) { + lights[OUT2_LIGHT + 0].setSmoothBrightness(light2 / 5.f, args.sampleTime); + lights[OUT2_LIGHT + 1].setSmoothBrightness(-light2 / 5.f, args.sampleTime); + lights[OUT2_LIGHT + 2].setBrightness(0.0f); + } + else { + lights[OUT2_LIGHT + 0].setBrightness(0.0f); + lights[OUT2_LIGHT + 1].setBrightness(0.0f); + lights[OUT2_LIGHT + 2].setBrightness(10.0f); + } } }; diff --git a/src/EvenVCO.cpp b/src/EvenVCO.cpp index b78d3a3..a7f976c 100644 --- a/src/EvenVCO.cpp +++ b/src/EvenVCO.cpp @@ -49,21 +49,21 @@ struct EvenVCO : Module { configParam(OCTAVE_PARAM, -5.0, 4.0, 0.0, "Octave", "'", 0.5); configParam(TUNE_PARAM, -7.0, 7.0, 0.0, "Tune", " semitones"); configParam(PWM_PARAM, -1.0, 1.0, 0.0, "Pulse width"); - - for(int i=0; i<4; i++) { + + for (int i = 0; i < 4; i++) { phase[i] = simd::float_4(0.0f); tri[i] = simd::float_4(0.0f); } - for(int c=0; c= 0.5) { - float crossing = -(phase[c/4].s[c%4] - 0.5) / deltaPhase[c/4].s[c%4]; + if (oldPhase[c / 4].s[c % 4] < 0.5 && phase[c / 4].s[c % 4] >= 0.5) { + float crossing = -(phase[c / 4].s[c % 4] - 0.5) / deltaPhase[c / 4].s[c % 4]; triSquareMinBlep[c].insertDiscontinuity(crossing, 2.f); doubleSawMinBlep[c].insertDiscontinuity(crossing, -2.f); } - if (!halfPhase[c] && phase[c/4].s[c%4] >= pw[c/4].s[c%4]) { - float crossing = -(phase[c/4].s[c%4] - pw[c/4].s[c%4]) / deltaPhase[c/4].s[c%4]; + if (!halfPhase[c] && phase[c / 4].s[c % 4] >= pw[c / 4].s[c % 4]) { + float crossing = -(phase[c / 4].s[c % 4] - pw[c / 4].s[c % 4]) / deltaPhase[c / 4].s[c % 4]; squareMinBlep[c].insertDiscontinuity(crossing, 2.f); halfPhase[c] = true; - } + } // Reset phase if at end of cycle - if (phase[c/4].s[c%4] >= 1.f) { - phase[c/4].s[c%4] -= 1.f; - float crossing = -phase[c/4].s[c%4] / deltaPhase[c/4].s[c%4]; + if (phase[c / 4].s[c % 4] >= 1.f) { + phase[c / 4].s[c % 4] -= 1.f; + float crossing = -phase[c / 4].s[c % 4] / deltaPhase[c / 4].s[c % 4]; triSquareMinBlep[c].insertDiscontinuity(crossing, -2.f); doubleSawMinBlep[c].insertDiscontinuity(crossing, -2.f); squareMinBlep[c].insertDiscontinuity(crossing, -2.f); @@ -171,11 +177,11 @@ struct EvenVCO : Module { simd::float_4 square[4]; simd::float_4 triOut[4]; - for(int c=0; c(Vec(15, 0))); addChild(createWidget(Vec(15, 365))); - addChild(createWidget(Vec(15*6, 0))); - addChild(createWidget(Vec(15*6, 365))); + addChild(createWidget(Vec(15 * 6, 0))); + addChild(createWidget(Vec(15 * 6, 365))); addParam(createParam(Vec(22, 32), module, EvenVCO::OCTAVE_PARAM)); addParam(createParam(Vec(73, 131), module, EvenVCO::TUNE_PARAM)); diff --git a/src/Mixer.cpp b/src/Mixer.cpp index f77ea5f..19dd327 100644 --- a/src/Mixer.cpp +++ b/src/Mixer.cpp @@ -2,7 +2,6 @@ #include "simd_input.hpp" - struct Mixer : Module { enum ParamIds { CH1_PARAM, @@ -30,21 +29,15 @@ struct Mixer : Module { NUM_LIGHTS }; - simd::float_4 minus_one; - Mixer() { config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS); configParam(CH1_PARAM, 0.0, 1.0, 0.0, "Ch 1 level", "%", 0, 100); configParam(CH2_PARAM, 0.0, 1.0, 0.0, "Ch 2 level", "%", 0, 100); configParam(CH3_PARAM, 0.0, 1.0, 0.0, "Ch 3 level", "%", 0, 100); configParam(CH4_PARAM, 0.0, 1.0, 0.0, "Ch 4 level", "%", 0, 100); - - minus_one = simd::float_4(-1.0f); } - void process(const ProcessArgs &args) override { - int channels1 = inputs[IN1_INPUT].getChannels(); int channels2 = inputs[IN2_INPUT].getChannels(); int channels3 = inputs[IN3_INPUT].getChannels(); @@ -55,66 +48,68 @@ struct Mixer : Module { out_channels = std::max(out_channels, channels2); out_channels = std::max(out_channels, channels3); out_channels = std::max(out_channels, channels4); - + simd::float_4 mult1 = simd::float_4(params[CH1_PARAM].getValue()); simd::float_4 mult2 = simd::float_4(params[CH2_PARAM].getValue()); simd::float_4 mult3 = simd::float_4(params[CH3_PARAM].getValue()); simd::float_4 mult4 = simd::float_4(params[CH4_PARAM].getValue()); - simd::float_4 out[4]; + simd::float_4 out[4]; - memset(out, 0, sizeof(out)); + std::memset(out, 0, sizeof(out)); - if(inputs[IN1_INPUT].isConnected()) { - for(int c=0; c simd::float_4::zero()); + /** Advances the state by `deltaTime`. Returns whether the pulse is in the HIGH state. */ + inline simd::float_4 process(float deltaTime) { - remaining -= ifelse(mask, simd::float_4(deltaTime), simd::float_4::zero()); - return ifelse(mask, simd::float_4::mask(), simd::float_4::zero()); - } + simd::float_4 mask = (remaining > simd::float_4::zero()); - /** Begins a trigger with the given `duration`. */ - inline void trigger(simd::float_4 mask, float duration = 1e-3f) { - // Keep the previous pulse if the existing pulse will be held longer than the currently requested one. - simd::float_4 duration_4 = simd::float_4(duration); - remaining = ifelse( mask&(duration_4>remaining), duration_4, remaining); - } + remaining -= ifelse(mask, simd::float_4(deltaTime), simd::float_4::zero()); + return ifelse(mask, simd::float_4::mask(), simd::float_4::zero()); + } + + /** Begins a trigger with the given `duration`. */ + inline void trigger(simd::float_4 mask, float duration = 1e-3f) { + // Keep the previous pulse if the existing pulse will be held longer than the currently requested one. + simd::float_4 duration_4 = simd::float_4(duration); + remaining = ifelse(mask & (duration_4 > remaining), duration_4, remaining); + } }; diff --git a/src/Rampage.cpp b/src/Rampage.cpp index 5e0321c..7af49bc 100644 --- a/src/Rampage.cpp +++ b/src/Rampage.cpp @@ -81,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); @@ -99,29 +99,28 @@ struct Rampage : Module { configParam(CYCLE_B_PARAM, 0.0, 1.0, 0.0, "Ch 2 cycle"); configParam(BALANCE_PARAM, 0.0, 1.0, 0.5, "Balance"); - memset(out, 0, sizeof(out)); - memset(gate, 0, sizeof(gate)); + std::memset(out, 0, sizeof(out)); + std::memset(gate, 0, sizeof(gate)); } void process(const ProcessArgs &args) override { - int channels_in[2]; int channels_trig[2]; int channels[2]; - // determine number of channels: + // determine number of channels: + + for (int part = 0; part < 2; part++) { - for (int part=0; part<2; part++) { - - channels_in[part] = inputs[IN_A_INPUT+part].getChannels(); - channels_trig[part] = inputs[TRIGG_A_INPUT+part].getChannels(); + channels_in[part] = inputs[IN_A_INPUT + part].getChannels(); + channels_trig[part] = inputs[TRIGG_A_INPUT + part].getChannels(); 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]); + 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 = std::max(channels[0], channels[1]); @@ -145,9 +144,15 @@ struct Rampage : Module { float shape = params[SHAPE_A_PARAM + part].getValue(); float minTime; switch ((int) params[RANGE_A_PARAM + part].getValue()) { - case 0: minTime = 1e-2; break; - case 1: minTime = 1e-3; break; - default: minTime = 1e-1; break; + case 0: + minTime = 1e-2; + break; + case 1: + minTime = 1e-3; + break; + default: + minTime = 1e-1; + break; } simd::float_4 param_rise = simd::float_4(params[RISE_A_PARAM + part].getValue() * 10.0f); @@ -155,115 +160,117 @@ struct Rampage : Module { simd::float_4 param_trig = simd::float_4(params[TRIGG_A_PARAM + part].getValue() * 20.0f); simd::float_4 param_cycle = simd::float_4(params[CYCLE_A_PARAM + part].getValue() * 10.0f); - for(int c=0; c simd::float_4::zero(); simd::float_4 delta_lt_0 = delta < simd::float_4::zero(); - simd::float_4 delta_eq_0 = ~(delta_lt_0|delta_gt_0); + simd::float_4 delta_eq_0 = ~(delta_lt_0 | delta_gt_0); - simd::float_4 rateCV = ifelse(delta_gt_0, riseCV[c/4], simd::float_4::zero()); - rateCV = ifelse(delta_lt_0, fallCV[c/4], rateCV); + simd::float_4 rateCV = ifelse(delta_gt_0, riseCV[c / 4], simd::float_4::zero()); + rateCV = ifelse(delta_lt_0, fallCV[c / 4], rateCV); rateCV = clamp(rateCV, simd::float_4::zero(), simd::float_4(10.0f)); simd::float_4 rate = minTime * simd::pow(2.0f, rateCV); - out[part][c/4] += shapeDelta(delta, rate, shape) * args.sampleTime; + out[part][c / 4] += shapeDelta(delta, rate, shape) * args.sampleTime; - simd::float_4 rising = (in[c/4] - out[part][c/4]) > simd::float_4( 1e-3); - simd::float_4 falling = (in[c/4] - out[part][c/4]) < simd::float_4(-1e-3); - simd::float_4 end_of_cycle = simd::andnot(falling,delta_lt_0); + simd::float_4 rising = (in[c / 4] - out[part][c / 4]) > simd::float_4(1e-3); + simd::float_4 falling = (in[c / 4] - out[part][c / 4]) < simd::float_4(-1e-3); + simd::float_4 end_of_cycle = simd::andnot(falling, delta_lt_0); - endOfCyclePulse[part][c/4].trigger(end_of_cycle, 1e-3); + endOfCyclePulse[part][c / 4].trigger(end_of_cycle, 1e-3); - gate[part][c/4] = ifelse( simd::andnot(rising, delta_gt_0), simd::float_4::zero(), gate[part][c/4]); - gate[part][c/4] = ifelse( end_of_cycle & (cycle[c/4]>=simd::float_4(4.0f)), simd::float_4::mask(), gate[part][c/4] ); - gate[part][c/4] = ifelse( delta_eq_0, simd::float_4::zero(), gate[part][c/4] ); + gate[part][c / 4] = ifelse(simd::andnot(rising, delta_gt_0), simd::float_4::zero(), gate[part][c / 4]); + gate[part][c / 4] = ifelse(end_of_cycle & (cycle[c / 4] >= simd::float_4(4.0f)), simd::float_4::mask(), gate[part][c / 4]); + gate[part][c / 4] = ifelse(delta_eq_0, simd::float_4::zero(), gate[part][c / 4]); - out[part][c/4] = ifelse( rising|falling, out[part][c/4], in[c/4] ); + out[part][c / 4] = ifelse(rising | falling, out[part][c / 4], in[c / 4]); - simd::float_4 out_rising = ifelse(rising, simd::float_4(10.0f), simd::float_4::zero() ); - simd::float_4 out_falling = ifelse(falling, simd::float_4(10.0f), simd::float_4::zero() ); + simd::float_4 out_rising = ifelse(rising, simd::float_4(10.0f), simd::float_4::zero()); + simd::float_4 out_falling = ifelse(falling, simd::float_4(10.0f), simd::float_4::zero()); - simd::float_4 pulse = endOfCyclePulse[part][c/4].process(args.sampleTime); - simd::float_4 out_EOC = ifelse(pulse, simd::float_4(10.f), simd::float_4::zero() ); + simd::float_4 pulse = endOfCyclePulse[part][c / 4].process(args.sampleTime); + simd::float_4 out_EOC = ifelse(pulse, simd::float_4(10.f), simd::float_4::zero()); - out[part][c/4].store(outputs[OUT_A_OUTPUT+part].getVoltages(c)); + out[part][c / 4].store(outputs[OUT_A_OUTPUT + part].getVoltages(c)); - out_rising.store( outputs[RISING_A_OUTPUT+part].getVoltages(c)); - out_falling.store(outputs[FALLING_A_OUTPUT+part].getVoltages(c)); - out_EOC.store(outputs[EOC_A_OUTPUT+part].getVoltages(c)); + out_rising.store(outputs[RISING_A_OUTPUT + part].getVoltages(c)); + out_falling.store(outputs[FALLING_A_OUTPUT + part].getVoltages(c)); + out_EOC.store(outputs[EOC_A_OUTPUT + part].getVoltages(c)); } // for(int c, ...) - if(channels[part] == 1) { - lights[RISING_A_LIGHT + 3*part ].setSmoothBrightness(outputs[RISING_A_OUTPUT+part].getVoltage()/10.f, args.sampleTime); - lights[RISING_A_LIGHT + 3*part+1].setBrightness(0.0f); - lights[RISING_A_LIGHT + 3*part+2].setBrightness(0.0f); - lights[FALLING_A_LIGHT + 3*part ].setSmoothBrightness(outputs[FALLING_A_OUTPUT+part].getVoltage()/10.f, args.sampleTime); - lights[FALLING_A_LIGHT + 3*part+1].setBrightness(0.0f); - lights[FALLING_A_LIGHT + 3*part+2].setBrightness(0.0f); - lights[OUT_A_LIGHT + 3*part ].setSmoothBrightness(out[part][0].s[0] / 10.0, args.sampleTime); - lights[OUT_A_LIGHT + 3*part+1].setBrightness(0.0f); - lights[OUT_A_LIGHT + 3*part+2].setBrightness(0.0f); - } else { - lights[RISING_A_LIGHT + 3*part ].setBrightness(0.0f); - lights[RISING_A_LIGHT + 3*part+1].setBrightness(0.0f); - lights[RISING_A_LIGHT + 3*part+2].setBrightness(10.0f); - lights[FALLING_A_LIGHT + 3*part ].setBrightness(0.0f); - lights[FALLING_A_LIGHT + 3*part+1].setBrightness(0.0f); - lights[FALLING_A_LIGHT + 3*part+2].setBrightness(10.0f); - lights[OUT_A_LIGHT + 3*part ].setBrightness(0.0f); - lights[OUT_A_LIGHT + 3*part+1].setBrightness(0.0f); - lights[OUT_A_LIGHT + 3*part+2].setBrightness(10.0f); + if (channels[part] == 1) { + lights[RISING_A_LIGHT + 3 * part ].setSmoothBrightness(outputs[RISING_A_OUTPUT + part].getVoltage() / 10.f, args.sampleTime); + lights[RISING_A_LIGHT + 3 * part + 1].setBrightness(0.0f); + lights[RISING_A_LIGHT + 3 * part + 2].setBrightness(0.0f); + lights[FALLING_A_LIGHT + 3 * part ].setSmoothBrightness(outputs[FALLING_A_OUTPUT + part].getVoltage() / 10.f, args.sampleTime); + lights[FALLING_A_LIGHT + 3 * part + 1].setBrightness(0.0f); + lights[FALLING_A_LIGHT + 3 * part + 2].setBrightness(0.0f); + lights[OUT_A_LIGHT + 3 * part ].setSmoothBrightness(out[part][0].s[0] / 10.0, args.sampleTime); + lights[OUT_A_LIGHT + 3 * part + 1].setBrightness(0.0f); + lights[OUT_A_LIGHT + 3 * part + 2].setBrightness(0.0f); + } + else { + lights[RISING_A_LIGHT + 3 * part ].setBrightness(0.0f); + lights[RISING_A_LIGHT + 3 * part + 1].setBrightness(0.0f); + lights[RISING_A_LIGHT + 3 * part + 2].setBrightness(10.0f); + lights[FALLING_A_LIGHT + 3 * part ].setBrightness(0.0f); + lights[FALLING_A_LIGHT + 3 * part + 1].setBrightness(0.0f); + lights[FALLING_A_LIGHT + 3 * part + 2].setBrightness(10.0f); + lights[OUT_A_LIGHT + 3 * part ].setBrightness(0.0f); + lights[OUT_A_LIGHT + 3 * part + 1].setBrightness(0.0f); + lights[OUT_A_LIGHT + 3 * part + 2].setBrightness(10.0f); } } // for (int part, ... ) @@ -272,19 +279,19 @@ struct Rampage : Module { // Logic float balance = params[BALANCE_PARAM].getValue(); - for(int c=0; c 0.5) a *= 2.0f * (1.0 - balance); - simd::float_4 comp = ifelse( b>a, simd::float_4(10.0f), simd::float_4::zero() ); - simd::float_4 out_min = simd::fmin(a,b); - simd::float_4 out_max = simd::fmax(a,b); + simd::float_4 comp = ifelse(b > a, simd::float_4(10.0f), simd::float_4::zero()); + simd::float_4 out_min = simd::fmin(a, b); + simd::float_4 out_max = simd::fmax(a, b); comp.store(outputs[COMPARATOR_OUTPUT].getVoltages(c)); out_min.store(outputs[MIN_OUTPUT].getVoltages(c)); @@ -292,29 +299,29 @@ struct Rampage : Module { } // Lights - if(channels_max==1) { + if (channels_max == 1) { lights[COMPARATOR_LIGHT ].setSmoothBrightness(outputs[COMPARATOR_OUTPUT].getVoltage(), args.sampleTime); - lights[COMPARATOR_LIGHT+1].setBrightness(0.0f); - lights[COMPARATOR_LIGHT+2].setBrightness(0.0f); + lights[COMPARATOR_LIGHT + 1].setBrightness(0.0f); + lights[COMPARATOR_LIGHT + 2].setBrightness(0.0f); lights[MIN_LIGHT ].setSmoothBrightness(outputs[MIN_OUTPUT].getVoltage(), args.sampleTime); - lights[MIN_LIGHT+1].setBrightness(0.0f); - lights[MIN_LIGHT+2].setBrightness(0.0f); + lights[MIN_LIGHT + 1].setBrightness(0.0f); + lights[MIN_LIGHT + 2].setBrightness(0.0f); lights[MAX_LIGHT ].setSmoothBrightness(outputs[MAX_OUTPUT].getVoltage(), args.sampleTime); - lights[MAX_LIGHT+1].setBrightness(0.0f); - lights[MAX_LIGHT+2].setBrightness(0.0f); - } else { + lights[MAX_LIGHT + 1].setBrightness(0.0f); + lights[MAX_LIGHT + 2].setBrightness(0.0f); + } + else { lights[COMPARATOR_LIGHT ].setBrightness(0.0f); - lights[COMPARATOR_LIGHT+1].setBrightness(0.0f); - lights[COMPARATOR_LIGHT+2].setBrightness(10.0f); + lights[COMPARATOR_LIGHT + 1].setBrightness(0.0f); + lights[COMPARATOR_LIGHT + 2].setBrightness(10.0f); lights[MIN_LIGHT ].setBrightness(0.0f); - lights[MIN_LIGHT+1].setBrightness(0.0f); - lights[MIN_LIGHT+2].setBrightness(10.0f); + lights[MIN_LIGHT + 1].setBrightness(0.0f); + lights[MIN_LIGHT + 2].setBrightness(10.0f); lights[MAX_LIGHT ].setBrightness(0.0f); - lights[MAX_LIGHT+1].setBrightness(0.0f); - lights[MAX_LIGHT+2].setBrightness(10.0f); + lights[MAX_LIGHT + 1].setBrightness(0.0f); + lights[MAX_LIGHT + 2].setBrightness(10.0f); } - - } // end process() + } }; @@ -326,9 +333,9 @@ struct RampageWidget : ModuleWidget { setPanel(APP->window->loadSvg(asset::plugin(pluginInstance, "res/Rampage.svg"))); addChild(createWidget(Vec(15, 0))); - addChild(createWidget(Vec(box.size.x-30, 0))); + addChild(createWidget(Vec(box.size.x - 30, 0))); addChild(createWidget(Vec(15, 365))); - addChild(createWidget(Vec(box.size.x-30, 365))); + addChild(createWidget(Vec(box.size.x - 30, 365))); addParam(createParam(Vec(94, 32), module, Rampage::RANGE_A_PARAM)); addParam(createParam(Vec(27, 90), module, Rampage::SHAPE_A_PARAM)); @@ -350,7 +357,7 @@ struct RampageWidget : ModuleWidget { addInput(createInput(Vec(67, 268), module, Rampage::FALL_CV_A_INPUT)); addInput(createInput(Vec(38, 297), module, Rampage::EXP_CV_A_INPUT)); addInput(createInput(Vec(102, 290), module, Rampage::CYCLE_A_INPUT)); - addInput(createInput(Vec(229, 30), module, Rampage::IN_B_INPUT)); + addInput(createInput(Vec(229, 30), module, Rampage::IN_B_INPUT)); addInput(createInput(Vec(192, 37), module, Rampage::TRIGG_B_INPUT)); addInput(createInput(Vec(176, 268), module, Rampage::RISE_CV_B_INPUT)); addInput(createInput(Vec(237, 268), module, Rampage::FALL_CV_B_INPUT)); diff --git a/src/SlewLimiter.cpp b/src/SlewLimiter.cpp index 581d230..e1237c1 100644 --- a/src/SlewLimiter.cpp +++ b/src/SlewLimiter.cpp @@ -44,41 +44,40 @@ struct SlewLimiter : Module { const float slewMin = 0.1; const float slewMax = 10000.f; // Amount of extra slew per voltage difference - const float shapeScale = 1/10.f; + const float shapeScale = 1 / 10.f; const simd::float_4 shape = simd::float_4(params[SHAPE_PARAM].getValue()); const simd::float_4 param_rise = simd::float_4(params[RISE_PARAM].getValue() * 10.f); const simd::float_4 param_fall = simd::float_4(params[FALL_PARAM].getValue() * 10.f); - outputs[OUT_OUTPUT].setChannels(channels); - load_input(inputs[IN_INPUT], in, channels); - load_input(inputs[RISE_INPUT], riseCV, channels); - load_input(inputs[FALL_INPUT], 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; c simd::float_4::zero(); simd::float_4 delta_lt_0 = delta < simd::float_4::zero(); simd::float_4 rateCV; - rateCV = ifelse(delta_gt_0, riseCV[c/4], simd::float_4::zero()); - rateCV = ifelse(delta_lt_0, fallCV[c/4], rateCV) * 0.1f; + rateCV = ifelse(delta_gt_0, riseCV[c / 4], simd::float_4::zero()); + rateCV = ifelse(delta_lt_0, fallCV[c / 4], rateCV) * 0.1f; simd::float_4 pm_one = simd::sgn(delta); simd::float_4 slew = slewMax * simd::pow(simd::float_4(slewMin / slewMax), rateCV); - out[c/4] += slew * simd::crossfade(pm_one, shapeScale*delta, shape) * args.sampleTime; - out[c/4] = ifelse( delta_gt_0 & (out[c/4]>in[c/4]), in[c/4], out[c/4]); - out[c/4] = ifelse( delta_lt_0 & (out[c/4] in[c / 4]), in[c / 4], out[c / 4]); + out[c / 4] = ifelse(delta_lt_0 & (out[c / 4] < in[c / 4]), in[c / 4], out[c / 4]); - out[c/4].store(outputs[OUT_OUTPUT].getVoltages(c)); + out[c / 4].store(outputs[OUT_OUTPUT].getVoltages(c)); } } }; diff --git a/src/SpringReverb.cpp b/src/SpringReverb.cpp index be9c4c0..91fbe0c 100644 --- a/src/SpringReverb.cpp +++ b/src/SpringReverb.cpp @@ -32,15 +32,15 @@ struct SpringReverb : Module { }; enum LightIds { PEAK_LIGHT, - VU1_LIGHT, - NUM_LIGHTS = VU1_LIGHT + 7 + ENUMS(VU1_LIGHTS, 7), + NUM_LIGHTS }; dsp::RealTimeConvolver *convolver = NULL; dsp::SampleRateConverter<1> inputSrc; dsp::SampleRateConverter<1> outputSrc; - dsp::DoubleRingBuffer, 16*BLOCK_SIZE> inputBuffer; - dsp::DoubleRingBuffer, 16*BLOCK_SIZE> outputBuffer; + dsp::DoubleRingBuffer, 16 * BLOCK_SIZE> inputBuffer; + dsp::DoubleRingBuffer, 16 * BLOCK_SIZE> outputBuffer; dsp::RCFilter dryFilter; dsp::PeakFilter vuFilter; @@ -55,7 +55,7 @@ struct SpringReverb : Module { convolver = new dsp::RealTimeConvolver(BLOCK_SIZE); - const float *kernel = (const float*) BINARY_START(src_SpringReverbIR_pcm); + const float *kernel = (const float *) BINARY_START(src_SpringReverbIR_pcm); size_t kernelLen = BINARY_SIZE(src_SpringReverbIR_pcm) / sizeof(float); convolver->setKernel(kernel, kernelLen); } @@ -94,7 +94,7 @@ struct SpringReverb : Module { inputSrc.setRates(args.sampleRate, 48000); int inLen = inputBuffer.size(); int outLen = BLOCK_SIZE; - inputSrc.process(inputBuffer.startData(), &inLen, (dsp::Frame<1>*) input, &outLen); + inputSrc.process(inputBuffer.startData(), &inLen, (dsp::Frame<1> *) input, &outLen); inputBuffer.startIncr(inLen); } @@ -106,7 +106,7 @@ struct SpringReverb : Module { outputSrc.setRates(48000, args.sampleRate); int inLen = BLOCK_SIZE; int outLen = outputBuffer.capacity(); - outputSrc.process((dsp::Frame<1>*) output, &inLen, outputBuffer.endData(), &outLen); + outputSrc.process((dsp::Frame<1> *) output, &inLen, outputBuffer.endData(), &outLen); outputBuffer.endIncr(outLen); } } @@ -126,12 +126,12 @@ struct SpringReverb : Module { vuFilter.setRate(lightRate); vuFilter.process(std::fabs(wet)); lightFilter.setRate(lightRate); - lightFilter.process(std::fabs(dry*50.0)); + lightFilter.process(std::fabs(dry * 50.0)); float vuValue = vuFilter.peak(); for (int i = 0; i < 7; i++) { float light = std::pow(1.413, i) * vuValue / 10.0 - 1.0; - lights[VU1_LIGHT + i].value = clamp(light, 0.0f, 1.0f); + lights[VU1_LIGHTS + i].value = clamp(light, 0.0f, 1.0f); } lights[PEAK_LIGHT].value = lightFilter.peak(); } @@ -145,8 +145,8 @@ struct SpringReverbWidget : ModuleWidget { addChild(createWidget(Vec(15, 0))); addChild(createWidget(Vec(15, 365))); - addChild(createWidget(Vec(15*6, 0))); - addChild(createWidget(Vec(15*6, 365))); + addChild(createWidget(Vec(15 * 6, 0))); + addChild(createWidget(Vec(15 * 6, 365))); addParam(createParam(Vec(22, 29), module, SpringReverb::WET_PARAM)); @@ -165,13 +165,13 @@ struct SpringReverbWidget : ModuleWidget { addOutput(createOutput(Vec(88, 317), module, SpringReverb::WET_OUTPUT)); addChild(createLight>(Vec(55, 269), module, SpringReverb::PEAK_LIGHT)); - addChild(createLight>(Vec(55, 113), module, SpringReverb::VU1_LIGHT + 0)); - addChild(createLight>(Vec(55, 126), module, SpringReverb::VU1_LIGHT + 1)); - addChild(createLight>(Vec(55, 138), module, SpringReverb::VU1_LIGHT + 2)); - addChild(createLight>(Vec(55, 150), module, SpringReverb::VU1_LIGHT + 3)); - addChild(createLight>(Vec(55, 163), module, SpringReverb::VU1_LIGHT + 4)); - addChild(createLight>(Vec(55, 175), module, SpringReverb::VU1_LIGHT + 5)); - addChild(createLight>(Vec(55, 188), module, SpringReverb::VU1_LIGHT + 6)); + addChild(createLight>(Vec(55, 113), module, SpringReverb::VU1_LIGHTS + 0)); + addChild(createLight>(Vec(55, 126), module, SpringReverb::VU1_LIGHTS + 1)); + addChild(createLight>(Vec(55, 138), module, SpringReverb::VU1_LIGHTS + 2)); + addChild(createLight>(Vec(55, 150), module, SpringReverb::VU1_LIGHTS + 3)); + addChild(createLight>(Vec(55, 163), module, SpringReverb::VU1_LIGHTS + 4)); + addChild(createLight>(Vec(55, 175), module, SpringReverb::VU1_LIGHTS + 5)); + addChild(createLight>(Vec(55, 188), module, SpringReverb::VU1_LIGHTS + 6)); } }; diff --git a/src/simd_input.hpp b/src/simd_input.hpp index 2a54be8..4b1265f 100644 --- a/src/simd_input.hpp +++ b/src/simd_input.hpp @@ -3,22 +3,26 @@ #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