Mercurial > hg > svcore
comparison data/model/FFTModel.cpp @ 1040:a1cd5abcb38b cxx11
Introduce and use a samplerate type
author | Chris Cannam |
---|---|
date | Wed, 04 Mar 2015 12:01:04 +0000 |
parents | cc27f35aa75c |
children | 1a73618b0b67 |
comparison
equal
deleted
inserted
replaced
1039:b14064bd1f97 | 1040:a1cd5abcb38b |
---|---|
157 polar, | 157 polar, |
158 criteria, | 158 criteria, |
159 fillFromColumn); | 159 fillFromColumn); |
160 } | 160 } |
161 | 161 |
162 int | 162 sv_samplerate_t |
163 FFTModel::getSampleRate() const | 163 FFTModel::getSampleRate() const |
164 { | 164 { |
165 return isOK() ? m_server->getModel()->getSampleRate() : 0; | 165 return isOK() ? m_server->getModel()->getSampleRate() : 0; |
166 } | 166 } |
167 | 167 |
196 } | 196 } |
197 | 197 |
198 QString | 198 QString |
199 FFTModel::getBinName(int n) const | 199 FFTModel::getBinName(int n) const |
200 { | 200 { |
201 int sr = getSampleRate(); | 201 sv_samplerate_t sr = getSampleRate(); |
202 if (!sr) return ""; | 202 if (!sr) return ""; |
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, float &frequency) |
209 { | 209 { |
210 if (!isOK()) return false; | 210 if (!isOK()) return false; |
211 | 211 |
212 int 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((double(y) * sampleRate) / fftSize); | 215 frequency = float((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. |
289 // For peak picking we use a moving median window, picking the | 289 // For peak picking we use a moving median window, picking the |
290 // highest value within each continuous region of values that | 290 // highest value within each continuous region of values that |
291 // exceed the median. For pitch adaptivity, we adjust the window | 291 // exceed the median. For pitch adaptivity, we adjust the window |
292 // size to a roughly constant pitch range (about four tones). | 292 // size to a roughly constant pitch range (about four tones). |
293 | 293 |
294 int sampleRate = getSampleRate(); | 294 sv_samplerate_t sampleRate = getSampleRate(); |
295 | 295 |
296 std::deque<float> window; | 296 std::deque<float> window; |
297 std::vector<int> inrange; | 297 std::vector<int> inrange; |
298 float dist = 0.5; | 298 float dist = 0.5; |
299 | 299 |
371 | 371 |
372 return peaks; | 372 return peaks; |
373 } | 373 } |
374 | 374 |
375 int | 375 int |
376 FFTModel::getPeakPickWindowSize(PeakPickType type, int sampleRate, | 376 FFTModel::getPeakPickWindowSize(PeakPickType type, sv_samplerate_t sampleRate, |
377 int bin, float &percentile) const | 377 int bin, float &percentile) const |
378 { | 378 { |
379 percentile = 0.5; | 379 percentile = 0.5; |
380 if (type == MajorPeaks) return 10; | 380 if (type == MajorPeaks) return 10; |
381 if (bin == 0) return 3; | 381 if (bin == 0) return 3; |
382 | 382 |
383 int fftSize = m_server->getFFTSize() >> m_yshift; | 383 int fftSize = m_server->getFFTSize() >> m_yshift; |
384 double binfreq = (double(sampleRate) * bin) / fftSize; | 384 double binfreq = (sampleRate * bin) / fftSize; |
385 double hifreq = Pitch::getFrequencyForPitch(73, 0, binfreq); | 385 double hifreq = Pitch::getFrequencyForPitch(73, 0, binfreq); |
386 | 386 |
387 int hibin = int(lrint((hifreq * fftSize) / sampleRate)); | 387 int hibin = int(lrint((hifreq * fftSize) / sampleRate)); |
388 int medianWinSize = hibin - bin; | 388 int medianWinSize = hibin - bin; |
389 if (medianWinSize < 3) medianWinSize = 3; | 389 if (medianWinSize < 3) medianWinSize = 3; |
401 | 401 |
402 PeakSet peaks; | 402 PeakSet peaks; |
403 if (!isOK()) return peaks; | 403 if (!isOK()) return peaks; |
404 PeakLocationSet locations = getPeaks(type, x, ymin, ymax); | 404 PeakLocationSet locations = getPeaks(type, x, ymin, ymax); |
405 | 405 |
406 int sampleRate = getSampleRate(); | 406 sv_samplerate_t sampleRate = getSampleRate(); |
407 int fftSize = m_server->getFFTSize() >> m_yshift; | 407 int fftSize = m_server->getFFTSize() >> m_yshift; |
408 int incr = getResolution(); | 408 int incr = getResolution(); |
409 | 409 |
410 // This duplicates some of the work of estimateStableFrequency to | 410 // This duplicates some of the work of estimateStableFrequency to |
411 // allow us to retrieve the phases in two separate vertical | 411 // allow us to retrieve the phases in two separate vertical |