comparison data/model/FFTModel.h @ 1091:bdebff3265ae simple-fft-model

Simplest naive FFTModel implementation (+ fill in tests)
author Chris Cannam
date Fri, 12 Jun 2015 18:08:57 +0100
parents 420fc961c0c4
children 70f18770b72d
comparison
equal deleted inserted replaced
1090:420fc961c0c4 1091:bdebff3265ae
19 #include "DenseThreeDimensionalModel.h" 19 #include "DenseThreeDimensionalModel.h"
20 #include "DenseTimeValueModel.h" 20 #include "DenseTimeValueModel.h"
21 21
22 #include "base/Window.h" 22 #include "base/Window.h"
23 23
24 #include "data/fft/FFTapi.h"
25
24 #include <set> 26 #include <set>
25 #include <map> 27 #include <map>
28 #include <vector>
29 #include <complex>
26 30
27 /** 31 /**
28 * An implementation of DenseThreeDimensionalModel that makes FFT data 32 * An implementation of DenseThreeDimensionalModel that makes FFT data
29 * derived from a DenseTimeValueModel available as a generic data 33 * derived from a DenseTimeValueModel available as a generic data
30 * grid. 34 * grid.
86 int getWindowSize() const { return m_windowSize; } 90 int getWindowSize() const { return m_windowSize; }
87 int getWindowIncrement() const { return m_windowIncrement; } 91 int getWindowIncrement() const { return m_windowIncrement; }
88 int getFFTSize() const { return m_fftSize; } 92 int getFFTSize() const { return m_fftSize; }
89 93
90 float getMagnitudeAt(int x, int y) const; 94 float getMagnitudeAt(int x, int y) const;
91 float getNormalizedMagnitudeAt(int x, int y) const;
92 float getMaximumMagnitudeAt(int x) const; 95 float getMaximumMagnitudeAt(int x) const;
93 float getPhaseAt(int x, int y) const; 96 float getPhaseAt(int x, int y) const;
94 void getValuesAt(int x, int y, float &real, float &imaginary) const; 97 void getValuesAt(int x, int y, float &real, float &imaginary) const;
95 bool isColumnAvailable(int x) const; 98 bool isColumnAvailable(int x) const;
96 bool getMagnitudesAt(int x, float *values, int minbin = 0, int count = 0) const; 99 bool getMagnitudesAt(int x, float *values, int minbin = 0, int count = 0) const;
142 WindowType m_windowType; 145 WindowType m_windowType;
143 int m_windowSize; 146 int m_windowSize;
144 int m_windowIncrement; 147 int m_windowIncrement;
145 int m_fftSize; 148 int m_fftSize;
146 Window<float> m_windower; 149 Window<float> m_windower;
150 FFTForward m_fft;
147 151
148 int getPeakPickWindowSize(PeakPickType type, sv_samplerate_t sampleRate, 152 int getPeakPickWindowSize(PeakPickType type, sv_samplerate_t sampleRate,
149 int bin, float &percentile) const; 153 int bin, float &percentile) const;
154
155 std::pair<sv_frame_t, sv_frame_t> getSourceSampleRange(int column) const {
156 sv_frame_t startFrame = m_windowIncrement * sv_frame_t(column);
157 sv_frame_t endFrame = startFrame + m_windowSize;
158 // Cols are centred on the audio sample (e.g. col 0 is centred at sample 0)
159 startFrame -= m_windowSize / 2;
160 endFrame -= m_windowSize / 2;
161 return { startFrame, endFrame };
162 }
163
164 std::vector<std::complex<float> > getFFTColumn(int column) const;
165 std::vector<float> getSourceSamples(int column) const;
150 }; 166 };
151 167
152 #endif 168 #endif