Skip to content

Commit

Permalink
fixed an audio glitch at the first note in exported mp3 file
Browse files Browse the repository at this point in the history
Update the max samples per block for all sequences (rather than in each process call)
  • Loading branch information
RomanPudashkin committed Sep 17, 2024
1 parent 4558ed6 commit 876a90b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/framework/vst/internal/synth/vstsynthesiser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 7 additions & 2 deletions src/framework/vst/internal/vstaudioclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Steinberg::int32>(samples);
m_samplesInfo.maxSamplesPerBlock = samples;
m_needUnprepareProcessData = true;

Expand Down
6 changes: 4 additions & 2 deletions src/framework/vst/internal/vstaudioclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,17 @@ 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<Steinberg::Vst::CtrlNumber>& controllers) const;

private:
struct SamplesInfo {
unsigned int sampleRate = 0;
unsigned int maxSamplesPerBlock = 0;
audio::samples_t maxSamplesPerBlock = 0;

bool isValid()
{
Expand Down

0 comments on commit 876a90b

Please sign in to comment.