]> git.sesse.net Git - kdenlive/blobdiff - src/audioscopes/audiospectrum.cpp
Reorganize and cleanup build structure
[kdenlive] / src / audioscopes / audiospectrum.cpp
index a92f6f5d5244577c9d71ed05beec824f11bd89e7..be40af7ab57504fbc284be771bf794958a02b588 100644 (file)
@@ -12,7 +12,7 @@
 
 #include "audiospectrum.h"
 #include "ffttools.h"
-#include "tools/kiss_fftr.h"
+#include "kiss_fft/tools/kiss_fftr.h"
 
 #include <QMenu>
 #include <QPainter>
 #include <QDebug>
 #endif
 
+// (defined in the header file)
+#ifdef DETECT_OVERMODULATION
+#include <limits>
+#include <cmath>
+#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
+#define ALPHA_MOVING_AVG 0.125
+#define MAX_OVM_COLOR 0.7
 
 AudioSpectrum::AudioSpectrum(QWidget *parent) :
-        AbstractAudioScopeWidget(true, parent),
-        m_fftTools(),
-        m_lastFFT(),
-        m_lastFFTLock(1)
+    AbstractAudioScopeWidget(true, parent),
+    m_fftTools(),
+    m_lastFFT(),
+    m_lastFFTLock(1),
+    m_peaks()
   #ifdef DEBUG_AUDIOSPEC
-        ,m_timeTotal(0)
-        ,m_showTotal(0)
+    ,m_timeTotal(0)
+    ,m_showTotal(0)
   #endif
+  ,colorizeFactor(0)
 {
     ui = new Ui::AudioSpectrum_UI;
     ui->setupUi(this);
@@ -50,11 +60,14 @@ AudioSpectrum::AudioSpectrum(QWidget *parent) :
     m_aResetHz = new QAction(i18n("Reset maximum frequency to sampling rate"), this);
     m_aTrackMouse = new QAction(i18n("Track mouse"), this);
     m_aTrackMouse->setCheckable(true);
+    m_aShowMax = new QAction(i18n("Show maximum"), this);
+    m_aShowMax->setCheckable(true);
 
 
     m_menu->addSeparator();
     m_menu->addAction(m_aResetHz);
     m_menu->addAction(m_aTrackMouse);
+    m_menu->addAction(m_aShowMax);
     m_menu->removeAction(m_aRealtime);
 
 
@@ -88,6 +101,7 @@ AudioSpectrum::~AudioSpectrum()
 
     delete m_aResetHz;
     delete m_aTrackMouse;
+    delete ui;
 }
 
 void AudioSpectrum::readConfig()
@@ -100,6 +114,7 @@ void AudioSpectrum::readConfig()
     ui->windowSize->setCurrentIndex(scopeConfig.readEntry("windowSize", 0));
     ui->windowFunction->setCurrentIndex(scopeConfig.readEntry("windowFunction", 0));
     m_aTrackMouse->setChecked(scopeConfig.readEntry("trackMouse", true));
+    m_aShowMax->setChecked(scopeConfig.readEntry("showMax", true));
     m_dBmax = scopeConfig.readEntry("dBmax", 0);
     m_dBmin = scopeConfig.readEntry("dBmin", -70);
     m_freqMax = scopeConfig.readEntry("freqMax", 0);
@@ -119,6 +134,7 @@ void AudioSpectrum::writeConfig()
     scopeConfig.writeEntry("windowSize", ui->windowSize->currentIndex());
     scopeConfig.writeEntry("windowFunction", ui->windowFunction->currentIndex());
     scopeConfig.writeEntry("trackMouse", m_aTrackMouse->isChecked());
+    scopeConfig.writeEntry("showMax", m_aShowMax->isChecked());
     scopeConfig.writeEntry("dBmax", m_dBmax);
     scopeConfig.writeEntry("dBmin", m_dBmin);
     if (m_customFreq) {
@@ -140,7 +156,10 @@ QImage AudioSpectrum::renderBackground(uint) { return QImage(); }
 QImage AudioSpectrum::renderAudioScope(uint, const QVector<int16_t> audioFrame, const int freq, const int num_channels,
                                        const int num_samples, const int)
 {
-    if (audioFrame.size() > 63) {
+    if (
+            audioFrame.size() > 63
+            && m_innerScopeRect.width() > 0 && m_innerScopeRect.height() > 0    // <= 0 if widget is too small (resized by user)
+    ) {
         if (!m_customFreq) {
             m_freqMax = freq / 2;
         }
@@ -148,6 +167,34 @@ QImage AudioSpectrum::renderAudioScope(uint, const QVector<int16_t> audioFrame,
         QTime start = QTime::currentTime();
 
 
+#ifdef DETECT_OVERMODULATION
+        bool overmodulated = false;
+        int overmodulateCount = 0;
+
+        for (int i = 0; i < audioFrame.size(); i++) {
+            if (
+                    audioFrame[i] == std::numeric_limits<int16_t>::max()
+                    || audioFrame[i] == std::numeric_limits<int16_t>::min()) {
+                overmodulateCount++;
+                if (overmodulateCount > 3) {
+                    overmodulated = true;
+                    break;
+                }
+            }
+        }
+        if (overmodulated) {
+            colorizeFactor = 1;
+        } else {
+            if (colorizeFactor > 0) {
+                colorizeFactor -= .08;
+                if (colorizeFactor < 0) {
+                    colorizeFactor = 0;
+                }
+            }
+        }
+#endif
+
+
         // Determine the window size to use. It should be
         // * not bigger than the number of samples actually available
         // * divisible by 2
@@ -177,12 +224,14 @@ QImage AudioSpectrum::renderAudioScope(uint, const QVector<int16_t> audioFrame,
         m_lastFFT = QVector<float>(fftWindow/2);
         memcpy(m_lastFFT.data(), &(freqSpectrum[0]), fftWindow/2 * sizeof(float));
 
-        uint right = ((float) m_freqMax)/(m_freq) * (m_lastFFT.size() - 1);
-        dbMap = interpolatePeakPreserving(m_lastFFT, m_innerScopeRect.width(), 0, right, -120);
+        uint right = ((float) m_freqMax)/(m_freq/2) * (m_lastFFT.size() - 1);
+        dbMap = FFTTools::interpolatePeakPreserving(m_lastFFT, m_innerScopeRect.width(), 0, right, -180);
         m_lastFFTLock.release();
 
 
+#ifdef DEBUG_AUDIOSPEC
         QTime drawTime = QTime::currentTime();
+#endif
 
         // Draw the spectrum
         QImage spectrum(m_scopeRect.size(), QImage::Format_ARGB32);
@@ -191,11 +240,31 @@ QImage AudioSpectrum::renderAudioScope(uint, const QVector<int16_t> audioFrame,
         const uint h = m_innerScopeRect.height();
         const uint leftDist = m_innerScopeRect.left() - m_scopeRect.left();
         const uint topDist = m_innerScopeRect.top() - m_scopeRect.top();
+        QColor spectrumColor(AbstractScopeWidget::colDarkWhite);
         int yMax;
 
+#ifdef DETECT_OVERMODULATION
+        if (colorizeFactor > 0) {
+            QColor col = AbstractScopeWidget::colHighlightDark;
+            QColor spec = spectrumColor;
+            float f = std::sin(M_PI_2 * colorizeFactor);
+            spectrumColor = QColor(
+                        (int) (f * col.red() + (1-f) * spec.red()),
+                        (int) (f * col.green() + (1-f) * spec.green()),
+                        (int) (f * col.blue() + (1-f) * spec.blue()),
+                        spec.alpha()
+                        );
+            // Limit the maximum colorization for non-overmodulated frames to better
+            // recognize consecutively overmodulated frames
+            if (colorizeFactor > MAX_OVM_COLOR) {
+                colorizeFactor = MAX_OVM_COLOR;
+            }
+        }
+#endif
+
 #ifdef AUDIOSPEC_LINES
         QPainter davinci(&spectrum);
-        davinci.setPen(AbstractScopeWidget::penThin);
+        davinci.setPen(QPen(QBrush(spectrumColor.rgba()), 1, Qt::SolidLine));
 #endif
 
         for (uint i = 0; i < w; i++) {
@@ -209,11 +278,42 @@ QImage AudioSpectrum::renderAudioScope(uint, const QVector<int16_t> audioFrame,
             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));
+                spectrum.setPixel(leftDist + i, topDist + h-y-1, spectrumColor.rgba());
             }
 #endif
         }
 
+        // Calculate the peak values. Use the new value if it is bigger, otherwise adapt to lower
+        // values using the Moving Average formula
+        if (m_aShowMax->isChecked()) {
+            davinci.setPen(QPen(QBrush(AbstractScopeWidget::colHighlightLight), 2));
+            if (m_peaks.size() != fftWindow/2) {
+                m_peaks = QVector<float>(m_lastFFT);
+            } else {
+                for (int i = 0; i < fftWindow/2; i++) {
+                    if (m_lastFFT[i] > m_peaks[i]) {
+                        m_peaks[i] = m_lastFFT[i];
+                    } else {
+                        m_peaks[i] = ALPHA_MOVING_AVG * m_lastFFT[i] + (1-ALPHA_MOVING_AVG) * m_peaks[i];
+                    }
+                }
+            }
+            int prev = 0;
+            m_peakMap = FFTTools::interpolatePeakPreserving(m_peaks, m_innerScopeRect.width(), 0, right, -180);
+            for (uint i = 0; i < w; i++) {
+                yMax = (m_peakMap[i] - m_dBmin) / (m_dBmax-m_dBmin) * (h-1);
+                if (yMax < 0) {
+                    yMax = 0;
+                } else if (yMax >= (int)h) {
+                    yMax = h-1;
+                }
+
+                davinci.drawLine(leftDist + i-1, topDist + h-prev-1, leftDist + i, topDist + h-yMax-1);
+                spectrum.setPixel(leftDist + i, topDist + h-yMax-1, AbstractScopeWidget::colHighlightLight.rgba());
+                prev = yMax;
+            }
+        }
+
 #ifdef DEBUG_AUDIOSPEC
         m_showTotal++;
         m_timeTotal += drawTime.elapsed();
@@ -233,137 +333,149 @@ QImage AudioSpectrum::renderHUD(uint)
 {
     QTime start = QTime::currentTime();
 
-    // Minimum distance between two lines
-    const uint minDistY = 30;
-    const uint minDistX = 40;
-    const uint textDistX = 10;
-    const uint textDistY = 25;
-    const uint topDist = m_innerScopeRect.top() - m_scopeRect.top();
-    const uint leftDist = m_innerScopeRect.left() - m_scopeRect.left();
-    const uint dbDiff = ceil((float)minDistY/m_innerScopeRect.height() * (m_dBmax-m_dBmin));
-    const int mouseX = m_mousePos.x() - m_innerScopeRect.left();
-    const int mouseY = m_mousePos.y() - m_innerScopeRect.top();
-
-    QImage hud(m_scopeRect.size(), QImage::Format_ARGB32);
-    hud.fill(qRgba(0,0,0,0));
-
-    QPainter davinci(&hud);
-    davinci.setPen(AbstractScopeWidget::penLight);
-
-    int y;
-    for (int db = -dbDiff; db > m_dBmin; db -= dbDiff) {
-        y = topDist + m_innerScopeRect.height() * ((float)db)/(m_dBmin - m_dBmax);
-        if (y-topDist > m_innerScopeRect.height()-minDistY+10) {
-            // Abort here, there is still a line left for min dB to paint which needs some room.
-            break;
-        }
-        davinci.drawLine(leftDist, y, leftDist + m_innerScopeRect.width()-1, y);
-        davinci.drawText(leftDist + m_innerScopeRect.width() + textDistX, y + 6, i18n("%1 dB", m_dBmax + db));
-    }
-    davinci.drawLine(leftDist, topDist, leftDist + m_innerScopeRect.width()-1, topDist);
-    davinci.drawText(leftDist + m_innerScopeRect.width() + textDistX, topDist+6, i18n("%1 dB", m_dBmax));
-    davinci.drawLine(leftDist, topDist+m_innerScopeRect.height()-1, leftDist + m_innerScopeRect.width()-1, topDist+m_innerScopeRect.height()-1);
-    davinci.drawText(leftDist + m_innerScopeRect.width() + textDistX, topDist+m_innerScopeRect.height()+6, i18n("%1 dB", m_dBmin));
-
-    const uint hzDiff = ceil( ((float)minDistX)/m_innerScopeRect.width() * m_freqMax / 1000 ) * 1000;
-    int x = 0;
-    const int rightBorder = leftDist + m_innerScopeRect.width()-1;
-    y = topDist + m_innerScopeRect.height() + textDistY;
-    for (uint hz = 0; x <= rightBorder; hz += hzDiff) {
+    if (m_innerScopeRect.height() > 0 && m_innerScopeRect.width() > 0) { // May be below 0 if widget is too small
+
+        // Minimum distance between two lines
+        const uint minDistY = 30;
+        const uint minDistX = 40;
+        const uint textDistX = 10;
+        const uint textDistY = 25;
+        const uint topDist = m_innerScopeRect.top() - m_scopeRect.top();
+        const uint leftDist = m_innerScopeRect.left() - m_scopeRect.left();
+        const uint dbDiff = ceil((float)minDistY/m_innerScopeRect.height() * (m_dBmax-m_dBmin));
+        const int mouseX = m_mousePos.x() - m_innerScopeRect.left();
+        const int mouseY = m_mousePos.y() - m_innerScopeRect.top();
+
+
+        QImage hud(m_scopeRect.size(), QImage::Format_ARGB32);
+        hud.fill(qRgba(0,0,0,0));
+
+        QPainter davinci(&hud);
         davinci.setPen(AbstractScopeWidget::penLight);
-        x = leftDist + m_innerScopeRect.width() * ((float)hz)/m_freqMax;
 
-        if (x <= rightBorder) {
-            davinci.drawLine(x, topDist, x, topDist + m_innerScopeRect.height()+6);
-        }
-        if (hz < m_freqMax && x+textDistY < leftDist + m_innerScopeRect.width()) {
-            davinci.drawText(x-4, y, QVariant(hz/1000).toString());
-        } else {
-            x = leftDist + m_innerScopeRect.width();
-            davinci.drawLine(x, topDist, x, topDist + m_innerScopeRect.height()+6);
-            davinci.drawText(x-10, y, i18n("%1 kHz").arg((double)m_freqMax/1000, 0, 'f', 1));
+        int y;
+        for (int db = -dbDiff; db > m_dBmin; db -= dbDiff) {
+            y = topDist + m_innerScopeRect.height() * ((float)db)/(m_dBmin - m_dBmax);
+            if (y-topDist > m_innerScopeRect.height()-minDistY+10) {
+                // Abort here, there is still a line left for min dB to paint which needs some room.
+                break;
+            }
+            davinci.drawLine(leftDist, y, leftDist + m_innerScopeRect.width()-1, y);
+            davinci.drawText(leftDist + m_innerScopeRect.width() + textDistX, y + 6, i18n("%1 dB", m_dBmax + db));
         }
+        davinci.drawLine(leftDist, topDist, leftDist + m_innerScopeRect.width()-1, topDist);
+        davinci.drawText(leftDist + m_innerScopeRect.width() + textDistX, topDist+6, i18n("%1 dB", m_dBmax));
+        davinci.drawLine(leftDist, topDist+m_innerScopeRect.height()-1, leftDist + m_innerScopeRect.width()-1, topDist+m_innerScopeRect.height()-1);
+        davinci.drawText(leftDist + m_innerScopeRect.width() + textDistX, topDist+m_innerScopeRect.height()+6, i18n("%1 dB", m_dBmin));
+
+        const uint hzDiff = ceil( ((float)minDistX)/m_innerScopeRect.width() * m_freqMax / 1000 ) * 1000;
+        int x = 0;
+        const int rightBorder = leftDist + m_innerScopeRect.width()-1;
+        y = topDist + m_innerScopeRect.height() + textDistY;
+        for (int hz = 0; x <= rightBorder; hz += hzDiff) {
+            davinci.setPen(AbstractScopeWidget::penLighter);
+            x = leftDist + m_innerScopeRect.width() * ((float)hz)/m_freqMax;
 
-        if (hz > 0) {
-            // Draw finer lines between the main lines
-            davinci.setPen(AbstractScopeWidget::penLightDots);
-            for (uint dHz = 3; dHz > 0; dHz--) {
-                x = leftDist + m_innerScopeRect.width() * ((float)hz - dHz * hzDiff/4.0f)/m_freqMax;
-                if (x > rightBorder) {
-                    break;
+            if (x <= rightBorder) {
+                davinci.drawLine(x, topDist, x, topDist + m_innerScopeRect.height()+6);
+            }
+            if (hz < m_freqMax && x+textDistY < leftDist + m_innerScopeRect.width()) {
+                davinci.drawText(x-4, y, QVariant(hz/1000).toString());
+            } else {
+                x = leftDist + m_innerScopeRect.width();
+                davinci.drawLine(x, topDist, x, topDist + m_innerScopeRect.height()+6);
+                davinci.drawText(x-10, y, i18n("%1 kHz").arg((double)m_freqMax/1000, 0, 'f', 1));
+            }
+
+            if (hz > 0) {
+                // Draw finer lines between the main lines
+                davinci.setPen(AbstractScopeWidget::penLightDots);
+                for (uint dHz = 3; dHz > 0; dHz--) {
+                    x = leftDist + m_innerScopeRect.width() * ((float)hz - dHz * hzDiff/4.0f)/m_freqMax;
+                    if (x > rightBorder) {
+                        break;
+                    }
+                    davinci.drawLine(x, topDist, x, topDist + m_innerScopeRect.height()-1);
                 }
-                davinci.drawLine(x, topDist, x, topDist + m_innerScopeRect.height()-1);
             }
         }
-    }
 
-    if (m_aTrackMouse->isChecked() && m_mouseWithinWidget && mouseX < m_innerScopeRect.width()-1) {
-        davinci.setPen(AbstractScopeWidget::penThin);
+        if (m_aTrackMouse->isChecked() && m_mouseWithinWidget && mouseX < m_innerScopeRect.width()-1) {
+            davinci.setPen(AbstractScopeWidget::penThin);
 
-        x = leftDist + mouseX;
+            x = leftDist + mouseX;
 
-        float db = 0;
-        float freq = ((float) mouseX)/(m_innerScopeRect.width()-1) * m_freqMax;
-        bool drawDb = false;
+            float db = 0;
+            float freq = ((float) mouseX)/(m_innerScopeRect.width()-1) * m_freqMax;
+            bool drawDb = false;
 
-        m_lastFFTLock.acquire();
-        // We need to test whether the mouse is inside the widget
-        // because the position could already have changed in the meantime (-> crash)
-        if (m_lastFFT.size() > 0 && mouseX >= 0 && mouseX < m_innerScopeRect.width()) {
-            uint right = ((float) m_freqMax)/(m_freq) * (m_lastFFT.size() - 1);
-            QVector<float> dbMap = AudioSpectrum::interpolatePeakPreserving(m_lastFFT, m_innerScopeRect.width(), 0, right, -120);
-
-            db = dbMap[mouseX];
-            y = topDist + m_innerScopeRect.height()-1 - (dbMap[mouseX] - m_dBmin) / (m_dBmax-m_dBmin) * (m_innerScopeRect.height()-1);
-
-            if (y < (int)topDist + m_innerScopeRect.height()-1) {
-                drawDb = true;
-                davinci.drawLine(x, y, leftDist + m_innerScopeRect.width()-1, y);
+            m_lastFFTLock.acquire();
+            // We need to test whether the mouse is inside the widget
+            // because the position could already have changed in the meantime (-> crash)
+            if (m_lastFFT.size() > 0 && mouseX >= 0 && mouseX < m_innerScopeRect.width()) {
+                uint right = ((float) m_freqMax)/(m_freq/2) * (m_lastFFT.size() - 1);
+                QVector<float> dbMap = FFTTools::interpolatePeakPreserving(m_lastFFT, m_innerScopeRect.width(), 0, right, -120);
+
+                db = dbMap[mouseX];
+                y = topDist + m_innerScopeRect.height()-1 - (dbMap[mouseX] - m_dBmin) / (m_dBmax-m_dBmin) * (m_innerScopeRect.height()-1);
+
+                if (y < (int)topDist + m_innerScopeRect.height()-1) {
+                    drawDb = true;
+                    davinci.drawLine(x, y, leftDist + m_innerScopeRect.width()-1, y);
+                }
+            } else {
+                y = topDist + mouseY;
             }
-        } else {
-            y = topDist + mouseY;
-        }
-        m_lastFFTLock.release();
+            m_lastFFTLock.release();
 
-        if (y > (int)topDist + mouseY) {
-            y = topDist+ mouseY;
-        }
-        davinci.drawLine(x, y, x, topDist + m_innerScopeRect.height()-1);
-
-        if (drawDb) {
-            QPoint dist(20, -20);
-            QRect rect(
-                        leftDist + mouseX + dist.x(),
-                        topDist + mouseY + dist.y(),
-                        100,
-                        40
-                        );
-            if (rect.right() > (int)leftDist + m_innerScopeRect.width()-1) {
-                // Mirror the rectangle at the y axis to keep it inside the widget
-                rect = QRect(
-                            rect.topLeft() - QPoint(rect.width() + 2*dist.x(), 0),
-                            rect.size());
+            if (y > (int)topDist + mouseY) {
+                y = topDist+ mouseY;
             }
+            davinci.drawLine(x, y, x, topDist + m_innerScopeRect.height()-1);
+
+            if (drawDb) {
+                QPoint dist(20, -20);
+                QRect rect(
+                            leftDist + mouseX + dist.x(),
+                            topDist + mouseY + dist.y(),
+                            100,
+                            40
+                            );
+                if (rect.right() > (int)leftDist + m_innerScopeRect.width()-1) {
+                    // Mirror the rectangle at the y axis to keep it inside the widget
+                    rect = QRect(
+                                rect.topLeft() - QPoint(rect.width() + 2*dist.x(), 0),
+                                rect.size());
+                }
 
-            QRect textRect(
-                        rect.topLeft() + QPoint(12, 4),
-                        rect.size()
-                        );
+                QRect textRect(
+                            rect.topLeft() + QPoint(12, 4),
+                            rect.size()
+                            );
+
+                davinci.fillRect(rect, AbstractScopeWidget::penBackground.brush());
+                davinci.setPen(AbstractScopeWidget::penLighter);
+                davinci.drawRect(rect);
+                davinci.drawText(textRect, QString(
+                                     i18n("%1 dB", QString("%1").arg(db, 0, 'f', 2))
+                                     + "\n"
+                                     + i18n("%1 kHz", QString("%1").arg(freq/1000, 0, 'f', 2))));
+            }
 
-            davinci.fillRect(rect, AbstractScopeWidget::penBackground.brush());
-            davinci.setPen(AbstractScopeWidget::penLighter);
-            davinci.drawRect(rect);
-            davinci.drawText(textRect, QString(
-                                 i18n("%1 dB", QString("%1").arg(db, 0, 'f', 2))
-                                 + "\n"
-                                 + i18n("%1 kHz", QString("%1").arg(freq/1000, 0, 'f', 2))));
         }
 
-    }
+        emit signalHUDRenderingFinished(start.elapsed(), 1);
+        return hud;
 
+    } else {
+#ifdef DEBUG_AUDIOSPEC
+        qDebug() << "Widget is too small for painting inside. Size of inner scope rect is "
+                 << m_innerScopeRect.width() << "x" << m_innerScopeRect.height() <<".";
+#endif
+        emit signalHUDRenderingFinished(0, 1);
+        return QImage();
+    }
 
-    emit signalHUDRenderingFinished(start.elapsed(), 1);
-    return hud;
 }
 
 QRect AudioSpectrum::scopeRect()
@@ -397,7 +509,7 @@ void AudioSpectrum::slotResetMaxFreq()
 
 ///// EVENTS /////
 
-void AudioSpectrum::handleMouseDrag(const QPoint movement, const RescaleDirection rescaleDirection, const Qt::KeyboardModifiers rescaleModifiers)
+void AudioSpectrum::handleMouseDrag(const QPoint &movement, const RescaleDirection rescaleDirection, const Qt::KeyboardModifiers rescaleModifiers)
 {
     if (rescaleDirection == North) {
         // Nort-South direction: Adjust the dB scale
@@ -461,82 +573,3 @@ void AudioSpectrum::handleMouseDrag(const QPoint movement, const RescaleDirectio
         forceUpdateScope();
     }
 }
-
-
-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;
-    }
-    Q_ASSERT(targetSize > 0);
-    Q_ASSERT(left < right);
-
-    QVector<float> out(targetSize);
-
-
-    float x;
-    float x_prev = 0;
-    int xi;
-    uint i;
-    for (i = 0; i < targetSize; i++) {
-
-        // i:  Target index
-        // x:  Interpolated source index (float!)
-        // xi: floor(x)
-
-        // Transform [0,targetSize-1] to [left,right]
-        x = ((float) i) / (targetSize-1) * (right-left) + left;
-        xi = (int) floor(x);
-
-        if (x > in.size()-1) {
-            // This may happen if right > in.size()-1; Fill the rest of the vector
-            // with the default value now.
-            break;
-        }
-
-
-        // Use linear interpolation in order to get smoother display
-        if (i == 0 || i == targetSize-1) {
-            // ... except if we are at the left or right border of the display or the spectrum
-            out[i] = in[xi];
-        } else {
-            if (in[xi] > in[xi+1]
-                && x_prev < xi) {
-                // This is a hack to preserve peaks.
-                // Consider f = {0, 100, 0}
-                //          x = {0.5,  1.5}
-                // Then x is 50 both times, and the 100 peak is lost.
-                // Get it back here for the first x after the peak (which is at xi).
-                // (x is the first after the peak if the previous x was smaller than floor(x).)
-                out[i] = in[xi];
-            } else {
-                out[i] =   (xi+1 - x) * in[xi]
-                      + (x - xi)   * in[xi+1];
-            }
-        }
-        x_prev = x;
-    }
-    // Fill the rest of the vector if the right border exceeds the input vector.
-    for (; i < targetSize; i++) {
-        out[i] = fill;
-    }
-
-#ifdef DEBUG_AUDIOSPEC
-    qDebug() << "Interpolated " << targetSize << " nodes from " << in.size() << " input points in " << start.elapsed() << " ms";
-#endif
-
-    return out;
-}
-
-
-#ifdef DEBUG_AUDIOSPEC
-#undef DEBUG_AUDIOSPEC
-#endif
-
-#undef MIN_DB_VALUE
-#undef MAX_FREQ_VALUE
-#undef MIN_FREQ_VALUE