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