BogaudioModules

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

commit 01067e68b21938cdc0e35486e850131f853a1069
parent 8828129f2e4802e8c2ad7eea817193e629f71c2e
Author: Matt Demanett <matt@demanett.net>
Date:   Wed, 21 Mar 2018 21:55:41 -0400

Fix saturation.

Diffstat:
Msrc/Test.cpp | 3+++
Msrc/Test.hpp | 4++--
Msrc/dsp/oscillator.cpp | 7++-----
Msrc/dsp/oscillator.hpp | 4+++-
4 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/src/Test.cpp b/src/Test.cpp @@ -67,6 +67,9 @@ void Test::step() { #elif SATSAW float saturation = params[PARAM2_PARAM].value * 10.0f; + if (inputs[CV2_INPUT].active) { + saturation *= clamp(inputs[CV2_INPUT].value / 10.0f, 0.0f, 1.0f); + } _saw.setSampleRate(engineGetSampleRate()); _saw.setFrequency(oscillatorPitch()); _saw.setSaturation(saturation); diff --git a/src/Test.hpp b/src/Test.hpp @@ -4,12 +4,12 @@ extern Model* modelTest; -#define LPF 1 +// #define LPF 1 // #define LPFNOISE 1 // #define SINE 1 // #define SQUARE 1 // #define SAW 1 -// #define SATSAW 1 +#define SATSAW 1 // #define TRIANGLE 1 // #define SINEBANK 1 // #define OVERSAMPLING 1 diff --git a/src/dsp/oscillator.cpp b/src/dsp/oscillator.cpp @@ -102,12 +102,9 @@ void SaturatingSawOscillator::setSaturation(float saturation) { float SaturatingSawOscillator::_nextForPhase(float phase) { float sample = SawOscillator::_nextForPhase(phase); if (_saturation >= 0.1f) { - // FIXME: amplitudes, tanh approximation or table. - sample /= _amplitude; - sample = tanhf(sample * _saturation * M_PI) * _saturationNormalization; - sample *= _amplitude; + sample = tanhf(-sample * _saturation * M_PI) * _saturationNormalization; } - return sample; + return _amplitude2 * sample; } diff --git a/src/dsp/oscillator.hpp b/src/dsp/oscillator.hpp @@ -160,15 +160,17 @@ struct SawOscillator : Phasor { struct SaturatingSawOscillator : SawOscillator { float _saturation; float _saturationNormalization; + float _amplitude2; SaturatingSawOscillator( float sampleRate, float frequency, float amplitude = 1.0f ) - : SawOscillator(sampleRate, frequency, amplitude) + : SawOscillator(sampleRate, frequency) , _saturation(0.0f) , _saturationNormalization(1.0f) + , _amplitude2(amplitude) { }