From 18b6f20c29e771193d477656cea3fd45fbda0d01 Mon Sep 17 00:00:00 2001 From: M374LX Date: Wed, 5 Aug 2015 20:42:10 -0300 Subject: [PATCH] Fix #1878 --- include/Engine.h | 2 +- include/Mixer.h | 2 +- src/core/Engine.cpp | 4 ++-- src/core/Mixer.cpp | 46 +++++++++++++++++--------------------- src/core/main.cpp | 2 +- src/gui/GuiApplication.cpp | 4 ++-- 6 files changed, 28 insertions(+), 32 deletions(-) diff --git a/include/Engine.h b/include/Engine.h index 96c77912b..b4a404205 100644 --- a/include/Engine.h +++ b/include/Engine.h @@ -46,7 +46,7 @@ class EXPORT Engine : public QObject { Q_OBJECT public: - static void init(); + static void init( bool renderOnly ); static void destroy(); // core diff --git a/include/Mixer.h b/include/Mixer.h index 03a815975..e51c168c5 100644 --- a/include/Mixer.h +++ b/include/Mixer.h @@ -382,7 +382,7 @@ private: } ; - Mixer(); + Mixer( bool renderOnly ); virtual ~Mixer(); void startProcessing( bool _needs_fifo = true ); diff --git a/src/core/Engine.cpp b/src/core/Engine.cpp index ad611bde2..77e168780 100644 --- a/src/core/Engine.cpp +++ b/src/core/Engine.cpp @@ -50,7 +50,7 @@ DummyTrackContainer * Engine::s_dummyTC = NULL; -void Engine::init() +void Engine::init( bool renderOnly ) { Engine *engine = inst(); @@ -60,7 +60,7 @@ void Engine::init() emit engine->initProgress(tr("Initializing data structures")); s_projectJournal = new ProjectJournal; - s_mixer = new Mixer; + s_mixer = new Mixer( renderOnly ); s_song = new Song; s_fxMixer = new FxMixer; s_bbTrackContainer = new BBTrackContainer; diff --git a/src/core/Mixer.cpp b/src/core/Mixer.cpp index fe8443dbc..10cd093c1 100644 --- a/src/core/Mixer.cpp +++ b/src/core/Mixer.cpp @@ -57,7 +57,7 @@ -Mixer::Mixer() : +Mixer::Mixer( bool renderOnly ) : m_framesPerPeriod( DEFAULT_BUFFER_SIZE ), m_workingBuf( NULL ), m_inputBufferRead( 0 ), @@ -82,38 +82,34 @@ Mixer::Mixer() : clearAudioBuffer( m_inputBuffer[i], m_inputBufferSize[i] ); } - // just rendering? - if( !gui ) + // determine FIFO size and number of frames per period + int fifoSize = 1; + + if (!renderOnly) { - m_framesPerPeriod = DEFAULT_BUFFER_SIZE; - m_fifo = new fifo( 1 ); - } - else if( ConfigManager::inst()->value( "mixer", "framesperaudiobuffer" - ).toInt() >= 32 ) - { - m_framesPerPeriod = - (fpp_t) ConfigManager::inst()->value( "mixer", - "framesperaudiobuffer" ).toInt(); + m_framesPerPeriod = + ( fpp_t ) ConfigManager::inst()-> + value( "mixer", "framesperaudiobuffer" ).toInt(); + + if (m_framesPerPeriod < 32) + { + ConfigManager::inst()->setValue( "mixer", + "framesperaudiobuffer", + QString::number( DEFAULT_BUFFER_SIZE ) ); + + m_framesPerPeriod = DEFAULT_BUFFER_SIZE; + } if( m_framesPerPeriod > DEFAULT_BUFFER_SIZE ) { - m_fifo = new fifo( m_framesPerPeriod - / DEFAULT_BUFFER_SIZE ); + fifoSize = m_framesPerPeriod / DEFAULT_BUFFER_SIZE; m_framesPerPeriod = DEFAULT_BUFFER_SIZE; } - else - { - m_fifo = new fifo( 1 ); - } - } - else - { - ConfigManager::inst()->setValue( "mixer", - "framesperaudiobuffer", - QString::number( m_framesPerPeriod ) ); - m_fifo = new fifo( 1 ); } + // allocte the FIFO from the determined size + m_fifo = new fifo( fifoSize ); + // now that framesPerPeriod is fixed initialize global BufferManager BufferManager::init( m_framesPerPeriod ); diff --git a/src/core/main.cpp b/src/core/main.cpp index cefac206a..95b1caeb1 100644 --- a/src/core/main.cpp +++ b/src/core/main.cpp @@ -509,7 +509,7 @@ int main( int argc, char * * argv ) else { // we're going to render our song - Engine::init(); + Engine::init( true ); printf( "loading project...\n" ); Engine::getSong()->loadProject( file_to_load ); diff --git a/src/gui/GuiApplication.cpp b/src/gui/GuiApplication.cpp index 32cfbab91..3ae5af326 100644 --- a/src/gui/GuiApplication.cpp +++ b/src/gui/GuiApplication.cpp @@ -90,7 +90,7 @@ GuiApplication::GuiApplication() this, SLOT(displayInitProgress(const QString&))); // Init central engine which handles all components of LMMS - Engine::init(); + Engine::init(false); s_instance = this; @@ -188,4 +188,4 @@ void GuiApplication::childDestroyed(QObject *obj) { m_controllerRackView = nullptr; } -} \ No newline at end of file +}