From 679d63224a89203280d65e3d8995a931cec519ff Mon Sep 17 00:00:00 2001 From: saker Date: Tue, 3 Jan 2023 18:26:57 -0500 Subject: [PATCH] Resample SampleBuffer only once when loading from SampleClip (#6594) The SampleBuffer's sample rate in SampleClip was altered twice during SampleClip::loadSettings: first when setSampleFile was called, which set the sample rate of the SampleBuffer to the AudioEngine's sample rate (good), and a second time when calling setSampleRate, which set it to the sample rate specified within the project file (bad). This led to the sample rate of the buffer being different than that of the project, resulting in it being pitched incorrectly on playback. --- src/core/SampleClip.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/core/SampleClip.cpp b/src/core/SampleClip.cpp index 1d173d78e..6396d49f3 100644 --- a/src/core/SampleClip.cpp +++ b/src/core/SampleClip.cpp @@ -292,15 +292,15 @@ void SampleClip::loadSettings( const QDomElement & _this ) if( sampleFile().isEmpty() && _this.hasAttribute( "data" ) ) { m_sampleBuffer->loadFromBase64( _this.attribute( "data" ) ); + if (_this.hasAttribute("sample_rate")) + { + m_sampleBuffer->setSampleRate(_this.attribute("sample_rate").toInt()); + } } changeLength( _this.attribute( "len" ).toInt() ); setMuted( _this.attribute( "muted" ).toInt() ); setStartTimeOffset( _this.attribute( "off" ).toInt() ); - if ( _this.hasAttribute( "sample_rate" ) ) { - m_sampleBuffer->setSampleRate( _this.attribute( "sample_rate" ).toInt() ); - } - if( _this.hasAttribute( "color" ) ) { useCustomClipColor( true );