diff --git a/include/AudioEngine.h b/include/AudioEngine.h index ab09544c7cb..91b467041ea 100644 --- a/include/AudioEngine.h +++ b/include/AudioEngine.h @@ -33,6 +33,7 @@ #include #include +#include "AudioDevice.h" #include "lmms_basics.h" #include "SampleFrame.h" #include "LocklessList.h" @@ -230,9 +231,20 @@ class LMMS_EXPORT AudioEngine : public QObject } - sample_rate_t baseSampleRate() const; - sample_rate_t outputSampleRate() const; - sample_rate_t inputSampleRate() const; + sample_rate_t baseSampleRate() const { return m_baseSampleRate; } + + + sample_rate_t outputSampleRate() const + { + return m_audioDev != nullptr ? m_audioDev->sampleRate() : m_baseSampleRate; + } + + + sample_rate_t inputSampleRate() const + { + return m_audioDev != nullptr ? m_audioDev->sampleRate() : m_baseSampleRate; + } + inline float masterGain() const { @@ -325,6 +337,7 @@ class LMMS_EXPORT AudioEngine : public QObject SampleFrame* m_inputBuffer[2]; f_cnt_t m_inputBufferFrames[2]; f_cnt_t m_inputBufferSize[2]; + sample_rate_t m_baseSampleRate; int m_inputBufferRead; int m_inputBufferWrite; diff --git a/src/core/AudioEngine.cpp b/src/core/AudioEngine.cpp index 184611cfba6..5206fa3d05f 100644 --- a/src/core/AudioEngine.cpp +++ b/src/core/AudioEngine.cpp @@ -75,6 +75,7 @@ AudioEngine::AudioEngine( bool renderOnly ) : m_framesPerPeriod(std::clamp(ConfigManager::inst() ->value("audioengine", "framesperaudiobuffer", QString::number(AudioEngine::DefaultBufferSize)) .toInt(), AudioEngine::MinimumBufferSize, AudioEngine::MaximumBufferSize)), + m_baseSampleRate(std::max(ConfigManager::inst()->value("audioengine", "samplerate").toInt(), 44100)), m_inputBufferRead( 0 ), m_inputBufferWrite( 1 ), m_outputBufferRead(nullptr), @@ -180,34 +181,6 @@ void AudioEngine::stopProcessing() -sample_rate_t AudioEngine::baseSampleRate() const -{ - sample_rate_t sr = ConfigManager::inst()->value( "audioengine", "samplerate" ).toInt(); - if( sr < 44100 ) - { - sr = 44100; - } - return sr; -} - - - - -sample_rate_t AudioEngine::outputSampleRate() const -{ - return m_audioDev != nullptr ? m_audioDev->sampleRate() : - baseSampleRate(); -} - - - - -sample_rate_t AudioEngine::inputSampleRate() const -{ - return m_audioDev != nullptr ? m_audioDev->sampleRate() : - baseSampleRate(); -} - bool AudioEngine::criticalXRuns() const { return cpuLoad() >= 99 && Engine::getSong()->isExporting() == false;