From 8acb44b202579f6940fd8bcfb7ea3ff9836f1a06 Mon Sep 17 00:00:00 2001 From: Frank <91616163+softhack007@users.noreply.github.com> Date: Sun, 14 Aug 2022 14:38:27 +0200 Subject: [PATCH] small improvement for limitSampleDynamics support the case when only attackTime XOR decayTime is defined --- usermods/audioreactive/audio_reactive.h | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/usermods/audioreactive/audio_reactive.h b/usermods/audioreactive/audio_reactive.h index c48501090..4cb0f6923 100644 --- a/usermods/audioreactive/audio_reactive.h +++ b/usermods/audioreactive/audio_reactive.h @@ -683,21 +683,24 @@ class AudioReactive : public Usermod { // effects: Gravimeter, Gravcenter, Gravcentric, Noisefire, Plasmoid, Freqpixels, Freqwave, Gravfreq, (2D Swirl, 2D Waverly) void limitSampleDynamics(void) { #ifdef SOUND_DYNAMICS_LIMITER - const float bigChange = 196; // just a representative number - a large, expected sample value + const float bigChange = 196; // just a representative number - a large, expected sample value static unsigned long last_time = 0; static float last_volumeSmth = 0.0f; - if ((attackTime > 0) && (decayTime > 0)) { // only change volume if user has defined attack>0 and decay>0 - long delta_time = millis() - last_time; - delta_time = constrain(delta_time , 1, 1000); // below 1ms -> 1ms; above 1sec -> sily lil hick-up - float maxAttack = bigChange * float(delta_time) / float(attackTime); - float maxDecay = - bigChange * float(delta_time) / float(decayTime); + long delta_time = millis() - last_time; + delta_time = constrain(delta_time , 1, 1000); // below 1ms -> 1ms; above 1sec -> sily lil hick-up + float deltaSample = volumeSmth - last_volumeSmth; - float deltaSample = volumeSmth - last_volumeSmth; + if (attackTime > 0) { // user has defined attack time > 0 + float maxAttack = bigChange * float(delta_time) / float(attackTime); if (deltaSample > maxAttack) deltaSample = maxAttack; - if (deltaSample < maxDecay) deltaSample = maxDecay; - volumeSmth = last_volumeSmth + deltaSample; } + if (decayTime > 0) { // user has defined decay time > 0 + float maxDecay = - bigChange * float(delta_time) / float(decayTime); + if (deltaSample < maxDecay) deltaSample = maxDecay; + } + + volumeSmth = last_volumeSmth + deltaSample; last_volumeSmth = volumeSmth; last_time = millis();