]> git.sesse.net Git - kdenlive/blobdiff - src/audioscopes/audiospectrum.h
Audio scopes: Only deliver audio when required for better performance when scopes...
[kdenlive] / src / audioscopes / audiospectrum.h
index 9a65a6499bda827d063f02c8d57f557fed62ca57..9ab399160f89b669aaff419ebdcf86af38da2ba9 100644 (file)
@@ -8,17 +8,25 @@
  *   (at your option) any later version.                                   *
  ***************************************************************************/
 
+/**
+   Displays a spectral power distribution of audio samples.
+   The frequency distribution is calculated by means of a Fast Fourier Transformation.
+   For more information see Wikipedia:FFT and the code comments.
+*/
+
 #ifndef AUDIOSPECTRUM_H
 #define AUDIOSPECTRUM_H
 
 #include <QtCore>
+#include <QVector>
+#include <QHash>
 
 #include "abstractaudioscopewidget.h"
 #include "ui_audiospectrum_ui.h"
 #include "tools/kiss_fftr.h"
+#include "ffttools.h"
 
 class AudioSpectrum_UI;
-
 class AudioSpectrum : public AbstractAudioScopeWidget {
     Q_OBJECT
 
@@ -29,11 +37,12 @@ public:
     // Implemented virtual methods
     QString widgetName() const;
 
+
 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;
@@ -41,25 +50,50 @@ protected:
     virtual void readConfig();
     void writeConfig();
 
+    virtual void handleMouseDrag(const QPoint movement, const RescaleDirection rescaleDirection, const Qt::KeyboardModifiers rescaleModifiers);
+
 private:
     Ui::AudioSpectrum_UI *ui;
-    kiss_fftr_cfg m_cfg;
 
-    QAction *m_aLin;
-    QAction *m_aLog;
-    QActionGroup *m_agScale;
+    QAction *m_aResetHz;
+    QAction *m_aTrackMouse;
 
-    QSize m_distance;
+    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;
 
     /** Lower bound for the dB value to display */
     int m_dBmin;
     /** Upper bound (max: 0) */
     int m_dBmax;
 
+    /** Maximum frequency (limited by the sampling rate if determined automatically).
+        Stored for the painters. */
     uint m_freqMax;
+    /** The user has chosen a custom frequency. */
+    bool m_customFreq;
+
+    /** 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);
+
 
 private slots:
-    void slotUpdateCfg();
+    void slotResetMaxFreq();
 
 };