Skip to content

Commit

Permalink
Reset I/O processor if NaNs are detected in the audio buffer (#340)
Browse files Browse the repository at this point in the history
* Reset I/O processor if NaNs are detected in the audio buffer

* Apply clang-format

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
jatinchowdhury18 and github-actions[bot] authored Jan 2, 2024
1 parent 0916f18 commit 6042929
Show file tree
Hide file tree
Showing 45 changed files with 101 additions and 41 deletions.
5 changes: 3 additions & 2 deletions src/BYOD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace BYODPaths
const String settingsFilePath = "ChowdhuryDSP/BYOD/.plugin_settings.json";
const String logFileSubDir = "ChowdhuryDSP/BYOD/Logs";
const String logFileNameRoot = "BYOD_Log_";
} // namespace
} // namespace BYODPaths

BYOD::BYOD() : chowdsp::PluginBase<BYOD> (&undoManager),
logger ({ .logFileSubDir = BYODPaths::logFileSubDir,
Expand Down Expand Up @@ -83,7 +83,8 @@ void BYOD::processBlock (AudioBuffer<float>& buffer, MidiBuffer& midi)
// real processing here!
procs->processAudio (buffer, midi);

chowdsp::BufferMath::sanitizeBuffer<AudioBuffer<float>, float> (buffer);
if (! chowdsp::BufferMath::sanitizeBuffer<AudioBuffer<float>, float> (buffer))
procs->reset();
}

void BYOD::processBlockBypassed (AudioBuffer<float>& buffer, MidiBuffer&)
Expand Down
2 changes: 1 addition & 1 deletion src/gui/pedalboard/BoardComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ static juce::Point<int> getRandomPosition (const Component& comp)
auto& rand = Random::getSystemRandom();
return b.getCentre() + juce::Point (rand.nextInt ({ -randX, randX }), rand.nextInt ({ -randY, randY }));
}
} // namespace
} // namespace BoardDims

BoardComponent::BoardComponent (ProcessorChain& procs, chowdsp::HostContextProvider& hostCP)
: Component ("Board"),
Expand Down
2 changes: 1 addition & 1 deletion src/gui/pedalboard/cables/CableViewConnectionHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ static void addConnectionsForProcessor (OwnedArray<Cable>& cables, BaseProcessor
}
}
}
} // namespace
} // namespace CableConnectionMethods

CableViewConnectionHelper::CableViewConnectionHelper (CableView& cv, BoardComponent& boardComp)
: cableView (cv),
Expand Down
2 changes: 1 addition & 1 deletion src/gui/pedalboard/cables/CableViewPortLocationHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ static void getClosestPort (const juce::Point<int>& pos, const ProcessorEditor*
}
}
}
} // namespace
} // namespace CableViewHelperMethods

CableViewPortLocationHelper::CableViewPortLocationHelper (CableView& cv) : cableView (cv),
board (cableView.board),
Expand Down
2 changes: 1 addition & 1 deletion src/gui/toolbar/SettingsButton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace SettingsColours
{
const Colour onColour = Colours::yellow;
const Colour offColour = Colours::white;
} // namespace
} // namespace SettingsColours

SettingsButton::SettingsButton (BYOD& processor, chowdsp::OpenGLHelper* oglHelper) : DrawableButton ("Settings", DrawableButton::ImageFitted),
proc (processor),
Expand Down
2 changes: 1 addition & 1 deletion src/gui/utils/LevelMeterComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace LevelMeterConstants
constexpr auto maxDB = 6.0f;
constexpr auto minDB = -45.0f;
constexpr auto dBRange = maxDB - minDB;
} // namespace
} // namespace LevelMeterConstants

LevelMeterComponent::LevelMeterComponent (const LevelDataType& levelData) : rmsLevels (levelData),
dbLevels ({ LevelMeterConstants::minDB, LevelMeterConstants::minDB }),
Expand Down
1 change: 1 addition & 0 deletions src/headless/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ target_sources(BYOD_headless PRIVATE

tests/AmpIRsSaveLoadTest.cpp
tests/BadModulationTest.cpp
tests/NaNResetTest.cpp
tests/ParameterSmoothTest.cpp
tests/PreBufferTest.cpp
tests/PresetsTest.cpp
Expand Down
40 changes: 40 additions & 0 deletions src/headless/tests/NaNResetTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include "UnitTests.h"

class NaNResetTest : public UnitTest
{
public:
NaNResetTest() : UnitTest ("NaN Reset Test")
{
}

void runTest() override
{
beginTest ("NaN Reset Test");

static constexpr int blockSize = 512;

BYOD byod;
byod.prepareToPlay (48000.0, blockSize);

MidiBuffer midi;
AudioBuffer<float> buffer { 2, blockSize };

{
for (auto [_, data] : chowdsp::buffer_iters::channels (buffer))
std::fill (data.begin(), data.end(), std::numeric_limits<float>::quiet_NaN());
byod.processBlock (buffer, midi);
const auto mag = chowdsp::BufferMath::getMagnitude (buffer);
expectEquals (mag, 0.0f);
}

{
for (auto [_, data] : chowdsp::buffer_iters::channels (buffer))
std::fill (data.begin(), data.end(), 1.0f);
byod.processBlock (buffer, midi);
const auto mag = chowdsp::BufferMath::getMagnitude (buffer);
expectGreaterOrEqual (mag, 1.0f);
}
}
};

static NaNResetTest nanResetTest;
11 changes: 11 additions & 0 deletions src/processors/chain/ChainIOProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,17 @@ void ChainIOProcessor::prepare (double sampleRate, int samplesPerBlock)
isPrepared = true;
}

void ChainIOProcessor::reset() noexcept
{
oversampling.reset();

inGain.reset();
outGain.reset();

ioBuffer.clear();
dryWetMixer.reset();
}

int ChainIOProcessor::getOversamplingFactor() const
{
if (! isPrepared)
Expand Down
1 change: 1 addition & 0 deletions src/processors/chain/ChainIOProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class ChainIOProcessor

static void createParameters (Parameters& params);
void prepare (double sampleRate, int samplesPerBlock);
void reset() noexcept;

int getOversamplingFactor() const;
dsp::AudioBlock<float> processAudioInput (const AudioBuffer<float>& buffer, bool& sampleRateChanged);
Expand Down
7 changes: 6 additions & 1 deletion src/processors/chain/ProcessorChain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ static const MidiBuffer& getMidiBufferToUse (const MidiBuffer& hostMidiBuffer, M

return internalMidiBuffer;
}
} // namespace
} // namespace ChainHelperFuncs

ProcessorChain::ProcessorChain (ProcessorStore& store,
AudioProcessorValueTreeState& vts,
Expand Down Expand Up @@ -89,6 +89,11 @@ void ProcessorChain::prepare (double sampleRate, int samplesPerBlock)
initializeProcessors();
}

void ProcessorChain::reset() noexcept
{
ioProcessor.reset();
}

void ProcessorChain::runProcessor (BaseProcessor* proc, AudioBuffer<float>& buffer, bool& outProcessed)
{
TRACE_DSP();
Expand Down
1 change: 1 addition & 0 deletions src/processors/chain/ProcessorChain.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class ProcessorChain : private AudioProcessorValueTreeState::Listener
static void createParameters (Parameters& params);
void prepare (double sampleRate, int samplesPerBlock);
void processAudio (AudioBuffer<float>& buffer, const MidiBuffer& hostMidiBuffer);
void reset() noexcept;

auto& getProcessors() { return procs; }
const auto& getProcessors() const { return procs; }
Expand Down
2 changes: 1 addition & 1 deletion src/processors/chain/ProcessorChainStateHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ static String getProcessorName (const String& tag)
{
return tag.replaceCharacter ('_', ' ');
}
} // namespace
} // namespace ChainStateHelperFuncs

ProcessorChainStateHelper::ProcessorChainStateHelper (ProcessorChain& thisChain, chowdsp::DeferredAction& deferredAction)
: chain (thisChain),
Expand Down
2 changes: 1 addition & 1 deletion src/processors/drive/BlondeDrive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ void processDrive (double* left, double* right, const double* A, xsimd::batch<do
right[n] = stereoVec[1];
}
}
} // namespace
} // namespace BlondeDriveTags

BlondeDrive::BlondeDrive (UndoManager* um) : BaseProcessor ("Blonde Drive", createParameterLayout(), um)
{
Expand Down
2 changes: 1 addition & 1 deletion src/processors/drive/GuitarMLAmp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const String conditionTag = "condition";
const String sampleRateCorrFilterTag = "sample_rate_corr_filter";
const String customModelTag = "custom_model";
constexpr std::string_view modelNameTag = "byod_guitarml_model_name";
} // namespace
} // namespace RONNTags

GuitarMLAmp::GuitarMLAmp (UndoManager* um) : BaseProcessor ("GuitarML", createParameterLayout(), um)
{
Expand Down
2 changes: 1 addition & 1 deletion src/processors/drive/RONN.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ Vec3 createRandomVec3<GlorotUniform> (std::default_random_engine& generator, Glo
glorot.initialise (-limit, limit);
return createRandomVec3 (generator, *glorot.dist, size1, size2, size3);
}
} // namespace
} // namespace RONNRandom

RONN::RONN (UndoManager* um) : BaseProcessor ("RONN", createParameterLayout(), um)
{
Expand Down
2 changes: 1 addition & 1 deletion src/processors/drive/Warp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ constexpr float calcQ (float gainDB)
constexpr float adaptiveQCoeffs[] = { -7.75358366e-09f, 5.21182270e-23f, 2.70080663e-06f, -3.04753193e-20f, -3.29851878e-04f, 1.89860352e-18f, 2.59076683e-02f, -4.77485061e-17f, 3.78416236e-01f };
return chowdsp::Polynomials::estrin<8> (adaptiveQCoeffs, gainDB);
}
} // namespace
} // namespace WarpFuncs

Warp::Warp (UndoManager* um) : BaseProcessor ("Warp", createParameterLayout(), um)
{
Expand Down
2 changes: 1 addition & 1 deletion src/processors/drive/junior_b/JuniorB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace JuniorBTags
const String driveTag = "juniorb_drive";
const String blendTag = "juniorb_blend";
const String stagesTag = "juniorb_nstages";
} // namespace
} // namespace JuniorBTags

JuniorB::JuniorB (UndoManager* um) : BaseProcessor ("Junior B", createParameterLayout(), um)
{
Expand Down
2 changes: 1 addition & 1 deletion src/processors/drive/king_of_tone/KingOfToneDrive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void calcDriveStageBypassedCoefs (FilterType& filter, float fs, const KingOfTone
Transform<float, 1>::bilinear (b_z, a_z, b_s, a_s, 2.0f * fs);
filter.setCoefs (b_z, a_z);
}
} // namespace
} // namespace ToneKingCoeffs

KingOfToneDrive::KingOfToneDrive (UndoManager* um) : BaseProcessor ("Tone King", createParameterLayout(), um)
{
Expand Down
2 changes: 1 addition & 1 deletion src/processors/drive/muff_clipper/MuffClipper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ static float harmParamToCutoffHz (float harmParam)

const auto sustainRange = ParameterHelpers::createNormalisableRange (0.4f, 2.0f, 1.0f);
const auto levelRange = ParameterHelpers::createNormalisableRange (-60.0f, 0.0f, -9.0f);
} // namespace
} // namespace MuffClipperRanges

MuffClipper::MuffClipper (UndoManager* um) : BaseProcessor ("Muff Clipper", createParameterLayout(), um)
{
Expand Down
2 changes: 1 addition & 1 deletion src/processors/drive/mxr_distortion/MXRDistortion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ static float paramSkew (float paramVal)
}

const auto levelSkew = ParameterHelpers::createNormalisableRange (-60.0f, 0.0f, -12.0f);
} // namespace
} // namespace MXRDistortionParams

MXRDistortion::MXRDistortion (UndoManager* um) : BaseProcessor ("Distortion Plus", createParameterLayout(), um)
{
Expand Down
2 changes: 1 addition & 1 deletion src/processors/drive/neural_utils/RNNAccelerated.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#pragma GCC diagnostic ignored "-Wshorten-64-to-32"
#pragma GCC diagnostic ignored "-Wsign-conversion"
#pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant"
#if !defined(__has_warning) || __has_warning("-Wunsafe-buffer-usage")
#if ! defined(__has_warning) || __has_warning("-Wunsafe-buffer-usage")
#pragma GCC diagnostic ignored "-Wunsafe-buffer-usage"
#endif
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/processors/modulation/Chorus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace ChorusTags
{
const String delayTypeTag = "delay_type";
} // namespace
} // namespace ChorusTags

Chorus::Chorus (UndoManager* um) : BaseProcessor (
"Chorus",
Expand Down
2 changes: 1 addition & 1 deletion src/processors/modulation/Flanger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace FlangerTags
{
const String delayTypeTag = "delay_type";
} // namespace
} // namespace FlangerTags

Flanger::Flanger (UndoManager* um) : BaseProcessor (
"Flanger",
Expand Down
2 changes: 1 addition & 1 deletion src/processors/modulation/MIDIModulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace MidiModulatorTags
{
const String bipolarTag = "bipolar";
const String midiMapTag = "midi_map_cc";
} // namespace
} // namespace MidiModulatorTags

MidiModulator::MidiModulator (UndoManager* um)
: BaseProcessor (
Expand Down
2 changes: 1 addition & 1 deletion src/processors/modulation/Panner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const String modDepthTag = "mod_depth";
const String modRateHzTag = "mod_rate";
const String panModeTag = "pan_mode";
const String stereoModeTag = "stereo_mode";
} // namespace
} // namespace PannerTags

Panner::Panner (UndoManager* um) : BaseProcessor (
"Panner",
Expand Down
2 changes: 1 addition & 1 deletion src/processors/modulation/ParamModulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace ParamModulatorTags
const String unipolarModTag = "unipolar_mod";
const String bipolarModTag = "bipolar_mod";
const String bipolarModeTag = "bipolar_mode";
} // namespace
} // namespace ParamModulatorTags

ParamModulator::ParamModulator (UndoManager* um)
: BaseProcessor (
Expand Down
2 changes: 1 addition & 1 deletion src/processors/other/EnvelopeFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const auto speedRange = ParameterHelpers::createNormalisableRange (5.0f, 100.0f,
const String senseTag = "sense";
const String directControlTag = "direct_control";
const String freqModTag = "freq_mod";
} // namespace
} // namespace EnvelopeFilterTags

EnvelopeFilter::EnvelopeFilter (UndoManager* um) : BaseProcessor (
"Envelope Filter",
Expand Down
2 changes: 1 addition & 1 deletion src/processors/other/LevelDetective.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const auto powerColour = Colours::gold.darker (0.1f);
const auto backgroundColour = Colours::teal.darker (0.1f);
const String attackTag = "attack";
const String releaseTag = "release";
} // namespace
} // namespace LevelDetectiveTags

LevelDetective::LevelDetective (UndoManager* um) : BaseProcessor (
"Level Detective",
Expand Down
2 changes: 1 addition & 1 deletion src/processors/other/ShimmerReverb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const String shiftTag = "shift";
const String sizeTag = "size";
const String feedbackTag = "feedback";
const String mixTag = "mix";
} // namespace
} // namespace ShimmerReverbTags

void ShimmerReverb::ShimmerFDNConfig::prepare (double sampleRate)
{
Expand Down
2 changes: 1 addition & 1 deletion src/processors/other/SmoothReverb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ constexpr auto preDelay2LengthMs = 77.0f;

constexpr auto preDelay1CutoffHz = 3000.0f;
constexpr auto preDelay2CutoffHz = 2000.0f;
} // namespace
} // namespace SmoothReverbTags

SmoothReverb::SmoothReverb (UndoManager* um) : BaseProcessor ("Smooth Reverb", createParameterLayout(), um)
{
Expand Down
2 changes: 1 addition & 1 deletion src/processors/other/cry_baby/CryBaby.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const String directControlTag = "direct_control";

// this module needs some extra oversampling to help the Newton-Raphson solver converge
constexpr int oversampleRatio = 2;
} // namespace
} // namespace CryBabyTags

CryBaby::CryBaby (UndoManager* um)
: BaseProcessor (
Expand Down
2 changes: 1 addition & 1 deletion src/processors/other/cry_baby/CryBabyNDK.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ constexpr auto BetaF_Q2 = 1430.0;
constexpr auto AlphaF_Q2 = (1.0 + BetaF_Q2) / BetaF_Q2;
constexpr auto BetaR_Q2 = 4.0;
// END USER ENTRIES
} // namespace
} // namespace CryBabyComponents

void CryBabyNDK::reset (T fs)
{
Expand Down
2 changes: 1 addition & 1 deletion src/processors/other/spring_reverb/SpringReverb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ constexpr double preDelayMs = 2.0;

constexpr float smallShakeSeconds = 0.0005f;
constexpr float largeShakeSeconds = 0.001f;
} // namespace
} // namespace SpringReverbConstants

SpringReverb::SpringReverb (double sampleRate)
: delay { static_cast<int> (0.099 * sampleRate * 1.5) },
Expand Down
2 changes: 1 addition & 1 deletion src/processors/tone/BigMuffTone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ static auto createComponentSets()
BigMuffTone::Components { .name = "Custom", .R8 = 39.0e3f, .C8 = 10.0e-9f, .C9 = 4.0e-9f, .R5_1 = 7.7e3f, .R5_2 = 28.6e3f, .RT = 100.0e3f },
};
}
} // namespace
} // namespace BigMuffToneComponents

BigMuffTone::BigMuffTone (UndoManager* um) : BaseProcessor ("Muff Tone", createParameterLayout(), um),
componentSets (BigMuffToneComponents::createComponentSets())
Expand Down
2 changes: 1 addition & 1 deletion src/processors/tone/BlondeTone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace BlondeToneTags
const String bassTag = "bass";
const String midTag = "mid";
const String trebleTag = "treble";
} // namespace
} // namespace BlondeToneTags

BlondeTone::BlondeTone (UndoManager* um) : BaseProcessor ("Blonde Tone", createParameterLayout(), um)
{
Expand Down
2 changes: 1 addition & 1 deletion src/processors/tone/GraphicEQ.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ constexpr float calcQ (float gainDB)
constexpr float adaptiveQCoeffs[] = { -7.75358366e-09f, 5.21182270e-23f, 2.70080663e-06f, -3.04753193e-20f, -3.29851878e-04f, 1.89860352e-18f, 2.59076683e-02f, -4.77485061e-17f, 3.78416236e-01f };
return chowdsp::Polynomials::estrin<8> (adaptiveQCoeffs, gainDB);
}
} // namespace
} // namespace GraphicEQParams

GraphicEQ::GraphicEQ (UndoManager* um) : BaseProcessor ("Graphic EQ", createParameterLayout(), um)
{
Expand Down
Loading

0 comments on commit 6042929

Please sign in to comment.