comparison layer/SpectrumLayer.cpp @ 1394:4a36f6130056 spectrogramparam

Various tweaks & fixes to log-scale handling in spectrum. We can't easily preserve the nice behaviour where peaks stay in place as fft size changes, without potentially losing a bit of low-frequency information
author Chris Cannam
date Wed, 14 Nov 2018 14:17:06 +0000
parents 900bed394f5a
children 2e316a724336
comparison
equal deleted inserted replaced
1393:a0bfe366f9cb 1394:4a36f6130056
387 387
388 double 388 double
389 SpectrumLayer::getFrequencyForX(const LayerGeometryProvider *v, double x) const 389 SpectrumLayer::getFrequencyForX(const LayerGeometryProvider *v, double x) const
390 { 390 {
391 if (!m_sliceableModel) return 0; 391 if (!m_sliceableModel) return 0;
392 double freq = getScalePointForX(v, x, 392
393 getFrequencyForBin(m_minbin), 393 double fmin = getFrequencyForBin(m_minbin);
394 getFrequencyForBin(m_maxbin)); 394
395 if (m_binScale == LogBins && m_minbin == 0) {
396 // Avoid too much space going to the first bin, but do so in a
397 // way that usually avoids us shifting left/right as the
398 // window size or oversampling ratio change - i.e. base this
399 // on frequency rather than bin number unless we have a lot of
400 // very low-resolution content
401 fmin = getFrequencyForBin(0.8);
402 if (fmin > 6.0) fmin = 6.0;
403 }
404
405 double fmax = getFrequencyForBin(m_maxbin);
406
407 double freq = getScalePointForX(v, x, fmin, fmax);
395 return freq; 408 return freq;
396 } 409 }
397 410
398 double 411 double
399 SpectrumLayer::getFrequencyForBin(double bin) const 412 SpectrumLayer::getFrequencyForBin(double bin) const
416 429
417 double 430 double
418 SpectrumLayer::getXForFrequency(const LayerGeometryProvider *v, double freq) const 431 SpectrumLayer::getXForFrequency(const LayerGeometryProvider *v, double freq) const
419 { 432 {
420 if (!m_sliceableModel) return 0; 433 if (!m_sliceableModel) return 0;
421 double x = getXForScalePoint(v, freq, 434
422 getFrequencyForBin(m_minbin), 435 double fmin = getFrequencyForBin(m_minbin);
423 getFrequencyForBin(m_maxbin)); 436 if (m_binScale == LogBins && m_minbin == 0) {
437 // See comment in getFrequencyForX above
438 fmin = getFrequencyForBin(0.8);
439 if (fmin > 6.0) fmin = 6.0;
440 }
441
442 double fmax = getFrequencyForBin(m_maxbin);
443
444 double x = getXForScalePoint(v, freq, fmin, fmax);
424 return x; 445 return x;
425 } 446 }
426 447
427 bool 448 bool
428 SpectrumLayer::getXScaleValue(const LayerGeometryProvider *v, int x, 449 SpectrumLayer::getXScaleValue(const LayerGeometryProvider *v, int x,