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..3f0ea0fb6 100644 --- a/include/Mixer.h +++ b/include/Mixer.h @@ -57,6 +57,7 @@ class MidiClient; class AudioPort; +const fpp_t MINIMUM_BUFFER_SIZE = 32; const fpp_t DEFAULT_BUFFER_SIZE = 256; const int BYTES_PER_SAMPLE = sizeof( sample_t ); @@ -382,7 +383,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 2766a572a..06e9fabf8 100644 --- a/src/core/Mixer.cpp +++ b/src/core/Mixer.cpp @@ -58,7 +58,7 @@ -Mixer::Mixer() : +Mixer::Mixer( bool renderOnly ) : m_framesPerPeriod( DEFAULT_BUFFER_SIZE ), m_workingBuf( NULL ), m_inputBufferRead( 0 ), @@ -83,37 +83,37 @@ Mixer::Mixer() : clearAudioBuffer( m_inputBuffer[i], m_inputBufferSize[i] ); } - // just rendering? - if( !gui ) - { - 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(); + // determine FIFO size and number of frames per period + int fifoSize = 1; - if( m_framesPerPeriod > DEFAULT_BUFFER_SIZE ) + // if not only rendering (that is, using the GUI), load the buffer + // size from user configuration + if( renderOnly == false ) + { + m_framesPerPeriod = + ( fpp_t ) ConfigManager::inst()-> + value( "mixer", "framesperaudiobuffer" ).toInt(); + + // if the value read from user configuration is not set or + // lower than the minimum allowed, use the default value and + // save it to the configuration + if( m_framesPerPeriod < MINIMUM_BUFFER_SIZE ) { - m_fifo = new fifo( m_framesPerPeriod - / DEFAULT_BUFFER_SIZE ); + ConfigManager::inst()->setValue( "mixer", + "framesperaudiobuffer", + QString::number( DEFAULT_BUFFER_SIZE ) ); + m_framesPerPeriod = DEFAULT_BUFFER_SIZE; } - else + else if( m_framesPerPeriod > DEFAULT_BUFFER_SIZE ) { - m_fifo = new fifo( 1 ); + fifoSize = m_framesPerPeriod / DEFAULT_BUFFER_SIZE; + m_framesPerPeriod = DEFAULT_BUFFER_SIZE; } } - 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 +}