commit 8a5df6f046528c007a4df548447c6f137f83c19f
parent df07cebb46cca7488a0ad528afab427541d09222
Author: Matt Demanett <matt@demanett.net>
Date: Fri, 6 Jul 2018 02:18:38 -0400
AD: attack/decay envelope.
Diffstat:
A | res-src/AD-src.svg | | | 180 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
A | res/AD.svg | | | 0 | |
A | src/AD.cpp | | | 117 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
A | src/AD.hpp | | | 66 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
M | src/bogaudio.cpp | | | 4 | ++++ |
5 files changed, 367 insertions(+), 0 deletions(-)
diff --git a/res-src/AD-src.svg b/res-src/AD-src.svg
@@ -0,0 +1,180 @@
+<svg
+ version="1.1"
+ xmlns="http://www.w3.org/2000/svg"
+ xmlns:xlink="http://www.w3.org/1999/xlink"
+ width="45"
+ height="380"
+ viewBox="0 0 45 380"
+>
+ <style>
+ text {
+ fill: #333;
+ font-family: 'Roboto', sans-serif;
+ font-weight: bold;
+ }
+ text.title {
+ font-family: 'Comfortaa', sans-serif;
+ font-weight: normal;
+ }
+ text.brand {
+ font-family: 'Audiowide', sans-serif;
+ font-weight: bold;
+ }
+ </style>
+
+ <defs>
+ <symbol id="knob" viewBox="0 0 45px 45px">
+ <g transform="translate(22.5 22.5)">
+ <polyline points="-5,0 5,0" stroke-width="1" stroke="#00f" />
+ <polyline points="0,-5 0,5" stroke-width="1" stroke="#00f" />
+ <circle cx="0" cy="0" r="14" stroke-width="1" stroke="#00f" fill="none" />
+ </g>
+ </symbol>
+
+ <symbol id="knobguide" viewBox="0 0 45px 45px">
+ <g transform="translate(22.5 22.5)">
+ <g transform="rotate(-240) translate(17 0)">
+ <g transform="translate(3 0) rotate(240)">
+ <text font-size="6.5pt" transform="translate(-2.8 3.3)">0</text>
+ </g>
+ </g>
+ <g transform="rotate(-172.92) translate(17 0)">
+ <polyline points="0,0 1.5,0" stroke-width="0.3" stroke="#333" />
+ </g>
+ <g transform="rotate(-145.13) translate(17 0)">
+ <g transform="translate(3 0) rotate(145.13)">
+ <text font-size="6.5pt" transform="translate(-2.8 3.3)">1</text>
+ </g>
+ </g>
+ <g transform="rotate(-105.84) translate(17 0)">
+ <polyline points="0,0 3,0" stroke-width="0.3" stroke="#333" />
+ </g>
+ <g transform="rotate(-75.68) translate(17 0)">
+ <polyline points="0,0 3,0" stroke-width="0.3" stroke="#333" />
+ </g>
+ <g transform="rotate(-50.26) translate(17 0)">
+ <polyline points="0,0 3,0" stroke-width="0.3" stroke="#333" />
+ </g>
+ <g transform="rotate(-27.87) translate(17 0)">
+ <g transform="translate(3 0) rotate(27.87)">
+ <text font-size="6.5pt" transform="translate(-2.8 3.3)">5</text>
+ </g>
+ </g>
+ <g transform="rotate(-7.62) translate(17 0)">
+ <polyline points="0,0 3,0" stroke-width="0.3" stroke="#333" />
+ </g>
+ <g transform="rotate(11) translate(17 0)">
+ <polyline points="0,0 3,0" stroke-width="0.3" stroke="#333" />
+ </g>
+ <g transform="rotate(28.33) translate(17 0)">
+ <polyline points="0,0 3,0" stroke-width="0.3" stroke="#333" />
+ </g>
+ <g transform="rotate(44.6) translate(17 0)">
+ <polyline points="0,0 3,0" stroke-width="0.3" stroke="#333" />
+ </g>
+ <g transform="rotate(60) translate(17 0)">
+ <polyline points="0,0 3,0" stroke-width="0.3" stroke="#333" />
+ </g>
+ </g>
+ </symbol>
+
+ <symbol id="input" viewBox="0 0 24px 24px">
+ <g transform="translate(12 12)">
+ <circle cx="0" cy="0" r="5" stroke-width="1" stroke="#0f0" fill="#0f0" />
+ <circle cx="0" cy="0" r="10.5" stroke-width="3" stroke="#0f0" fill="none" />
+ </g>
+ </symbol>
+
+ <symbol id="output" viewBox="0 0 24px 24px">
+ <g transform="translate(12 12)">
+ <circle cx="0" cy="0" r="5" stroke-width="1" stroke="#f00" fill="#f00" />
+ <circle cx="0" cy="0" r="10.5" stroke-width="3" stroke="#f00" fill="none" />
+ </g>
+ </symbol>
+
+ <symbol id="button-small" viewBox="0 0 9px 9px">
+ <g transform="translate(4.5 4.5)">
+ <circle r="4" stroke-width="1" stroke="#00f" fill="#f00" />
+ </g>
+ </symbol>
+
+ <symbol id="light-small" viewBox="0 0 6.4px 6.4px">
+ <rect width="6.4" height="6.4" fill="#0f0" />
+ </symbol>
+
+ <symbol id="light-tiny" viewBox="0 0 1.1px 1.1px">
+ <rect width="3.2" height="3.2" fill="#0f0" />
+ </symbol>
+ </defs>
+
+ <rect width="100%" height="100%" fill="#ddd" />
+ <polyline points="1,1 44,1 44,379 1,379 1,1" stroke="#e4e4e4" stroke-width="0.5" fill="none" />
+ <polyline points="0.5,0.5 44.5,0.5 44.5,379.5 0.5,379.5 0.5,0.5" stroke="#ebebeb" stroke-width="0.8" fill="none" />
+ <polyline points="0,0 45,0 45,380 0,380 0,0" stroke="#f2f2f2" stroke-width="1" fill="none" />
+
+ <!-- <polyline points="22.5,0 22.5,380" stroke-width="0.5" stroke="#0f0" /> -->
+ <!-- <polyline points="5,0 5,380" stroke-width="0.5" stroke="#0f0" /> -->
+ <!-- <polyline points="40,0 40,380" stroke-width="0.5" stroke="#0f0" /> -->
+ <!-- <rect width="45" height="10" fill="#0f0" transform="translate(0 68)" /> -->
+ <!-- <rect width="45" height="10" fill="#0f0" transform="translate(0 127)" /> -->
+ <!-- <rect width="45" height="10" fill="#0f0" transform="translate(0 177)" /> -->
+
+ <g transform="rotate(-90) translate(-376 13)">
+ <text class="title" font-size="7pt" letter-spacing="2.5px">AD</text>
+ <g transform="translate(0 12)">
+ <text class="brand" font-size="7pt" letter-spacing="2px">BGA</text>
+ <rect width="3.0" height="3" fill="#ddd" transform="translate(11.5 -5)" />
+ </g>
+ </g>
+
+ <g transform="translate(0 25)">
+ <text font-size="6pt" letter-spacing="1.5px" transform="translate(3.5 0)">ATTACK</text>
+ <use id="ATTACK_PARAM" xlink:href="#knob" transform="translate(0 0)" />
+ <use xlink:href="#knobguide" transform="translate(0 0)" />
+ <use id="ATTACK_LIGHT" xlink:href="#light-tiny" transform="translate(20.8 40)" />
+ </g>
+
+ <g transform="translate(0 82)">
+ <text font-size="6pt" letter-spacing="2px" transform="translate(6 0)">DECAY</text>
+ <use id="DECAY_PARAM" xlink:href="#knob" transform="translate(0 0)" />
+ <use xlink:href="#knobguide" transform="translate(0 0)" />
+ <use id="DECAY_LIGHT" xlink:href="#light-tiny" transform="translate(20.8 40)" />
+ </g>
+
+ <g transform="translate(2.5 132.5)">
+ <!-- <polyline points="0,3.2 70,3.2" stroke="#0f0" stroke-width="1" fill="none" /> -->
+ <use id="LOOP_PARAM" xlink:href="#button-small" transform="translate(31 -1.3)" />
+ <use id="LOOP_LIGHT" xlink:href="#light-small" transform="translate(0 0)" />
+ <text font-size="6pt" letter-spacing="0.5px" transform="translate(8 6.1)">LOOP</text>
+ <!-- <rect width="90" height="10" fill="#0f0" transform="translate(0 7)" /> -->
+ </g>
+
+ <g transform="translate(2.5 147)">
+ <!-- <polyline points="0,3.2 70,3.2" stroke="#0f0" stroke-width="1" fill="none" /> -->
+ <use id="LINEAR_PARAM" xlink:href="#button-small" transform="translate(31 -1.3)" />
+ <use id="LINEAR_LIGHT" xlink:href="#light-small" transform="translate(0 0)" />
+ <text font-size="6pt" letter-spacing="2px" transform="translate(8 6.1)">LIN</text>
+ <!-- <rect width="90" height="10" fill="#0f0" transform="translate(0 7)" /> -->
+ </g>
+
+ <g transform="translate(0 160.5)">
+ <g transform="translate(5.5 0)">
+ <rect width="34" height="10" fill="#fafafa" transform="translate(0 98)" />
+ <rect width="34" height="108" rx="5" fill="#fafafa" />
+ <use id="TRIGGER_INPUT" xlink:href="#input" transform="translate(5 3)" />
+ <text font-size="5pt" letter-spacing="2px" transform="translate(6.5 35)">TRIG</text>
+ <use id="ATTACK_INPUT" xlink:href="#input" transform="translate(5 38)" />
+ <text font-size="5pt" letter-spacing="1px" transform="translate(2 70)">ATTACK</text>
+ <use id="DECAY_INPUT" xlink:href="#input" transform="translate(5 73)" />
+ <text font-size="5pt" letter-spacing="2px" transform="translate(2.5 105)">DECAY</text>
+ </g>
+ <g transform="translate(5.5 111)">
+ <rect width="34" height="10" fill="#bbb" transform="translate(0 -3)" />
+ <rect width="34" height="70" rx="5" fill="#bbb" />
+ <use id="ENV_OUTPUT" xlink:href="#output" transform="translate(5 0)" />
+ <text font-size="5pt" letter-spacing="2px" transform="translate(8.5 32)">ENV</text>
+ <use id="EOC_OUTPUT" xlink:href="#output" transform="translate(5 35)" />
+ <text font-size="5pt" letter-spacing="2px" transform="translate(8.5 67)">EOC</text>
+ </g>
+ </g>
+</svg>
diff --git a/res/AD.svg b/res/AD.svg
Binary files differ.
diff --git a/src/AD.cpp b/src/AD.cpp
@@ -0,0 +1,117 @@
+
+#include "AD.hpp"
+
+void AD::onReset() {
+ _trigger.reset();
+ _eocPulseGen.process(10.0);
+ _envelope.reset();
+ _modulationStep = modulationSteps;
+ _on = false;
+}
+
+void AD::onSampleRateChange() {
+ float sr = engineGetSampleRate();
+ _envelope.setSampleRate(sr);
+ _attackSL.setParams(sr / (float)modulationSteps);
+ _decaySL.setParams(sr / (float)modulationSteps);
+ _modulationStep = modulationSteps;
+}
+
+void AD::step() {
+ lights[LOOP_LIGHT].value = _loopMode = params[LOOP_PARAM].value > 0.5f;
+ lights[LINEAR_LIGHT].value = _linearMode = params[LINEAR_PARAM].value > 0.5f;
+ if (!(outputs[ENV_OUTPUT].active || outputs[EOC_OUTPUT].active || inputs[TRIGGER_INPUT].active)) {
+ return;
+ }
+
+ ++_modulationStep;
+ if (_modulationStep >= modulationSteps) {
+ _modulationStep = 0;
+
+ float attack = powf(params[ATTACK_PARAM].value, 2.0f);
+ if (inputs[ATTACK_INPUT].active) {
+ attack *= clamp(inputs[ATTACK_INPUT].value / 10.0f, 0.0f, 1.0f);
+ }
+ _envelope.setAttack(_attackSL.next(attack * 10.f));
+
+ float decay = powf(params[DECAY_PARAM].value, 2.0f);
+ if (inputs[DECAY_INPUT].active) {
+ decay *= clamp(inputs[DECAY_INPUT].value / 10.0f, 0.0f, 1.0f);
+ }
+ _envelope.setDecay(_decaySL.next(decay * 10.f));
+
+ _envelope.setLinearShape(_linearMode);
+ }
+
+ _trigger.process(inputs[TRIGGER_INPUT].value);
+ if (!_on && (_trigger.isHigh() || (_loopMode && _envelope.isStage(ADSR::STOPPED_STAGE)))) {
+ _on = true;
+ }
+ _envelope.setGate(_on);
+ outputs[ENV_OUTPUT].value = _envelope.next() * 10.0f;
+ if (_on && _envelope.isStage(ADSR::SUSTAIN_STAGE)) {
+ _envelope.reset();
+ _on = false;
+ _eocPulseGen.trigger(0.001f);
+ }
+ outputs[EOC_OUTPUT].value = _eocPulseGen.process(engineGetSampleTime()) ? 5.0f : 0.0f;
+
+ lights[ATTACK_LIGHT].value = _envelope.isStage(ADSR::ATTACK_STAGE);
+ lights[DECAY_LIGHT].value = _envelope.isStage(ADSR::DECAY_STAGE);
+}
+
+struct ADWidget : ModuleWidget {
+ static constexpr int hp = 3;
+
+ ADWidget(AD* module) : ModuleWidget(module) {
+ box.size = Vec(RACK_GRID_WIDTH * hp, RACK_GRID_HEIGHT);
+
+ {
+ SVGPanel *panel = new SVGPanel();
+ panel->box.size = box.size;
+ panel->setBackground(SVG::load(assetPlugin(plugin, "res/AD.svg")));
+ addChild(panel);
+ }
+
+ addChild(Widget::create<ScrewSilver>(Vec(0, 0)));
+ addChild(Widget::create<ScrewSilver>(Vec(box.size.x - 15, 365)));
+
+ // generated by svg_widgets.rb
+ auto attackParamPosition = Vec(8.0, 33.0);
+ auto decayParamPosition = Vec(8.0, 90.0);
+ auto loopParamPosition = Vec(33.5, 131.2);
+ auto linearParamPosition = Vec(33.5, 145.7);
+
+ auto triggerInputPosition = Vec(10.5, 163.5);
+ auto attackInputPosition = Vec(10.5, 198.5);
+ auto decayInputPosition = Vec(10.5, 233.5);
+
+ auto envOutputPosition = Vec(10.5, 271.5);
+ auto eocOutputPosition = Vec(10.5, 306.5);
+
+ auto attackLightPosition = Vec(20.8, 65.0);
+ auto decayLightPosition = Vec(20.8, 122.0);
+ auto loopLightPosition = Vec(2.5, 132.5);
+ auto linearLightPosition = Vec(2.5, 147.0);
+ // end generated by svg_widgets.rb
+
+ addParam(ParamWidget::create<Knob29>(attackParamPosition, module, AD::ATTACK_PARAM, 0.0, 1.0, 0.12));
+ addParam(ParamWidget::create<Knob29>(decayParamPosition, module, AD::DECAY_PARAM, 0.0, 1.0, 0.31623));
+ addParam(ParamWidget::create<StatefulButton9>(loopParamPosition, module, AD::LOOP_PARAM, 0.0, 1.0, 0.0));
+ addParam(ParamWidget::create<StatefulButton9>(linearParamPosition, module, AD::LINEAR_PARAM, 0.0, 1.0, 0.0));
+
+ addInput(Port::create<Port24>(triggerInputPosition, Port::INPUT, module, AD::TRIGGER_INPUT));
+ addInput(Port::create<Port24>(attackInputPosition, Port::INPUT, module, AD::ATTACK_INPUT));
+ addInput(Port::create<Port24>(decayInputPosition, Port::INPUT, module, AD::DECAY_INPUT));
+
+ addOutput(Port::create<Port24>(envOutputPosition, Port::OUTPUT, module, AD::ENV_OUTPUT));
+ addOutput(Port::create<Port24>(eocOutputPosition, Port::OUTPUT, module, AD::EOC_OUTPUT));
+
+ addChild(ModuleLightWidget::create<TinyLight<GreenLight>>(attackLightPosition, module, AD::ATTACK_LIGHT));
+ addChild(ModuleLightWidget::create<TinyLight<GreenLight>>(decayLightPosition, module, AD::DECAY_LIGHT));
+ addChild(ModuleLightWidget::create<SmallLight<GreenLight>>(loopLightPosition, module, AD::LOOP_LIGHT));
+ addChild(ModuleLightWidget::create<SmallLight<GreenLight>>(linearLightPosition, module, AD::LINEAR_LIGHT));
+ }
+};
+
+Model* modelAD = createModel<AD, ADWidget>("Bogaudio-AD", "AD", "utility envelope", ENVELOPE_GENERATOR_TAG);
diff --git a/src/AD.hpp b/src/AD.hpp
@@ -0,0 +1,66 @@
+#pragma once
+
+#include "bogaudio.hpp"
+#include "dsp/envelope.hpp"
+#include "dsp/signal.hpp"
+
+using namespace bogaudio::dsp;
+
+extern Model* modelAD;
+
+namespace bogaudio {
+
+struct AD : Module {
+ enum ParamsIds {
+ ATTACK_PARAM,
+ DECAY_PARAM,
+ LOOP_PARAM,
+ LINEAR_PARAM,
+ NUM_PARAMS
+ };
+
+ enum InputsIds {
+ TRIGGER_INPUT,
+ ATTACK_INPUT,
+ DECAY_INPUT,
+ NUM_INPUTS
+ };
+
+ enum OutputsIds {
+ ENV_OUTPUT,
+ EOC_OUTPUT,
+ NUM_OUTPUTS
+ };
+
+ enum LightsIds {
+ ATTACK_LIGHT,
+ DECAY_LIGHT,
+ LOOP_LIGHT,
+ LINEAR_LIGHT,
+ NUM_LIGHTS
+ };
+
+ const int modulationSteps = 100;
+ int _modulationStep = 0;
+ bool _loopMode = false;
+ bool _linearMode = false;
+ SchmittTrigger _trigger;
+ PulseGenerator _eocPulseGen;
+ bool _on = false;
+ ADSR _envelope;
+ SlewLimiter _attackSL;
+ SlewLimiter _decaySL;
+
+ AD() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) {
+ onReset();
+ onSampleRateChange();
+ _envelope.setSustain(0.0f);
+ _envelope.setRelease(0.0f);
+ }
+
+ void onReset() override;
+ void onSampleRateChange() override;
+ void step() override;
+};
+
+} // namespace bogaudio
diff --git a/src/bogaudio.cpp b/src/bogaudio.cpp
@@ -1,6 +1,7 @@
#include "bogaudio.hpp"
+#include "AD.hpp"
#include "ADSR.hpp"
#include "Additator.hpp"
#include "Analyzer.hpp"
@@ -69,6 +70,9 @@ void init(rack::Plugin *p) {
p->addModel(modelDGate);
p->addModel(modelShaper);
p->addModel(modelShaperPlus);
+#ifdef EXPERIMENTAL
+ p->addModel(modelAD);
+#endif
p->addModel(modelADSR);
p->addModel(modelFollow);