]> git.sesse.net Git - kdenlive/commitdiff
Audio Spectrum: Increased performance by 25 % by directly painting lines instead...
authorSimon A. Eugster <simon.eu@gmail.com>
Tue, 14 Dec 2010 12:59:06 +0000 (12:59 +0000)
committerSimon A. Eugster <simon.eu@gmail.com>
Tue, 14 Dec 2010 12:59:06 +0000 (12:59 +0000)
svn path=/trunk/kdenlive/; revision=5174

src/audioscopes/audiospectrum.cpp
src/audioscopes/audiospectrum.h

index ef8b44beb6871240dc6e1a12964a3900a4d9f76e..a92f6f5d5244577c9d71ed05beec824f11bd89e7 100644 (file)
 
 #include <iostream>
 
-// Enables debugging
-//#define DEBUG_AUDIOSPEC
-
+// (defined in the header file)
 #ifdef DEBUG_AUDIOSPEC
 #include <QDebug>
 #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<int16_t> 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<int16_t> 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<int16_t> 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<float> AudioSpectrum::interpolatePeakPreserving(const QVector<float> 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<float> AudioSpectrum::interpolatePeakPreserving(const QVector<floa
         out[i] = fill;
     }
 
+#ifdef DEBUG_AUDIOSPEC
+    qDebug() << "Interpolated " << targetSize << " nodes from " << in.size() << " input points in " << start.elapsed() << " ms";
+#endif
+
     return out;
 }
 
index 9ab399160f89b669aaff419ebdcf86af38da2ba9..057dcdeed531cebaca19158de404a599834ec6ba 100644 (file)
@@ -17,6 +17,9 @@
 #ifndef AUDIOSPECTRUM_H
 #define AUDIOSPECTRUM_H
 
+// Enables debugging
+//#define DEBUG_AUDIOSPEC
+
 #include <QtCore>
 #include <QVector>
 #include <QHash>
@@ -91,6 +94,11 @@ private:
         */
     static const QVector<float> interpolatePeakPreserving(const QVector<float> 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();