From 5e8f220b9c9801029465d7579c039c15cce28266 Mon Sep 17 00:00:00 2001 From: regulus79 <117475203+regulus79@users.noreply.github.com> Date: Tue, 23 Dec 2025 14:59:17 -0500 Subject: [PATCH] Fix AudioFileProcessor Wrong Beat Length Depending on Sample Rate (#8176) Fixes #8138 Essentially, when playing beat notes in the pattern editor, technically, they have an internal length of 0. However, when the NotePlayHandle is created and recieves that value of 0, it realizes it's supposed to be a beat note, so it asks the instrument track what the default length of note should be. For most instruments, that defaults to whatever the length of the envelope is (no matter whether the envelope is enabled or not. Is that a good system? I don't know.) However, AudioFileProcessor does it custom and returns the length of its sample in frames. However, the frame count it returned did not take into account that the sample rate of lmms could be different from the sample rate of the sample. This PR fixes that issue by multiplying by the correct sample rate ratio. --- plugins/AudioFileProcessor/AudioFileProcessor.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/AudioFileProcessor/AudioFileProcessor.cpp b/plugins/AudioFileProcessor/AudioFileProcessor.cpp index 4892ee839..e78cdfdf4 100644 --- a/plugins/AudioFileProcessor/AudioFileProcessor.cpp +++ b/plugins/AudioFileProcessor/AudioFileProcessor.cpp @@ -288,13 +288,14 @@ auto AudioFileProcessor::beatLen(NotePlayHandle* note) const -> f_cnt_t const auto freqFactor = baseFreq / note->frequency() * Engine::audioEngine()->outputSampleRate() / Engine::audioEngine()->baseSampleRate(); + const auto sampleRateRatio = static_cast(Engine::audioEngine()->outputSampleRate()) / m_sample.sampleRate(); const auto startFrame = m_nextPlayStartPoint >= static_cast(m_sample.endFrame()) ? m_sample.startFrame() : m_nextPlayStartPoint; const auto duration = m_sample.endFrame() - startFrame; - return static_cast(std::floor(duration * freqFactor)); + return static_cast(std::floor(duration * freqFactor * sampleRateRatio)); }