]> git.sesse.net Git - kdenlive/blobdiff - src/audioscopes/audiospectrum.h
Reorganize and cleanup build structure
[kdenlive] / src / audioscopes / audiospectrum.h
index 3e714895ee8cedb991b2ddee479dade1b9d0a543..77308afa98e21f50cb1fb208ed708c9c39694c81 100644 (file)
@@ -8,17 +8,31 @@
  *   (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
 
+// Enables debugging
+//#define DEBUG_AUDIOSPEC
+
+// Show overmodulation
+#define DETECT_OVERMODULATION
+
 #include <QtCore>
+#include <QVector>
+#include <QHash>
 
 #include "abstractaudioscopewidget.h"
 #include "ui_audiospectrum_ui.h"
-#include "tools/kiss_fftr.h"
+#include "kiss_fft/tools/kiss_fftr.h"
+#include "ffttools.h"
 
 class AudioSpectrum_UI;
-
 class AudioSpectrum : public AbstractAudioScopeWidget {
     Q_OBJECT
 
@@ -29,16 +43,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;
@@ -46,47 +56,46 @@ 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;
-    kiss_fftr_cfg m_cfg;
 
-    QAction *m_aLockHz;
-    QAction *m_aLin;
-    QAction *m_aLog;
-    QActionGroup *m_agScale;
+    QAction *m_aResetHz;
+    QAction *m_aTrackMouse;
+    QAction *m_aShowMax;
 
-    QSize m_distance;
+    FFTTools m_fftTools;
+    QVector<float> m_lastFFT;
+    QSemaphore m_lastFFTLock;
+
+    QVector<float> m_peaks;
+    QVector<float> m_peakMap;
+
+    /** 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 (depends on the sampling rate)
-        Stored for the HUD painter */
-    uint m_freqMax;
-
-
-    ///// Movement detection /////
-    const int m_rescaleMinDist;
-    const float m_rescaleVerticalThreshold;
+    /** Maximum frequency (limited by the sampling rate if determined automatically).
+        Stored for the painters. */
+    int m_freqMax;
+    /** The user has chosen a custom frequency. */
+    bool m_customFreq;
 
-    bool m_rescaleActive;
-    bool m_rescalePropertiesLocked;
-    bool m_rescaleFirstRescaleDone;
-    short m_rescaleScale;
-    Qt::KeyboardModifiers m_rescaleModifiers;
-    AudioSpectrum::RescaleDirection m_rescaleClockDirection;
-    QPoint m_rescaleStartPoint;
+    float colorizeFactor;
 
+#ifdef DEBUG_AUDIOSPEC
+    long m_timeTotal;
+    long m_showTotal;
+#endif
 
 
 private slots:
-    void slotUpdateCfg();
+    void slotResetMaxFreq();
 
 };