From a1b9d9db8802e87f140d9a175f92ff519faaf4c7 Mon Sep 17 00:00:00 2001 From: Roman Pudashkin Date: Fri, 13 Sep 2024 08:43:08 +0300 Subject: [PATCH] fixed an audio glitch at the first note in exported mp3 file Update the max samples per block for all sequences (rather than in each process call) --- src/framework/vst/internal/synth/vstsynthesiser.cpp | 4 ++++ src/framework/vst/internal/vstaudioclient.cpp | 9 +++++++-- src/framework/vst/internal/vstaudioclient.h | 6 ++++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/framework/vst/internal/synth/vstsynthesiser.cpp b/src/framework/vst/internal/synth/vstsynthesiser.cpp index 9f8cada193a60..0b65bb1378c82 100644 --- a/src/framework/vst/internal/synth/vstsynthesiser.cpp +++ b/src/framework/vst/internal/synth/vstsynthesiser.cpp @@ -199,6 +199,10 @@ samples_t VstSynthesiser::process(float* buffer, samples_t samplesPerChannel) return 0; } + if (samplesPerChannel > m_vstAudioClient->maxSamplesPerBlock()) { + m_vstAudioClient->setMaxSamplesPerBlock(samplesPerChannel); + } + const msecs_t nextMsecs = samplesToMsecs(samplesPerChannel, m_sampleRate); const VstSequencer::EventSequenceMap sequences = m_sequencer.movePlaybackForward(nextMsecs); samples_t sampleOffset = 0; diff --git a/src/framework/vst/internal/vstaudioclient.cpp b/src/framework/vst/internal/vstaudioclient.cpp index 4220720170ec4..c486c9a90cc35 100644 --- a/src/framework/vst/internal/vstaudioclient.cpp +++ b/src/framework/vst/internal/vstaudioclient.cpp @@ -210,13 +210,18 @@ void VstAudioClient::allNotesOff() m_playingParams.clear(); } -void VstAudioClient::setMaxSamplesPerBlock(unsigned int samples) +samples_t VstAudioClient::maxSamplesPerBlock() const +{ + return m_samplesInfo.maxSamplesPerBlock; +} + +void VstAudioClient::setMaxSamplesPerBlock(samples_t samples) { if (m_samplesInfo.maxSamplesPerBlock == samples) { return; } - m_processData.numSamples = samples; + m_processData.numSamples = static_cast(samples); m_samplesInfo.maxSamplesPerBlock = samples; m_needUnprepareProcessData = true; diff --git a/src/framework/vst/internal/vstaudioclient.h b/src/framework/vst/internal/vstaudioclient.h index a2f04747dfab1..b63b711f319ec 100644 --- a/src/framework/vst/internal/vstaudioclient.h +++ b/src/framework/vst/internal/vstaudioclient.h @@ -47,7 +47,9 @@ class VstAudioClient void flush(); void allNotesOff(); - void setMaxSamplesPerBlock(unsigned int samples); + audio::samples_t maxSamplesPerBlock() const; + void setMaxSamplesPerBlock(audio::samples_t samples); + void setSampleRate(unsigned int sampleRate); ParamsMapping paramsMapping(const std::set& controllers) const; @@ -55,7 +57,7 @@ class VstAudioClient private: struct SamplesInfo { unsigned int sampleRate = 0; - unsigned int maxSamplesPerBlock = 0; + audio::samples_t maxSamplesPerBlock = 0; bool isValid() {