diff --git a/src/context/applets/analyzer/plugin/AnalyzerWorker.h b/src/context/applets/analyzer/plugin/AnalyzerWorker.h --- a/src/context/applets/analyzer/plugin/AnalyzerWorker.h +++ b/src/context/applets/analyzer/plugin/AnalyzerWorker.h @@ -50,7 +50,7 @@ public: const static int PROCESSING_INTERVAL = 5; // Interval between new data lookups - const static int DATA_BUFFER_SIZE = 7; // Higher values increase latency, lower values increase risk of missing frames + const static int DATA_BUFFER_SIZE = 8; // Higher values increase latency, lower values increase risk of missing frames Worker(); ~Worker(); diff --git a/src/context/applets/analyzer/plugin/AnalyzerWorker.cpp b/src/context/applets/analyzer/plugin/AnalyzerWorker.cpp --- a/src/context/applets/analyzer/plugin/AnalyzerWorker.cpp +++ b/src/context/applets/analyzer/plugin/AnalyzerWorker.cpp @@ -66,12 +66,6 @@ if( newData.isEmpty() || newData[Phonon::AudioDataOutput::LeftChannel].size() != newDataSize ) return; - if( m_size < newDataSize ) - { - debug() << "Data size mismatch in analyzer!"; - return; - } - m_rawInMutex.lock(); for( int x = 0; x < newDataSize; x++ ) @@ -89,19 +83,16 @@ m_rawIn.last() /= ( 1 << 15 ); // Scale to [0, 1] } - while( m_rawIn.size() > (int)m_size + DATA_BUFFER_SIZE * newDataSize ) - m_rawIn.removeFirst(); - m_rawInMutex.unlock(); } void Analyzer::Worker::processData() { int timeElapsed = m_lastUpdate.elapsed(); // Delay if processing is too fast - if( timeElapsed < m_expectedDataTime ) - QThread::currentThread()->msleep( m_expectedDataTime - timeElapsed ); + if( timeElapsed < m_expectedDataTime - 1 ) + QThread::currentThread()->msleep( m_expectedDataTime - timeElapsed - 1 ); applyWindowFunction(); } @@ -118,6 +109,9 @@ const int newDataSize = EngineController::DATAOUTPUT_DATA_SIZE; + while( m_rawIn.size() > (int)m_size + DATA_BUFFER_SIZE * newDataSize ) + m_rawIn.removeFirst(); + // Apply window function for( uint i = 0; i < m_size; i++ ) { diff --git a/src/context/applets/analyzer/plugin/BlockRenderer.h b/src/context/applets/analyzer/plugin/BlockRenderer.h --- a/src/context/applets/analyzer/plugin/BlockRenderer.h +++ b/src/context/applets/analyzer/plugin/BlockRenderer.h @@ -59,25 +59,22 @@ // Draw the background p.drawPixmap(QRect(QPoint(0, 0), framebufferObject()->size()), m_backgroundPixmap); - - const int frameHeight = framebufferObject()->height(); - for( uint x = 0; x < (uint)m_store.size(); ++x ) { // Draw fade bars for( const auto &fadebar : m_fadebars.at(x) ) { if( fadebar.intensity > 0 ) { const uint offset = fadebar.intensity; - const int fadeHeight = frameHeight - fadebar.y * (BLOCK_HEIGHT + 1); + const int fadeHeight = fadebar.y * (BLOCK_HEIGHT + 1); if( fadeHeight > 0 ) p.drawPixmap(x * ( m_columnWidth + 1 ), 0, m_fadeBarsPixmaps.value(offset), 0, 0, m_columnWidth, fadeHeight); } } // Draw bars - const int height = frameHeight - m_store.at(x) * (BLOCK_HEIGHT + 1); + const int height = m_store.at(x) * (BLOCK_HEIGHT + 1); if (height > 0) p.drawPixmap(x * (m_columnWidth + 1), 0, m_barPixmap, 0, 0, m_columnWidth, height); diff --git a/src/context/applets/analyzer/plugin/BlockWorker.cpp b/src/context/applets/analyzer/plugin/BlockWorker.cpp --- a/src/context/applets/analyzer/plugin/BlockWorker.cpp +++ b/src/context/applets/analyzer/plugin/BlockWorker.cpp @@ -32,13 +32,11 @@ , m_refreshTime( 16 ) , m_showFadebars( showFadebars ) { - m_yscale.resize( m_rows + 1 ); - const double PRE = 1, PRO = 1; //PRE and PRO allow us to restrict the range somewhat + m_yscale.resize( m_rows ); + const double PRO = 1; //PRO allows us to restrict the range somewhat for( int z = 0; z < m_rows; ++z ) - m_yscale[z] = 1 - ( log10( PRE + z ) / log10( PRE + m_rows + PRO ) ); - - m_yscale[m_rows] = 0; + m_yscale[z] = 1 - log10( m_rows - z ) / log10( m_rows + PRO ); m_store.resize( columns ); m_fadebars.resize( columns ); @@ -55,12 +53,11 @@ m_rows = rows; m_yscale.resize( m_rows + 1 ); - const double PRE = 1, PRO = 1; //PRE and PRO allow us to restrict the range somewhat + const double PRO = 1; //PRO allows us to restrict the range somewhat for( int z = 0; z < m_rows; ++z ) - m_yscale[z] = 1 - ( log10( PRE + z ) / log10( PRE + m_rows + PRO ) ); + m_yscale[z] = 1 - log10( m_rows - z ) / log10( m_rows + PRO ); - m_yscale[m_rows] = 0; m_mutex.unlock(); } @@ -77,7 +74,7 @@ int timeElapsed = m_lastUpdate.elapsed(); // only analyze if screen is fast enough - if( timeElapsed < m_refreshTime ) + if( timeElapsed < m_refreshTime - 1 ) QThread::currentThread()->msleep( m_refreshTime - timeElapsed - 1 ); const auto scopeData = scope(); @@ -98,7 +95,7 @@ { // determine y int y = 0; - while( y < m_yscale.size() && scopeData.at(x) < m_yscale.at(y) ) + while( y < m_yscale.size() && scopeData.at(x) > m_yscale.at(y) ) y++; auto &fadebars = m_fadebars[x]; @@ -116,13 +113,13 @@ for( auto &fadebar : fadebars ) fadebar.intensity -= fadeStep; - if( ( double )y > store ) + if( ( double )y < store ) { // add new fadebar at old column height if( m_showFadebars ) fadebars << Fadebar( store, BlockAnalyzer::FADE_SIZE ); - store = qMin( store + step, double( y ) ); + store = qMax( store - step, double( y ) ); } else store = y;