1 /***************************************************************************
2 * Copyright (C) 2010 by Simon Andreas Eugster (simon.eu@gmail.com) *
3 * This file is part of kdenlive. See www.kdenlive.org. *
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 ***************************************************************************/
11 /** This Spectrogram shows the spectral power distribution of incoming audio samples
12 over time. See http://en.wikipedia.org/wiki/Spectrogram.
14 The Spectrogram makes use of two caches:
15 * A cached image where only the most recent line needs to be appended instead of
16 having to recalculate the whole image. A typical speedup factor is 10x.
17 * A FFT cache storing a history of previous spectral power distributions (i.e.
18 the Fourier-transformed audio signals). This is used if the user adjusts parameters
19 like the maximum frequency to display or minimum/maximum signal strength in dB.
20 All required information is preserved in the FFT history, which would not be the
21 case for an image (consider re-sizing the widget to 100x100 px and then back to
22 800x400 px -- lost is lost).
29 #include "abstractaudioscopewidget.h"
30 #include "ui_spectrogram_ui.h"
31 #include "lib/audio/fftTools.h"
34 class Spectrogram : public AbstractAudioScopeWidget {
38 Spectrogram(QWidget *parent = 0);
41 QString widgetName() const;
44 ///// Implemented methods /////
46 QImage renderHUD(uint accelerationFactor);
47 QImage renderAudioScope(uint accelerationFactor, const QVector<int16_t> &audioFrame, const int freq, const int num_channels, const int num_samples, const int newData);
48 QImage renderBackground(uint accelerationFactor);
49 bool isHUDDependingOnInput() const;
50 bool isScopeDependingOnInput() const;
51 bool isBackgroundDependingOnInput() const;
52 virtual void readConfig();
54 void handleMouseDrag(const QPoint &movement, const RescaleDirection rescaleDirection, const Qt::KeyboardModifiers rescaleModifiers);
55 void resizeEvent(QResizeEvent *event);
58 Ui::Spectrogram_UI *ui;
62 QAction *m_aTrackMouse;
63 QAction *m_aHighlightPeaks;
65 QList<QVector<float> > m_fftHistory;
66 QImage m_fftHistoryImg;
74 bool m_parameterChanged;
76 QRect m_innerScopeRect;
79 void slotResetMaxFreq();
83 #endif // SPECTROGRAM_H