00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef _FFT_MODEL_H_
00017 #define _FFT_MODEL_H_
00018
00019 #include "data/fft/FFTDataServer.h"
00020 #include "DenseThreeDimensionalModel.h"
00021
00022 #include <set>
00023 #include <map>
00024
00031 class FFTModel : public DenseThreeDimensionalModel
00032 {
00033 Q_OBJECT
00034
00035 public:
00056 FFTModel(const DenseTimeValueModel *model,
00057 int channel,
00058 WindowType windowType,
00059 size_t windowSize,
00060 size_t windowIncrement,
00061 size_t fftSize,
00062 bool polar,
00063 StorageAdviser::Criteria criteria = StorageAdviser::NoCriteria,
00064 size_t fillFromColumn = 0);
00065 ~FFTModel();
00066
00067 float getMagnitudeAt(size_t x, size_t y) {
00068 return m_server->getMagnitudeAt(x << m_xshift, y << m_yshift);
00069 }
00070 float getNormalizedMagnitudeAt(size_t x, size_t y) {
00071 return m_server->getNormalizedMagnitudeAt(x << m_xshift, y << m_yshift);
00072 }
00073 float getMaximumMagnitudeAt(size_t x) {
00074 return m_server->getMaximumMagnitudeAt(x << m_xshift);
00075 }
00076 float getPhaseAt(size_t x, size_t y) {
00077 return m_server->getPhaseAt(x << m_xshift, y << m_yshift);
00078 }
00079 void getValuesAt(size_t x, size_t y, float &real, float &imaginary) {
00080 m_server->getValuesAt(x << m_xshift, y << m_yshift, real, imaginary);
00081 }
00082 bool isColumnAvailable(size_t x) const {
00083 return m_server->isColumnReady(x << m_xshift);
00084 }
00085
00086 size_t getFillExtent() const { return m_server->getFillExtent(); }
00087
00088
00089
00090 virtual size_t getWidth() const {
00091 return m_server->getWidth() >> m_xshift;
00092 }
00093 virtual size_t getHeight() const {
00094
00095
00096
00097
00098
00099
00100 return (m_server->getHeight() >> m_yshift) + (m_yshift > 0 ? 1 : 0);
00101 }
00102 virtual float getValueAt(size_t x, size_t y) const {
00103 return const_cast<FFTModel *>(this)->getMagnitudeAt(x, y);
00104 }
00105 virtual bool isOK() const {
00106 return m_server && m_server->getModel();
00107 }
00108 virtual size_t getStartFrame() const {
00109 return 0;
00110 }
00111 virtual size_t getEndFrame() const {
00112 return getWidth() * getResolution() + getResolution();
00113 }
00114 virtual size_t getSampleRate() const;
00115 virtual size_t getResolution() const {
00116 return m_server->getWindowIncrement() << m_xshift;
00117 }
00118 virtual size_t getYBinCount() const {
00119 return getHeight();
00120 }
00121 virtual float getMinimumLevel() const {
00122 return 0.f;
00123 }
00124 virtual float getMaximumLevel() const {
00125 return 1.f;
00126 }
00127 virtual void getColumn(size_t x, Column &result) const;
00128 virtual QString getBinName(size_t n) const;
00129
00135 virtual bool estimateStableFrequency(size_t x, size_t y, float &frequency);
00136
00137 enum PeakPickType
00138 {
00139 AllPeaks,
00140 MajorPeaks,
00141 MajorPitchAdaptivePeaks
00142 };
00143
00144 typedef std::set<size_t> PeakLocationSet;
00145 typedef std::map<size_t, float> PeakSet;
00146
00151 virtual PeakLocationSet getPeaks(PeakPickType type, size_t x,
00152 size_t ymin = 0, size_t ymax = 0);
00153
00157 virtual PeakSet getPeakFrequencies(PeakPickType type, size_t x,
00158 size_t ymin = 0, size_t ymax = 0);
00159
00160 virtual int getCompletion() const { return m_server->getFillCompletion(); }
00161
00162 virtual Model *clone() const;
00163
00164 virtual void suspend() { m_server->suspend(); }
00165 virtual void suspendWrites() { m_server->suspendWrites(); }
00166 virtual void resume() { m_server->resume(); }
00167
00168 QString getTypeName() const { return tr("FFT"); }
00169
00170 public slots:
00171 void sourceModelAboutToBeDeleted();
00172
00173 private:
00174 FFTModel(const FFTModel &);
00175 FFTModel &operator=(const FFTModel &);
00176
00177 FFTDataServer *m_server;
00178 int m_xshift;
00179 int m_yshift;
00180
00181 FFTDataServer *getServer(const DenseTimeValueModel *,
00182 int, WindowType, size_t, size_t, size_t,
00183 bool, StorageAdviser::Criteria, size_t);
00184
00185 size_t getPeakPickWindowSize(PeakPickType type, size_t sampleRate,
00186 size_t bin, float &percentile) const;
00187 };
00188
00189 #endif