]> git.sesse.net Git - kdenlive/blob - src/audioscopes/audiospectrum.h
Audio Spectrum: Option to show maximum values added (decreases with the Moving Averag...
[kdenlive] / src / audioscopes / audiospectrum.h
1 /***************************************************************************
2  *   Copyright (C) 2010 by Simon Andreas Eugster (simon.eu@gmail.com)      *
3  *   This file is part of kdenlive. See www.kdenlive.org.                  *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) any later version.                                   *
9  ***************************************************************************/
10
11 /**
12    Displays a spectral power distribution of audio samples.
13    The frequency distribution is calculated by means of a Fast Fourier Transformation.
14    For more information see Wikipedia:FFT and the code comments.
15 */
16
17 #ifndef AUDIOSPECTRUM_H
18 #define AUDIOSPECTRUM_H
19
20 // Enables debugging
21 //#define DEBUG_AUDIOSPEC
22
23 #include <QtCore>
24 #include <QVector>
25 #include <QHash>
26
27 #include "abstractaudioscopewidget.h"
28 #include "ui_audiospectrum_ui.h"
29 #include "tools/kiss_fftr.h"
30 #include "ffttools.h"
31
32 class AudioSpectrum_UI;
33 class AudioSpectrum : public AbstractAudioScopeWidget {
34     Q_OBJECT
35
36 public:
37     AudioSpectrum(QWidget *parent = 0);
38     ~AudioSpectrum();
39
40     // Implemented virtual methods
41     QString widgetName() const;
42
43
44 protected:
45     ///// Implemented methods /////
46     QRect scopeRect();
47     QImage renderHUD(uint accelerationFactor);
48     QImage renderAudioScope(uint accelerationFactor, const QVector<int16_t> audioFrame, const int freq, const int num_channels, const int num_samples, const int newData);
49     QImage renderBackground(uint accelerationFactor);
50     bool isHUDDependingOnInput() const;
51     bool isScopeDependingOnInput() const;
52     bool isBackgroundDependingOnInput() const;
53     virtual void readConfig();
54     void writeConfig();
55
56     virtual void handleMouseDrag(const QPoint movement, const RescaleDirection rescaleDirection, const Qt::KeyboardModifiers rescaleModifiers);
57
58 private:
59     Ui::AudioSpectrum_UI *ui;
60
61     QAction *m_aResetHz;
62     QAction *m_aTrackMouse;
63     QAction *m_aShowMax;
64
65     FFTTools m_fftTools;
66     QVector<float> m_lastFFT;
67     QSemaphore m_lastFFTLock;
68
69     QVector<float> m_peaks;
70     QVector<float> m_peakMap;
71
72     /** Contains the plot only; m_scopeRect contains text and widgets as well */
73     QRect m_innerScopeRect;
74
75     /** Lower bound for the dB value to display */
76     int m_dBmin;
77     /** Upper bound (max: 0) */
78     int m_dBmax;
79
80     /** Maximum frequency (limited by the sampling rate if determined automatically).
81         Stored for the painters. */
82     int m_freqMax;
83     /** The user has chosen a custom frequency. */
84     bool m_customFreq;
85
86 #ifdef DEBUG_AUDIOSPEC
87     long m_timeTotal;
88     long m_showTotal;
89 #endif
90
91
92 private slots:
93     void slotResetMaxFreq();
94
95 };
96
97 #endif // AUDIOSPECTRUM_H