From 51a850074ead00987f1e691f6a4f283c7093bb20 Mon Sep 17 00:00:00 2001 From: Paul Walker Date: Fri, 3 Mar 2023 16:02:04 -0500 Subject: [PATCH] FX Mode handles block mod buffers better In the event we are in non-latent mode and our buffer is not a multiple of block size, then 1: reset the inputs and outputs 2: Enter latent mode 3: set latency and 4: inform the host of a latency change Addresses #6638 but some testing before we close it would be super. --- src/surge-fx/SurgeFXProcessor.cpp | 14 ++++++++++++++ src/surge-fx/SurgeFXProcessor.h | 1 + 2 files changed, 15 insertions(+) diff --git a/src/surge-fx/SurgeFXProcessor.cpp b/src/surge-fx/SurgeFXProcessor.cpp index 6a83f20bf77..cc1d980da5c 100644 --- a/src/surge-fx/SurgeFXProcessor.cpp +++ b/src/surge-fx/SurgeFXProcessor.cpp @@ -186,6 +186,20 @@ void SurgefxAudioProcessor::processBlock(juce::AudioBuffer &buffer, resetFxParams(true); } + auto sampl = buffer.getNumSamples(); + if (nonLatentBlockMode && ((sampl & ~(BLOCK_SIZE-1)) != sampl)) + { + nonLatentBlockMode = false; + input_position = 0; + output_position = 0; + memset(output_buffer, 0, sizeof(output_buffer)); + memset(input_buffer, 0, sizeof(input_buffer)); + memset(sidechain_buffer, 0, sizeof(sidechain_buffer)); + + setLatencySamples(BLOCK_SIZE); + updateHostDisplay(ChangeDetails().withLatencyChanged(true)); + } + auto mainInput = getBusBuffer(buffer, true, 0); int inChanL = 0; diff --git a/src/surge-fx/SurgeFXProcessor.h b/src/surge-fx/SurgeFXProcessor.h index 4bd30af66a4..cd9dab69662 100644 --- a/src/surge-fx/SurgeFXProcessor.h +++ b/src/surge-fx/SurgeFXProcessor.h @@ -38,6 +38,7 @@ class SurgefxAudioProcessor : public juce::AudioProcessor, int output_position{-1}; bool nonLatentBlockMode{true}; + //============================================================================== void prepareToPlay(double sampleRate, int samplesPerBlock) override; void releaseResources() override;