]> git.sesse.net Git - kdenlive/blob - src/scopes/audioscopes/audiospectrum.h
Fix label
[kdenlive] / src / scopes / 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 #ifndef AUDIOSPECTRUM_H
13 #define AUDIOSPECTRUM_H
14
15 // Enables debugging
16 //#define DEBUG_AUDIOSPEC
17
18 // Show overmodulation
19 #define DETECT_OVERMODULATION
20
21 #include <QtCore>
22 #include <QVector>
23 #include <QHash>
24
25 #include "abstractaudioscopewidget.h"
26 #include "ui_audiospectrum_ui.h"
27 #include "lib/external/kiss_fft/tools/kiss_fftr.h"
28 #include "lib/audio/fftTools.h"
29
30 class AudioSpectrum_UI;
31
32 /**
33    \brief Displays a spectral power distribution of audio samples.
34    The frequency distribution is calculated by means of a Fast Fourier Transformation.
35    For more information see Wikipedia:FFT and the code comments.
36
37    \todo Currently only supports one channel. Add support for multiple channels.
38 */
39 class AudioSpectrum : public AbstractAudioScopeWidget {
40     Q_OBJECT
41
42 public:
43     explicit AudioSpectrum(QWidget *parent = 0);
44     ~AudioSpectrum();
45
46     // Implemented virtual methods
47     QString widgetName() const;
48
49
50 protected:
51     ///// Implemented methods /////
52     QRect scopeRect();
53     QImage renderHUD(uint accelerationFactor);
54     QImage renderAudioScope(uint accelerationFactor, const QVector<int16_t> &audioFrame, const int freq, const int num_channels, const int num_samples, const int newData);
55     QImage renderBackground(uint accelerationFactor);
56     bool isHUDDependingOnInput() const;
57     bool isScopeDependingOnInput() const;
58     bool isBackgroundDependingOnInput() const;
59     virtual void readConfig();
60     void writeConfig();
61
62     virtual void handleMouseDrag(const QPoint &movement, const RescaleDirection rescaleDirection, const Qt::KeyboardModifiers rescaleModifiers);
63
64 private:
65     Ui::AudioSpectrum_UI *ui;
66
67     QAction *m_aResetHz;
68     QAction *m_aTrackMouse;
69     QAction *m_aShowMax;
70
71     FFTTools m_fftTools;
72     QVector<float> m_lastFFT;
73     QSemaphore m_lastFFTLock;
74
75     QVector<float> m_peaks;
76     QVector<float> m_peakMap;
77
78     /** Contains the plot only; m_scopeRect contains text and widgets as well */
79     QRect m_innerScopeRect;
80
81     /** Lower bound for the dB value to display */
82     int m_dBmin;
83     /** Upper bound (max: 0) */
84     int m_dBmax;
85
86     /** Maximum frequency (limited by the sampling rate if determined automatically).
87         Stored for the painters. */
88     int m_freqMax;
89     /** The user has chosen a custom frequency. */
90     bool m_customFreq;
91
92     float colorizeFactor;
93
94 #ifdef DEBUG_AUDIOSPEC
95     long m_timeTotal;
96     long m_showTotal;
97 #endif
98
99
100 private slots:
101     void slotResetMaxFreq();
102
103 };
104
105 #endif // AUDIOSPECTRUM_H