From ddd9ad94a4f25c03d4834c55b89075e8e1ac0e2c Mon Sep 17 00:00:00 2001 From: hemmer <915048+hemmer@users.noreply.github.com> Date: Fri, 20 Aug 2021 07:43:36 +0100 Subject: [PATCH] Make STMix polyphonic * remove clipping from Morphader (according to voltage saturation part of voltage standard) --- plugin.json | 3 +- res/STMix.svg | 14 +++---- src/Morphader.cpp | 5 ++- src/STMix.cpp | 99 +++++++++++++++++++++++++++++++++-------------- 4 files changed, 81 insertions(+), 40 deletions(-) diff --git a/plugin.json b/plugin.json index 97627b9..aac5c89 100644 --- a/plugin.json +++ b/plugin.json @@ -200,7 +200,8 @@ "tags": [ "Hardware clone", "Mixer", - "Stereo" + "Stereo", + "Polyphonic" ] } ] diff --git a/res/STMix.svg b/res/STMix.svg index 74bd338..52ac16d 100644 --- a/res/STMix.svg +++ b/res/STMix.svg @@ -25,9 +25,9 @@ inkscape:pageshadow="2" inkscape:zoom="3.959798" inkscape:cx="95.397589" - inkscape:cy="410.81889" + inkscape:cy="380.51432" inkscape:document-units="mm" - inkscape:current-layer="components" + inkscape:current-layer="background" inkscape:document-rotation="0" showgrid="false" inkscape:window-width="2560" @@ -96,7 +96,7 @@ inkscape:export-filename="/home/diego/Escritorio/tirar kick all" inkscape:label="Layer 1" id="g73679" - transform="matrix(0.22493746,0,0,0.22493746,-41.377444,5.1830576)" + transform="matrix(0.22493746,0,0,0.22493746,-39.998259,5.1830576)" style="display:inline"> @@ -548,7 +548,7 @@ inkscape:groupmode="layer" id="components" inkscape:label="components" - style="display:inline"> + style="display:none"> (0.f, c); + const float_4 in_right = inputs[RIGHT_INPUT + i].getNormalPolyVoltageSimd(in_left, c); - const float in_left = inputs[LEFT_INPUT + i].getNormalVoltage(0.f); - const float in_right = inputs[RIGHT_INPUT + i].getNormalVoltage(in_left); - const float gain = (i < numMixerChannels) ? params[GAIN_PARAM + i].getValue() : 1.f; + const float gain = (i < numMixerChannels) ? params[GAIN_PARAM + i].getValue() : 1.f; - out[0] += in_left * gain; - out[1] += in_right * gain; + out_left[c / 4] += in_left * gain; + out_right[c / 4] += in_right * gain; + } } - outputs[LEFT_OUTPUT].setVoltage(out[0]); - outputs[RIGHT_OUTPUT].setVoltage(out[1]); + outputs[LEFT_OUTPUT].setChannels(numActivePolyphonyEngines); + outputs[RIGHT_OUTPUT].setChannels(numActivePolyphonyEngines); - lights[LEFT_LED].setSmoothBrightness(outputs[LEFT_OUTPUT].getVoltage() / 5.f, args.sampleTime); - lights[RIGHT_LED].setSmoothBrightness(outputs[RIGHT_OUTPUT].getVoltage() / 5.f, args.sampleTime); + for (int c = 0; c < numActivePolyphonyEngines; c += 4) { + outputs[LEFT_OUTPUT].setVoltageSimd(out_left[c / 4], c); + outputs[RIGHT_OUTPUT].setVoltageSimd(out_right[c / 4], c); + } + + if (numActivePolyphonyEngines == 1) { + lights[LEFT_LED + 0].setSmoothBrightness(outputs[LEFT_OUTPUT].getVoltage() / 5.f, args.sampleTime); + lights[RIGHT_LED + 0].setSmoothBrightness(outputs[RIGHT_OUTPUT].getVoltage() / 5.f, args.sampleTime); + lights[LEFT_LED + 1].setBrightness(0.f); + lights[RIGHT_LED + 1].setBrightness(0.f); + lights[LEFT_LED + 2].setBrightness(0.f); + lights[RIGHT_LED + 2].setBrightness(0.f); + } + else { + lights[LEFT_LED + 0].setBrightness(0.f); + lights[RIGHT_LED + 0].setBrightness(0.f); + lights[LEFT_LED + 1].setBrightness(0.f); + lights[RIGHT_LED + 1].setBrightness(0.f); + + float b_left = 0.f; + float b_right = 0.f; + for (int c = 0; c < numActivePolyphonyEngines; c++) { + b_left += std::pow(out_left[c / 4][c % 4], 2); + b_right += std::pow(out_right[c / 4][c % 4], 2); + } + b_left = std::sqrt(b_left) / 5.f; + b_right = std::sqrt(b_right) / 5.f; + lights[LEFT_LED + 2].setSmoothBrightness(b_left, args.sampleTime); + lights[RIGHT_LED + 2].setSmoothBrightness(b_right, args.sampleTime); + } } }; @@ -65,28 +104,28 @@ struct STMixWidget : ModuleWidget { addChild(createWidget(Vec(RACK_GRID_WIDTH, 0))); addChild(createWidget(Vec(RACK_GRID_WIDTH, RACK_GRID_HEIGHT - RACK_GRID_WIDTH))); - addParam(createParamCentered(mm2px(Vec(20.892, 18.141)), module, STMix::GAIN_PARAM + 0)); - addParam(createParamCentered(mm2px(Vec(20.982, 41.451)), module, STMix::GAIN_PARAM + 1)); - addParam(createParamCentered(mm2px(Vec(20.927, 64.318)), module, STMix::GAIN_PARAM + 2)); + addParam(createParamCentered(mm2px(Vec(21.0, 18.141)), module, STMix::GAIN_PARAM + 0)); + addParam(createParamCentered(mm2px(Vec(21.0, 41.451)), module, STMix::GAIN_PARAM + 1)); + addParam(createParamCentered(mm2px(Vec(21.0, 64.318)), module, STMix::GAIN_PARAM + 2)); addParam(createParamCentered(mm2px(Vec(21.0, 87.124)), module, STMix::GAIN_PARAM + 3)); - addInput(createInputCentered(mm2px(Vec(6.308, 13.108)), module, STMix::LEFT_INPUT + 0)); - addInput(createInputCentered(mm2px(Vec(6.308, 36.175)), module, STMix::LEFT_INPUT + 1)); + addInput(createInputCentered(mm2px(Vec(6.3, 13.108)), module, STMix::LEFT_INPUT + 0)); + addInput(createInputCentered(mm2px(Vec(6.3, 36.175)), module, STMix::LEFT_INPUT + 1)); addInput(createInputCentered(mm2px(Vec(6.3, 59.243)), module, STMix::LEFT_INPUT + 2)); - addInput(createInputCentered(mm2px(Vec(6.279, 82.311)), module, STMix::LEFT_INPUT + 3)); - addInput(createInputCentered(mm2px(Vec(6.287, 105.378)), module, STMix::LEFT_INPUT + 4)); + addInput(createInputCentered(mm2px(Vec(6.3, 82.311)), module, STMix::LEFT_INPUT + 3)); + addInput(createInputCentered(mm2px(Vec(6.3, 105.378)), module, STMix::LEFT_INPUT + 4)); - addInput(createInputCentered(mm2px(Vec(6.308, 23.108)), module, STMix::RIGHT_INPUT + 0)); - addInput(createInputCentered(mm2px(Vec(6.313, 46.354)), module, STMix::RIGHT_INPUT + 1)); - addInput(createInputCentered(mm2px(Vec(6.308, 69.237)), module, STMix::RIGHT_INPUT + 2)); - addInput(createInputCentered(mm2px(Vec(6.308, 92.132)), module, STMix::RIGHT_INPUT + 3)); - addInput(createInputCentered(mm2px(Vec(6.279, 115.379)), module, STMix::RIGHT_INPUT + 4)); + addInput(createInputCentered(mm2px(Vec(6.3, 23.108)), module, STMix::RIGHT_INPUT + 0)); + addInput(createInputCentered(mm2px(Vec(6.3, 46.354)), module, STMix::RIGHT_INPUT + 1)); + addInput(createInputCentered(mm2px(Vec(6.3, 69.237)), module, STMix::RIGHT_INPUT + 2)); + addInput(createInputCentered(mm2px(Vec(6.3, 92.132)), module, STMix::RIGHT_INPUT + 3)); + addInput(createInputCentered(mm2px(Vec(6.3, 115.379)), module, STMix::RIGHT_INPUT + 4)); - addOutput(createOutputCentered(mm2px(Vec(23.813, 105.422)), module, STMix::LEFT_OUTPUT)); - addOutput(createOutputCentered(mm2px(Vec(23.792, 115.392)), module, STMix::RIGHT_OUTPUT)); + addOutput(createOutputCentered(mm2px(Vec(23.8, 105.422)), module, STMix::LEFT_OUTPUT)); + addOutput(createOutputCentered(mm2px(Vec(23.8, 115.392)), module, STMix::RIGHT_OUTPUT)); - addChild(createLightCentered>(mm2px(Vec(16.8, 103.0)), module, STMix::LEFT_LED)); - addChild(createLightCentered>(mm2px(Vec(16.8, 113.0)), module, STMix::RIGHT_LED)); + addChild(createLightCentered>(mm2px(Vec(16.8, 103.0)), module, STMix::LEFT_LED)); + addChild(createLightCentered>(mm2px(Vec(16.8, 113.0)), module, STMix::RIGHT_LED)); } };