Skip to content

Commit

Permalink
A bit more spike mitigation in Tone King and RONN
Browse files Browse the repository at this point in the history
  • Loading branch information
jatinchowdhury18 committed Mar 14, 2022
1 parent fb512f5 commit 64f794e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/processors/drive/RONN.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 10 additions & 5 deletions src/processors/drive/king_of_tone/KingOfToneDrive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,17 @@ void KingOfToneDrive::prepare (double sampleRate, int samplesPerBlock)
dcBlocker.prepare (sampleRate, samplesPerBlock);

prevMode = (int) *modeParam;
prevNumChannels = 2;

preBuffer.setSize (2, samplesPerBlock);
doPreBuffering();
}

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);
Expand All @@ -144,16 +146,17 @@ void KingOfToneDrive::doPreBuffering()

void KingOfToneDrive::processAudio (AudioBuffer<float>& 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)
Expand Down Expand Up @@ -197,7 +200,9 @@ void KingOfToneDrive::processAudio (AudioBuffer<float>& buffer)
FloatVectorOperations::multiply (x, Decibels::decibelsToGain (makeupGainDB), numSamples);
}
else
{
FloatVectorOperations::multiply (x, Decibels::decibelsToGain (-12.0f), numSamples);
}
}

dcBlocker.processAudio (buffer);
Expand Down
1 change: 1 addition & 0 deletions src/processors/drive/king_of_tone/KingOfToneDrive.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class KingOfToneDrive : public BaseProcessor

SmoothedValue<float> driveParamSmooth[2];
int prevMode = 0;
int prevNumChannels = 0;

float fs = 48000.0f;
chowdsp::FirstOrderHPF<float> inputFilter[2];
Expand Down

0 comments on commit 64f794e

Please sign in to comment.