]> git.sesse.net Git - kdenlive/blobdiff - src/audioscopes/audiospectrum.h
Audio Spectrum: Increased performance by 25 % by directly painting lines instead...
[kdenlive] / src / audioscopes / audiospectrum.h
index 45c210073752277490a556a9b347ff8d9c6b78a6..057dcdeed531cebaca19158de404a599834ec6ba 100644 (file)
@@ -17,6 +17,9 @@
 #ifndef AUDIOSPECTRUM_H
 #define AUDIOSPECTRUM_H
 
+// Enables debugging
+//#define DEBUG_AUDIOSPEC
+
 #include <QtCore>
 #include <QVector>
 #include <QHash>
@@ -24,6 +27,7 @@
 #include "abstractaudioscopewidget.h"
 #include "ui_audiospectrum_ui.h"
 #include "tools/kiss_fftr.h"
+#include "ffttools.h"
 
 class AudioSpectrum_UI;
 class AudioSpectrum : public AbstractAudioScopeWidget {
@@ -36,16 +40,12 @@ public:
     // Implemented virtual methods
     QString widgetName() const;
 
-    static const QString directions[]; // Mainly for debug output
-    enum RescaleDirection { North, Northeast, East, Southeast };
-    enum RescaleDimension { Min_dB, Max_dB, Max_Hz };
-
 
 protected:
     ///// Implemented methods /////
     QRect scopeRect();
     QImage renderHUD(uint accelerationFactor);
-    QImage renderAudioScope(uint accelerationFactor, const QVector<int16_t> audioFrame, const int freq, const int num_channels, const int num_samples);
+    QImage renderAudioScope(uint accelerationFactor, const QVector<int16_t> audioFrame, const int freq, const int num_channels, const int num_samples, const int newData);
     QImage renderBackground(uint accelerationFactor);
     bool isHUDDependingOnInput() const;
     bool isScopeDependingOnInput() const;
@@ -53,16 +53,17 @@ protected:
     virtual void readConfig();
     void writeConfig();
 
-    void mouseMoveEvent(QMouseEvent *event);
-    void mousePressEvent(QMouseEvent *event);
-    void mouseReleaseEvent(QMouseEvent *event);
+    virtual void handleMouseDrag(const QPoint movement, const RescaleDirection rescaleDirection, const Qt::KeyboardModifiers rescaleModifiers);
 
 private:
     Ui::AudioSpectrum_UI *ui;
-    QHash<QString, kiss_fftr_cfg> m_fftCfgs; // FFT cfg cache
-    QHash<QString, QVector<float> > m_windowFunctions; // Window function cache
 
     QAction *m_aResetHz;
+    QAction *m_aTrackMouse;
+
+    FFTTools m_fftTools;
+    QVector<float> m_lastFFT;
+    QSemaphore m_lastFFTLock;
 
     /** Contains the plot only; m_scopeRect contains text and widgets as well */
     QRect m_innerScopeRect;
@@ -78,24 +79,25 @@ private:
     /** The user has chosen a custom frequency. */
     bool m_customFreq;
 
-
-    /** Returns a signature for a kiss_fft configuration
-        used as a hash in the cache */
-    static const QString cfgSignature(const int size);
-
-
-    ///// Movement detection /////
-    const int m_rescaleMinDist;
-    const float m_rescaleVerticalThreshold;
-
-    bool m_rescaleActive;
-    bool m_rescalePropertiesLocked;
-    bool m_rescaleFirstRescaleDone;
-    short m_rescaleScale;
-    Qt::KeyboardModifiers m_rescaleModifiers;
-    AudioSpectrum::RescaleDirection m_rescaleClockDirection;
-    QPoint m_rescaleStartPoint;
-
+    /** This is linear interpolation with the special property that it preserves peaks, which is required
+        for e.g. showing correct Decibel values (where the peak values are of interest).
+        Consider f = {0, 100, 0}
+                 x = {0.5,  1.5}: With default linear interpolation x0 and x1 would both be mapped to 50.
+        This function maps x1 (the first position after the peak) to 100.
+
+        @param in           The source vector containing the data
+        @param targetSize   Number of interpolation nodes between ...
+        @param left         the left array index in the in-vector and ...
+        @param right        the right array index (both inclusive).
+        @param fill         If right lies outside of the array bounds (which is perfectly fine here) then this value
+                            will be used for filling the missing information.
+        */
+    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: