From 64f794ee44bb601fd05de9d214620c2a8c0058d3 Mon Sep 17 00:00:00 2001 From: Jatin Chowdhury Date: Mon, 14 Mar 2022 21:45:23 +0000 Subject: [PATCH] A bit more spike mitigation in Tone King and RONN --- src/processors/drive/RONN.cpp | 2 ++ .../drive/king_of_tone/KingOfToneDrive.cpp | 15 ++++++++++----- .../drive/king_of_tone/KingOfToneDrive.h | 1 + 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/processors/drive/RONN.cpp b/src/processors/drive/RONN.cpp index 4c2ed48c..20fef28c 100644 --- a/src/processors/drive/RONN.cpp +++ b/src/processors/drive/RONN.cpp @@ -179,6 +179,8 @@ void RONN::reloadModel (int randomSeed) if (std::isnan (makeupGain) || std::isinf (makeupGain)) reloadModel (randomSeed + 1); + + makeupGain = jmax (makeupGain, 30.0f); } void RONN::prepare (double sampleRate, int samplesPerBlock) diff --git a/src/processors/drive/king_of_tone/KingOfToneDrive.cpp b/src/processors/drive/king_of_tone/KingOfToneDrive.cpp index 2a071419..a42c9725 100644 --- a/src/processors/drive/king_of_tone/KingOfToneDrive.cpp +++ b/src/processors/drive/king_of_tone/KingOfToneDrive.cpp @@ -127,6 +127,7 @@ void KingOfToneDrive::prepare (double sampleRate, int samplesPerBlock) dcBlocker.prepare (sampleRate, samplesPerBlock); prevMode = (int) *modeParam; + prevNumChannels = 2; preBuffer.setSize (2, samplesPerBlock); doPreBuffering(); @@ -134,8 +135,9 @@ void KingOfToneDrive::prepare (double sampleRate, int samplesPerBlock) void KingOfToneDrive::doPreBuffering() { + preBuffer.setSize (prevNumChannels, preBuffer.getNumSamples(), false, false, true); const auto numSamples = preBuffer.getNumSamples(); - for (int i = 0; i < int (fs * 0.5f); i += numSamples) + for (int i = 0; i < (int) fs; i += numSamples) { preBuffer.clear(); processAudio (preBuffer); @@ -144,16 +146,17 @@ void KingOfToneDrive::doPreBuffering() void KingOfToneDrive::processAudio (AudioBuffer& buffer) { + const auto numSamples = (int) buffer.getNumSamples(); + const auto numChannels = (int) buffer.getNumChannels(); + const auto currentMode = (int) *modeParam; - if (currentMode != prevMode) + if (currentMode != prevMode || numChannels != prevNumChannels) { prevMode = currentMode; + prevNumChannels = numChannels; doPreBuffering(); } - const auto numSamples = (int) buffer.getNumSamples(); - const auto numChannels = (int) buffer.getNumChannels(); - buffer.applyGain (0.2f); // voltage scaling for (int ch = 0; ch < numChannels; ++ch) @@ -197,7 +200,9 @@ void KingOfToneDrive::processAudio (AudioBuffer& buffer) FloatVectorOperations::multiply (x, Decibels::decibelsToGain (makeupGainDB), numSamples); } else + { FloatVectorOperations::multiply (x, Decibels::decibelsToGain (-12.0f), numSamples); + } } dcBlocker.processAudio (buffer); diff --git a/src/processors/drive/king_of_tone/KingOfToneDrive.h b/src/processors/drive/king_of_tone/KingOfToneDrive.h index d8567cc4..1289275e 100644 --- a/src/processors/drive/king_of_tone/KingOfToneDrive.h +++ b/src/processors/drive/king_of_tone/KingOfToneDrive.h @@ -24,6 +24,7 @@ class KingOfToneDrive : public BaseProcessor SmoothedValue driveParamSmooth[2]; int prevMode = 0; + int prevNumChannels = 0; float fs = 48000.0f; chowdsp::FirstOrderHPF inputFilter[2];