From d962070d7c84a1c1b0fa3877b41fe5d6365fdf69 Mon Sep 17 00:00:00 2001 From: Lukas W Date: Sat, 30 Sep 2023 00:01:10 +0200 Subject: [PATCH] Fix release fade-out not being applied This fixes to bugs leading to clicks on instrument note-off in most instruments. The first bug was introduced as part of a refactoring done by Vesa [1] and caused each note play handle's last buffer being dropped because the play handles were deleted before being processed in AudioPort. Thanks to @lleroy for pointing this out. [2] The second bug / typo has always been there [3] and was a misplaced parenthesis in Instrument::applyRelease breaking the calculation of the note-off envelope's start frame, sometimes putting it outside of the buffer. Fixes #3086 [1] 857de8d2c829dc688745f41ba8eddbe148a63a20 and related commits [1] https://github.com/LMMS/lmms/issues/3086#issuecomment-519087089 [2] 02433380c629457ad021a1f9c91b8148769c33dc --- src/core/AudioEngine.cpp | 22 +++++++++++----------- src/core/Instrument.cpp | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/core/AudioEngine.cpp b/src/core/AudioEngine.cpp index 29c54647c..df274c188 100644 --- a/src/core/AudioEngine.cpp +++ b/src/core/AudioEngine.cpp @@ -394,6 +394,17 @@ void AudioEngine::renderStageInstruments() AudioEngineWorkerThread::fillJobQueue(m_playHandles); AudioEngineWorkerThread::startAndWaitForJobs(); +} + + + +void AudioEngine::renderStageEffects() +{ + AudioEngineProfiler::Probe profilerProbe(m_profiler, AudioEngineProfiler::DetailType::Effects); + + // STAGE 2: process effects of all instrument- and sampletracks + AudioEngineWorkerThread::fillJobQueue(m_audioPorts); + AudioEngineWorkerThread::startAndWaitForJobs(); // removed all play handles which are done for( PlayHandleList::Iterator it = m_playHandles.begin(); @@ -424,17 +435,6 @@ void AudioEngine::renderStageInstruments() -void AudioEngine::renderStageEffects() -{ - AudioEngineProfiler::Probe profilerProbe(m_profiler, AudioEngineProfiler::DetailType::Effects); - - // STAGE 2: process effects of all instrument- and sampletracks - AudioEngineWorkerThread::fillJobQueue(m_audioPorts); - AudioEngineWorkerThread::startAndWaitForJobs(); -} - - - void AudioEngine::renderStageMix() { AudioEngineProfiler::Probe profilerProbe(m_profiler, AudioEngineProfiler::DetailType::Mixing); diff --git a/src/core/Instrument.cpp b/src/core/Instrument.cpp index b715bcac0..fd729e3ab 100644 --- a/src/core/Instrument.cpp +++ b/src/core/Instrument.cpp @@ -186,7 +186,7 @@ void Instrument::applyRelease( sampleFrame * buf, const NotePlayHandle * _n ) { for( fpp_t f = (fpp_t)( ( fl > desiredReleaseFrames() ) ? (std::max(fpp - desiredReleaseFrames(), 0) + - fl % fpp) : 0); f < frames; ++f) + fl) % fpp : 0); f < frames; ++f) { const float fac = (float)( fl-f-1 ) / desiredReleaseFrames();