From 8d3082233657ba7a82d5c53d7d8d17a53795cd0d Mon Sep 17 00:00:00 2001 From: "Simon A. Eugster" Date: Tue, 14 Dec 2010 12:59:06 +0000 Subject: [PATCH] Audio Spectrum: Increased performance by 25 % by directly painting lines instead of single pixels svn path=/trunk/kdenlive/; revision=5174 --- src/audioscopes/audiospectrum.cpp | 37 ++++++++++++++++++++++++++++--- src/audioscopes/audiospectrum.h | 8 +++++++ 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/src/audioscopes/audiospectrum.cpp b/src/audioscopes/audiospectrum.cpp index ef8b44be..a92f6f5d 100644 --- a/src/audioscopes/audiospectrum.cpp +++ b/src/audioscopes/audiospectrum.cpp @@ -20,13 +20,15 @@ #include -// Enables debugging -//#define DEBUG_AUDIOSPEC - +// (defined in the header file) #ifdef DEBUG_AUDIOSPEC #include #endif +// Draw lines instead of single pixels. +// This is about 25 % faster, especially when enlarging the scope to e.g. 1680x1050 px. +#define AUDIOSPEC_LINES + #define MIN_DB_VALUE -120 #define MAX_FREQ_VALUE 96000 #define MIN_FREQ_VALUE 1000 @@ -36,6 +38,10 @@ AudioSpectrum::AudioSpectrum(QWidget *parent) : m_fftTools(), m_lastFFT(), m_lastFFTLock(1) + #ifdef DEBUG_AUDIOSPEC + ,m_timeTotal(0) + ,m_showTotal(0) + #endif { ui = new Ui::AudioSpectrum_UI; ui->setupUi(this); @@ -176,6 +182,8 @@ QImage AudioSpectrum::renderAudioScope(uint, const QVector audioFrame, m_lastFFTLock.release(); + QTime drawTime = QTime::currentTime(); + // Draw the spectrum QImage spectrum(m_scopeRect.size(), QImage::Format_ARGB32); spectrum.fill(qRgba(0,0,0,0)); @@ -185,6 +193,11 @@ QImage AudioSpectrum::renderAudioScope(uint, const QVector audioFrame, const uint topDist = m_innerScopeRect.top() - m_scopeRect.top(); int yMax; +#ifdef AUDIOSPEC_LINES + QPainter davinci(&spectrum); + davinci.setPen(AbstractScopeWidget::penThin); +#endif + for (uint i = 0; i < w; i++) { yMax = (dbMap[i] - m_dBmin) / (m_dBmax-m_dBmin) * (h-1); if (yMax < 0) { @@ -192,11 +205,21 @@ QImage AudioSpectrum::renderAudioScope(uint, const QVector audioFrame, } else if (yMax >= (int)h) { yMax = h-1; } +#ifdef AUDIOSPEC_LINES + davinci.drawLine(leftDist + i, topDist + h-1, leftDist + i, topDist + h-1 - yMax); +#else for (int y = 0; y < yMax && y < (int)h; y++) { spectrum.setPixel(leftDist + i, topDist + h-y-1, qRgba(225, 182, 255, 255)); } +#endif } +#ifdef DEBUG_AUDIOSPEC + m_showTotal++; + m_timeTotal += drawTime.elapsed(); + qDebug() << widgetName() << " took " << drawTime.elapsed() << " ms for drawing. Average: " << ((float)m_timeTotal/m_showTotal) ; +#endif + emit signalScopeRenderingFinished(start.elapsed(), 1); @@ -442,6 +465,10 @@ void AudioSpectrum::handleMouseDrag(const QPoint movement, const RescaleDirectio const QVector AudioSpectrum::interpolatePeakPreserving(const QVector in, const uint targetSize, uint left, uint right, float fill) { +#ifdef DEBUG_AUDIOSPEC + QTime start = QTime::currentTime(); +#endif + if (right == 0) { right = in.size()-1; } @@ -498,6 +525,10 @@ const QVector AudioSpectrum::interpolatePeakPreserving(const QVector #include #include @@ -91,6 +94,11 @@ private: */ static const QVector interpolatePeakPreserving(const QVector in, const uint targetSize, uint left = 0, uint right = 0, float fill = 0.0); +#ifdef DEBUG_AUDIOSPEC + long m_timeTotal; + long m_showTotal; +#endif + private slots: void slotResetMaxFreq(); -- 2.39.5