BogaudioModules

BogaudioModules for VCV Rack
Log | Files | Refs | README | LICENSE

commit 3ec7f22bd727f95c5c33ce6670288c401b9881c5
parent d246972fe9bde35058ee854fc15aa5977c7194b0
Author: Matt Demanett <matt@demanett.net>
Date:   Sun, 19 Nov 2017 16:27:37 -0500

Work-in-progress Noise module.

Diffstat:
Ares/Noise-src.svg | 0
Ares/Noise.svg | 0
Msrc/BogaudioModules.cpp | 1+
Msrc/BogaudioModules.hpp | 4++++
Asrc/Noise.cpp | 71+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/dsp/dsp.hpp | 66++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
6 files changed, 142 insertions(+), 0 deletions(-)

diff --git a/res/Noise-src.svg b/res/Noise-src.svg Binary files differ. diff --git a/res/Noise.svg b/res/Noise.svg Binary files differ. diff --git a/src/BogaudioModules.cpp b/src/BogaudioModules.cpp @@ -17,4 +17,5 @@ void init(rack::Plugin *p) { p->addModel(createModel<OffsetWidget>("Bogaudio", "Bogaudio-Offset", "Offset", ATTENUATOR_TAG, UTILITY_TAG)); p->addModel(createModel<SampleHoldWidget>("Bogaudio", "Bogaudio-SampleHold", "S&H", SAMPLE_AND_HOLD_TAG, DUAL_TAG, UTILITY_TAG)); p->addModel(createModel<ManualWidget>("Bogaudio", "Bogaudio-Manual", "Manual", UTILITY_TAG)); + // p->addModel(createModel<NoiseWidget>("Bogaudio", "Bogaudio-Noise", "Noise", NOISE_TAG, UTILITY_TAG)); } diff --git a/src/BogaudioModules.hpp b/src/BogaudioModules.hpp @@ -32,6 +32,10 @@ struct ManualWidget : ModuleWidget { ManualWidget(); }; +struct NoiseWidget : ModuleWidget { + NoiseWidget(); +}; + struct Knob29 : RoundKnob { Knob29() { diff --git a/src/Noise.cpp b/src/Noise.cpp @@ -0,0 +1,71 @@ + +#include "BogaudioModules.hpp" +#include "dsp/dsp.hpp" + +struct Noise : Module { + enum ParamsIds { + NUM_PARAMS + }; + + enum InputsIds { + NUM_INPUTS + }; + + enum OutputsIds { + WHITE_OUTPUT, + PINK_OUTPUT, + GAUSS_OUTPUT, + NUM_OUTPUTS + }; + + enum LightsIds { + NUM_LIGHTS + }; + + bogaudio::dsp::WhiteNoiseGenerator _white; + bogaudio::dsp::PinkNoiseGenerator _pink; + bogaudio::dsp::GaussianNoiseGenerator _gauss; + + Noise() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) {} + + virtual void step() override; +}; + +void Noise::step() { + if (outputs[WHITE_OUTPUT].active) { + outputs[WHITE_OUTPUT].value = _white.next() * 10.0; + } + if (outputs[PINK_OUTPUT].active) { + outputs[PINK_OUTPUT].value = _pink.next() * 10.0; + } + if (outputs[GAUSS_OUTPUT].active) { + outputs[GAUSS_OUTPUT].value = _gauss.next(); + } +} + + +NoiseWidget::NoiseWidget() { + Noise *module = new Noise(); + setModule(module); + box.size = Vec(RACK_GRID_WIDTH * 3, RACK_GRID_HEIGHT); + + { + SVGPanel *panel = new SVGPanel(); + panel->box.size = box.size; + panel->setBackground(SVG::load(assetPlugin(plugin, "res/Noise.svg"))); + addChild(panel); + } + + addChild(createScrew<ScrewSilver>(Vec(0, 0))); + addChild(createScrew<ScrewSilver>(Vec(box.size.x - 15, 365))); + + // generated by svg_widgets.rb + auto whiteOutputPosition = Vec(10.5, 34.0); + auto pinkOutputPosition = Vec(10.5, 75.0); + auto gaussOutputPosition = Vec(10.5, 144.0); + // end generated by svg_widgets.rb + + addOutput(createOutput<PJ301MPort>(whiteOutputPosition, module, Noise::WHITE_OUTPUT)); + addOutput(createOutput<PJ301MPort>(pinkOutputPosition, module, Noise::PINK_OUTPUT)); + addOutput(createOutput<PJ301MPort>(gaussOutputPosition, module, Noise::GAUSS_OUTPUT)); +} diff --git a/src/dsp/dsp.hpp b/src/dsp/dsp.hpp @@ -0,0 +1,66 @@ + +#include "rack.hpp" + +namespace bogaudio { +namespace dsp { + +struct Generator { + Generator() {} + virtual ~Generator() {} + + virtual float next() = 0; +}; + +struct NoiseGenerator : Generator { + NoiseGenerator() {} +}; + +struct WhiteNoiseGenerator : NoiseGenerator { + WhiteNoiseGenerator() {} + + virtual float next() { + return rack::randomf(); + } +}; + +struct PinkNoiseGenerator : NoiseGenerator { + static const int _n = 7; + uint64_t _g; + uint64_t _gs[_n]; + uint32_t _count; + uint64_t _sum; + + PinkNoiseGenerator() { + _sum = _g = rack::randomu64(); + for (int i = 0; i < _n; ++i) { + _sum += _gs[i] = rack::randomu64(); + } + _count = rack::randomu32(); + } + + virtual float next() { + // See: http://www.firstpr.com.au/dsp/pink-noise/ + _sum -= _g; + _sum += _g = rack::randomu64(); + for (int i = 0, bit = 1; i < _n; ++i, bit <<= 1) { + if (_count & bit) { + _sum -= _gs[i]; + _sum += _gs[i] = rack::randomu64(); + break; + } + } + ++_count; + return (_sum >> (64 - 24)) / powf(2, 24); + } +}; + +struct GaussianNoiseGenerator : NoiseGenerator { + GaussianNoiseGenerator() {} + + virtual float next() { + return rack::randomNormal(); + } +}; + +} // namespace dsp +} // namespace bogaudio