commit b9d0ef05a903b1089d2137e7033e7d1758492393
parent 7571721ba5a354e58277f20cd0848803c59d44c6
Author: Matt Demanett <matt@demanett.net>
Date: Sun, 30 Dec 2018 18:56:10 -0500
Replace abs() with fabs(), and swap <math.h> for <cmath>, to avoid floats being truncated on max/linux community builds. I was burned by the C abs() vs C++ abs() difference. This really should fix the longstanding S&H normalled-noise bug. #18
Diffstat:
10 files changed, 17 insertions(+), 15 deletions(-)
diff --git a/src/Clpr.cpp b/src/Clpr.cpp
@@ -36,7 +36,7 @@ void Clpr::step() {
float leftInput = inputs[LEFT_INPUT].value;
float rightInput = inputs[RIGHT_INPUT].value;
- float env = abs(leftInput + rightInput);
+ float env = fabs(leftInput + rightInput);
float detectorDb = amplitudeToDecibels(env / 5.0f);
float compressionDb = _compressor.compressionDb(detectorDb, _thresholdDb, Compressor::maxEffectiveRatio, _softKnee);
_amplifier.setLevel(-compressionDb);
diff --git a/src/Cmp.cpp b/src/Cmp.cpp
@@ -51,7 +51,7 @@ void Cmp::step() {
outputs[LESS_OUTPUT]
);
stepChannel(
- abs(a - b) <= window,
+ fabs(a - b) <= window,
high,
low,
_windowState,
diff --git a/src/EightFO.cpp b/src/EightFO.cpp
@@ -62,9 +62,9 @@ void EightFO::step() {
_sampleSteps = 1;
}
else {
- float sample = abs(params[SAMPLE_PWM_PARAM].value);
+ float sample = fabs(params[SAMPLE_PWM_PARAM].value);
if (inputs[SAMPLE_PWM_INPUT].active) {
- sample *= clamp(abs(inputs[SAMPLE_PWM_INPUT].value) / 5.0f, 0.0f, 1.0f);
+ sample *= clamp(fabs(inputs[SAMPLE_PWM_INPUT].value) / 5.0f, 0.0f, 1.0f);
}
float maxSampleSteps = (_phasor._sampleRate / _phasor._frequency) / 4.0f;
_sampleSteps = clamp((int)(sample * maxSampleSteps), 1, (int)maxSampleSteps);
diff --git a/src/Mix4.cpp b/src/Mix4.cpp
@@ -154,7 +154,7 @@ struct Mix4Widget : ModuleWidget {
id,
0.0,
1.0,
- abs(MixerChannel::minDecibels) / (MixerChannel::maxDecibels - MixerChannel::minDecibels)
+ fabs(MixerChannel::minDecibels) / (MixerChannel::maxDecibels - MixerChannel::minDecibels)
);
dynamic_cast<VUSlider*>(slider)->setVULevel(&rms);
addParam(slider);
diff --git a/src/Mix8.cpp b/src/Mix8.cpp
@@ -222,7 +222,7 @@ struct Mix8Widget : ModuleWidget {
id,
0.0,
1.0,
- abs(MixerChannel::minDecibels) / (MixerChannel::maxDecibels - MixerChannel::minDecibels)
+ fabs(MixerChannel::minDecibels) / (MixerChannel::maxDecibels - MixerChannel::minDecibels)
);
dynamic_cast<VUSlider*>(slider)->setVULevel(&rms);
addParam(slider);
diff --git a/src/Pressor.cpp b/src/Pressor.cpp
@@ -99,7 +99,7 @@ void Pressor::step() {
env = _detectorRMS.next(env);
}
else {
- env = abs(env);
+ env = fabs(env);
}
if (env > _lastEnv) {
env = _attackSL.next(env, _lastEnv);
diff --git a/src/SampleHold.cpp b/src/SampleHold.cpp
@@ -14,7 +14,7 @@ void SampleHold::step() {
_value1 = inputs[IN1_INPUT].value;
}
else {
- _value1 = abs(_noise.next()) * 10.0;
+ _value1 = fabs(_noise.next()) * 10.0;
}
}
outputs[OUT1_OUTPUT].value = _value1;
@@ -24,7 +24,7 @@ void SampleHold::step() {
_value2 = inputs[IN2_INPUT].value;
}
else {
- _value2 = abs(_noise.next()) * 10.0;
+ _value2 = fabs(_noise.next()) * 10.0;
}
}
outputs[OUT2_OUTPUT].value = _value2;
diff --git a/src/VCAmp.cpp b/src/VCAmp.cpp
@@ -56,7 +56,7 @@ struct VCAmpWidget : ModuleWidget {
VCAmp::LEVEL_PARAM,
0.0,
1.0,
- abs(module->minDecibels) / (module->maxDecibels - module->minDecibels)
+ fabs(module->minDecibels) / (module->maxDecibels - module->minDecibels)
);
dynamic_cast<VUSlider*>(slider)->setVULevel(&(module->_rmsLevel));
addParam(slider);
diff --git a/src/bogaudio.hpp b/src/bogaudio.hpp
@@ -3,8 +3,9 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
-#include <math.h>
+
#include <algorithm>
+#include <cmath>
#include "rack.hpp"
diff --git a/src/dsp/signal.cpp b/src/dsp/signal.cpp
@@ -1,6 +1,7 @@
#include <assert.h>
#include <algorithm>
+#include <cmath>
#include "signal.hpp"
@@ -205,7 +206,7 @@ void ShapedSlewLimiter::setParams(float sampleRate, float milliseconds, float sh
float ShapedSlewLimiter::next(float sample) {
float difference = sample - _last;
- float ttg = abs(difference) / range;
+ float ttg = fabs(difference) / range;
if (_time < 0.0001f || ttg < 0.0001f) {
return _last = sample;
}
@@ -218,7 +219,7 @@ float ShapedSlewLimiter::next(float sample) {
if (_shapeExponent != 0.0f) {
ttg = powf(ttg, _inverseShapeExponent);
}
- float y = abs(difference) - ttg * range;
+ float y = fabs(difference) - ttg * range;
if (difference < 0.0f) {
return _last = std::max(_last - y, sample);
}
@@ -385,7 +386,7 @@ void Limiter::setParams(float shape, float knee, float limit, float scale) {
}
float Limiter::next(float sample) {
- float out = abs(sample);
+ float out = fabs(sample);
if (out > _knee) {
out -= _knee;
out /= _scale;
@@ -397,7 +398,7 @@ float Limiter::next(float sample) {
x = _tanhf.value(x * _shape * M_PI) * _normalization;
x = std::min(x, 1.0f);
x *= _limit - _knee;
- out = std::min(abs(sample) - _knee, x);
+ out = std::min(fabs(sample) - _knee, x);
}
else {
out = std::min(out, _limit - _knee);