comparison data/model/FFTModel.cpp @ 1045:1a73618b0b67 cxx11

More type fixes, primarily in the spectrogram
author Chris Cannam
date Tue, 10 Mar 2015 10:31:27 +0000
parents a1cd5abcb38b
children 0fd3661bcfff
comparison
equal deleted inserted replaced
1044:31f01931b781 1045:1a73618b0b67
34 int windowSize, 34 int windowSize,
35 int windowIncrement, 35 int windowIncrement,
36 int fftSize, 36 int fftSize,
37 bool polar, 37 bool polar,
38 StorageAdviser::Criteria criteria, 38 StorageAdviser::Criteria criteria,
39 int fillFromColumn) : 39 sv_frame_t fillFromFrame) :
40 //!!! ZoomConstraint! 40 //!!! ZoomConstraint!
41 m_server(0), 41 m_server(0),
42 m_xshift(0), 42 m_xshift(0),
43 m_yshift(0) 43 m_yshift(0)
44 { 44 {
50 windowSize, 50 windowSize,
51 windowIncrement, 51 windowIncrement,
52 fftSize, 52 fftSize,
53 polar, 53 polar,
54 criteria, 54 criteria,
55 fillFromColumn); 55 fillFromFrame);
56 56
57 if (!m_server) return; // caller should check isOK() 57 if (!m_server) return; // caller should check isOK()
58 58
59 int xratio = windowIncrement / m_server->getWindowIncrement(); 59 int xratio = windowIncrement / m_server->getWindowIncrement();
60 int yratio = m_server->getFFTSize() / fftSize; 60 int yratio = m_server->getFFTSize() / fftSize;
108 int windowSize, 108 int windowSize,
109 int windowIncrement, 109 int windowIncrement,
110 int fftSize, 110 int fftSize,
111 bool polar, 111 bool polar,
112 StorageAdviser::Criteria criteria, 112 StorageAdviser::Criteria criteria,
113 int fillFromColumn) 113 sv_frame_t fillFromFrame)
114 { 114 {
115 // Obviously, an FFT model of channel C (where C != -1) of an 115 // Obviously, an FFT model of channel C (where C != -1) of an
116 // aggregate model is the same as the FFT model of the appropriate 116 // aggregate model is the same as the FFT model of the appropriate
117 // channel of whichever model that aggregate channel is drawn 117 // channel of whichever model that aggregate channel is drawn
118 // from. We should use that model here, in case we already have 118 // from. We should use that model here, in case we already have
140 windowSize, 140 windowSize,
141 windowIncrement, 141 windowIncrement,
142 fftSize, 142 fftSize,
143 polar, 143 polar,
144 criteria, 144 criteria,
145 fillFromColumn); 145 fillFromFrame);
146 } 146 }
147 } 147 }
148 148
149 // The normal case 149 // The normal case
150 150
154 windowSize, 154 windowSize,
155 windowIncrement, 155 windowIncrement,
156 fftSize, 156 fftSize,
157 polar, 157 polar,
158 criteria, 158 criteria,
159 fillFromColumn); 159 fillFromFrame);
160 } 160 }
161 161
162 sv_samplerate_t 162 sv_samplerate_t
163 FFTModel::getSampleRate() const 163 FFTModel::getSampleRate() const
164 { 164 {
203 QString name = tr("%1 Hz").arg((n * sr) / ((getHeight()-1) * 2)); 203 QString name = tr("%1 Hz").arg((n * sr) / ((getHeight()-1) * 2));
204 return name; 204 return name;
205 } 205 }
206 206
207 bool 207 bool
208 FFTModel::estimateStableFrequency(int x, int y, float &frequency) 208 FFTModel::estimateStableFrequency(int x, int y, double &frequency)
209 { 209 {
210 if (!isOK()) return false; 210 if (!isOK()) return false;
211 211
212 sv_samplerate_t sampleRate = m_server->getModel()->getSampleRate(); 212 sv_samplerate_t sampleRate = m_server->getModel()->getSampleRate();
213 213
214 int fftSize = m_server->getFFTSize() >> m_yshift; 214 int fftSize = m_server->getFFTSize() >> m_yshift;
215 frequency = float((y * sampleRate) / fftSize); 215 frequency = double(y * sampleRate) / fftSize;
216 216
217 if (x+1 >= getWidth()) return false; 217 if (x+1 >= getWidth()) return false;
218 218
219 // At frequency f, a phase shift of 2pi (one cycle) happens in 1/f sec. 219 // At frequency f, a phase shift of 2pi (one cycle) happens in 1/f sec.
220 // At hopsize h and sample rate sr, one hop happens in h/sr sec. 220 // At hopsize h and sample rate sr, one hop happens in h/sr sec.
238 238
239 // The new frequency estimate based on the phase error resulting 239 // The new frequency estimate based on the phase error resulting
240 // from assuming the "native" frequency of this bin 240 // from assuming the "native" frequency of this bin
241 241
242 frequency = 242 frequency =
243 float((sampleRate * (expectedPhase + phaseError - oldPhase)) / 243 (sampleRate * (expectedPhase + phaseError - oldPhase)) /
244 (2 * M_PI * incr)); 244 (2.0 * M_PI * incr);
245 245
246 return true; 246 return true;
247 } 247 }
248 248
249 FFTModel::PeakLocationSet 249 FFTModel::PeakLocationSet
428 double frequency = 428 double frequency =
429 (sampleRate * (expectedPhase + phaseError - oldPhase)) 429 (sampleRate * (expectedPhase + phaseError - oldPhase))
430 / (2 * M_PI * incr); 430 / (2 * M_PI * incr);
431 // bool stable = (fabsf(phaseError) < (1.1f * (incr * M_PI) / fftSize)); 431 // bool stable = (fabsf(phaseError) < (1.1f * (incr * M_PI) / fftSize));
432 // if (stable) 432 // if (stable)
433 peaks[*i] = float(frequency); 433 peaks[*i] = frequency;
434 ++phaseIndex; 434 ++phaseIndex;
435 } 435 }
436 436
437 return peaks; 437 return peaks;
438 } 438 }