comparison data/model/FFTModel.h @ 152:21792a550ec9 last-cc-copyright

* Move the current DenseThreeDimensionalModel to EditableDenseThreeDimensionalModel (wow!), and make DTDM an abstract base * Move FFTFuzzyAdapter to FFTModel as a new subclass of DTDM
author Chris Cannam
date Mon, 31 Jul 2006 17:05:18 +0000
parents
children 6ec58bb8f729
comparison
equal deleted inserted replaced
151:3c1d5ef43baa 152:21792a550ec9
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2
3 /*
4 Sonic Visualiser
5 An audio file viewer and annotation editor.
6 Centre for Digital Music, Queen Mary, University of London.
7 This file copyright 2006 Chris Cannam.
8
9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License as
11 published by the Free Software Foundation; either version 2 of the
12 License, or (at your option) any later version. See the file
13 COPYING included with this distribution for more information.
14 */
15
16 #ifndef _FFT_MODEL_H_
17 #define _FFT_MODEL_H_
18
19 #include "data/fft/FFTDataServer.h"
20 #include "DenseThreeDimensionalModel.h"
21
22 class FFTModel : public DenseThreeDimensionalModel
23 {
24 public:
25 FFTModel(const DenseTimeValueModel *model,
26 int channel,
27 WindowType windowType,
28 size_t windowSize,
29 size_t windowIncrement,
30 size_t fftSize,
31 bool polar,
32 size_t fillFromColumn = 0);
33 ~FFTModel();
34
35 size_t getWidth() const {
36 return m_server->getWidth() >> m_xshift;
37 }
38 size_t getHeight() const {
39 return m_server->getHeight() >> m_yshift;
40 }
41 float getMagnitudeAt(size_t x, size_t y) {
42 return m_server->getMagnitudeAt(x << m_xshift, y << m_yshift);
43 }
44 float getNormalizedMagnitudeAt(size_t x, size_t y) {
45 return m_server->getNormalizedMagnitudeAt(x << m_xshift, y << m_yshift);
46 }
47 float getMaximumMagnitudeAt(size_t x) {
48 return m_server->getMaximumMagnitudeAt(x << m_xshift);
49 }
50 float getPhaseAt(size_t x, size_t y) {
51 return m_server->getPhaseAt(x << m_xshift, y << m_yshift);
52 }
53 void getValuesAt(size_t x, size_t y, float &real, float &imaginary) {
54 m_server->getValuesAt(x << m_xshift, y << m_yshift, real, imaginary);
55 }
56 bool isColumnReady(size_t x) {
57 return m_server->isColumnReady(x << m_xshift);
58 }
59 bool isLocalPeak(size_t x, size_t y) {
60 float mag = getMagnitudeAt(x, y);
61 if (y > 0 && mag < getMagnitudeAt(x, y - 1)) return false;
62 if (y < getHeight() - 1 && mag < getMagnitudeAt(x, y + 1)) return false;
63 return true;
64 }
65 bool isOverThreshold(size_t x, size_t y, float threshold) {
66 return getMagnitudeAt(x, y) > threshold;
67 }
68
69 size_t getFillExtent() const { return m_server->getFillExtent(); }
70
71 // DenseThreeDimensionalModel and Model methods:
72 //
73 virtual bool isOK() const {
74 return m_server && m_server->getModel();
75 }
76 virtual size_t getStartFrame() const {
77 return 0;
78 }
79 virtual size_t getEndFrame() const {
80 return getWidth() * getResolution() + getResolution();
81 }
82 virtual size_t getSampleRate() const;
83 virtual size_t getResolution() const {
84 return m_server->getWindowIncrement() << m_xshift;
85 }
86 virtual size_t getYBinCount() const {
87 return getHeight();
88 }
89 virtual float getMinimumLevel() const {
90 return 0.f; // Can't provide
91 }
92 virtual float getMaximumLevel() const {
93 return 1.f; // Can't provide
94 }
95 virtual void getBinValues(long windowStartFrame, BinValueSet &result) const;
96 virtual float getBinValue(long windowStartFrame, size_t n) const;
97 virtual QString getBinName(size_t n) const;
98
99 virtual int getCompletion() const { return m_server->getFillCompletion(); }
100
101 virtual Model *clone() const;
102
103 private:
104 FFTModel(const FFTModel &);
105 FFTModel &operator=(const FFTModel &); // not implemented
106
107 FFTDataServer *m_server;
108 int m_xshift;
109 int m_yshift;
110 };
111
112 #endif