comparison layer/SpectrumLayer.cpp @ 1386:fc3d89f88690 spectrogramparam

Use log-frequency rather than log-bin for calculating x coord in spectrum. This has the advantage that frequency positions don't move when we change the window size or oversampling ratio, but it does give us an unhelpfully large amount of space for very low frequencies - to be considered
author Chris Cannam
date Mon, 12 Nov 2018 11:34:34 +0000
parents 37e9d6a1e00c
children bca9870301b7
comparison
equal deleted inserted replaced
1385:37e9d6a1e00c 1386:fc3d89f88690
344 return; 344 return;
345 } 345 }
346 } 346 }
347 347
348 double 348 double
349 SpectrumLayer::getBinForFrequency(double freq) const
350 {
351 if (!m_sliceableModel) return 0;
352 double bin = (freq * getFFTSize()) / m_sliceableModel->getSampleRate();
353 // we assume the frequency of a bin corresponds to the centre of
354 // its visual range
355 bin += 0.5;
356 return bin;
357 }
358
359 double
360 SpectrumLayer::getBinForX(const LayerGeometryProvider *v, double x) const
361 {
362 if (!m_sliceableModel) return 0;
363 double bin = getBinForFrequency(getFrequencyForX(v, x));
364 return bin;
365 }
366
367 double
349 SpectrumLayer::getFrequencyForX(const LayerGeometryProvider *v, double x) const 368 SpectrumLayer::getFrequencyForX(const LayerGeometryProvider *v, double x) const
350 { 369 {
351 if (!m_sliceableModel) return 0; 370 if (!m_sliceableModel) return 0;
352 double bin = getBinForX(v, x); 371 double freq = getScalePointForX(v, x,
372 getFrequencyForBin(m_minbin),
373 getFrequencyForBin(m_maxbin));
374 return freq;
375 }
376
377 double
378 SpectrumLayer::getFrequencyForBin(double bin) const
379 {
380 if (!m_sliceableModel) return 0;
353 // we assume the frequency of a bin corresponds to the centre of 381 // we assume the frequency of a bin corresponds to the centre of
354 // its visual range 382 // its visual range
355 bin -= 0.5; 383 bin -= 0.5;
356 return (m_sliceableModel->getSampleRate() * bin) / 384 double freq = (bin * m_sliceableModel->getSampleRate()) / getFFTSize();
357 (m_sliceableModel->getHeight() * 2); 385 return freq;
386 }
387
388 double
389 SpectrumLayer::getXForBin(const LayerGeometryProvider *v, double bin) const
390 {
391 if (!m_sliceableModel) return 0;
392 double x = getXForFrequency(v, getFrequencyForBin(bin));
393 return x;
358 } 394 }
359 395
360 double 396 double
361 SpectrumLayer::getXForFrequency(const LayerGeometryProvider *v, double freq) const 397 SpectrumLayer::getXForFrequency(const LayerGeometryProvider *v, double freq) const
362 { 398 {
363 if (!m_sliceableModel) return 0; 399 if (!m_sliceableModel) return 0;
364 double bin = (freq * m_sliceableModel->getHeight() * 2) / 400 double x = getXForScalePoint(v, freq,
365 m_sliceableModel->getSampleRate(); 401 getFrequencyForBin(m_minbin),
366 // we want the centre of the bin range 402 getFrequencyForBin(m_maxbin));
367 bin += 0.5; 403 return x;
368 return getXForBin(v, bin);
369 } 404 }
370 405
371 bool 406 bool
372 SpectrumLayer::getXScaleValue(const LayerGeometryProvider *v, int x, 407 SpectrumLayer::getXScaleValue(const LayerGeometryProvider *v, int x,
373 double &value, QString &unit) const 408 double &value, QString &unit) const