From 18b6f20c29e771193d477656cea3fd45fbda0d01 Mon Sep 17 00:00:00 2001 From: M374LX Date: Wed, 5 Aug 2015 20:42:10 -0300 Subject: [PATCH 1/4] 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 +} From c73edc5d940bf3b6323499f20acdebd3650dc5d0 Mon Sep 17 00:00:00 2001 From: Alexandre Almeida Date: Wed, 5 Aug 2015 20:50:10 -0300 Subject: [PATCH 2/4] Adjust coding conventions --- src/core/Mixer.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/Mixer.cpp b/src/core/Mixer.cpp index 10cd093c1..51d8e2666 100644 --- a/src/core/Mixer.cpp +++ b/src/core/Mixer.cpp @@ -85,13 +85,13 @@ Mixer::Mixer( bool renderOnly ) : // determine FIFO size and number of frames per period int fifoSize = 1; - if (!renderOnly) + if( renderOnly == false ) { m_framesPerPeriod = ( fpp_t ) ConfigManager::inst()-> value( "mixer", "framesperaudiobuffer" ).toInt(); - if (m_framesPerPeriod < 32) + if( m_framesPerPeriod < 32 ) { ConfigManager::inst()->setValue( "mixer", "framesperaudiobuffer", From 2f24d635c34f5aa146a6adf1eb5b39c3447dd57e Mon Sep 17 00:00:00 2001 From: Alexandre Almeida Date: Sun, 9 Aug 2015 11:50:12 -0300 Subject: [PATCH 3/4] Add a MINIMUM_BUFFER_SIZE constant and comments --- src/core/Mixer.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/core/Mixer.cpp b/src/core/Mixer.cpp index 51d8e2666..5e204f08b 100644 --- a/src/core/Mixer.cpp +++ b/src/core/Mixer.cpp @@ -85,22 +85,26 @@ Mixer::Mixer( bool renderOnly ) : // determine FIFO size and number of frames per period int fifoSize = 1; + // 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( m_framesPerPeriod < 32 ) + // 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 ) { ConfigManager::inst()->setValue( "mixer", - "framesperaudiobuffer", + "framesperaudiobuffer", QString::number( DEFAULT_BUFFER_SIZE ) ); m_framesPerPeriod = DEFAULT_BUFFER_SIZE; } - - if( m_framesPerPeriod > DEFAULT_BUFFER_SIZE ) + else if( m_framesPerPeriod > DEFAULT_BUFFER_SIZE ) { fifoSize = m_framesPerPeriod / DEFAULT_BUFFER_SIZE; m_framesPerPeriod = DEFAULT_BUFFER_SIZE; From 6944b520eac45004e606ba1c45c3512577739732 Mon Sep 17 00:00:00 2001 From: Alexandre Almeida Date: Sun, 9 Aug 2015 11:50:24 -0300 Subject: [PATCH 4/4] Add a MINIMUM_BUFFER_SIZE constant --- include/Mixer.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/Mixer.h b/include/Mixer.h index e51c168c5..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 );