Mercurial > hg > svgui
diff layer/SpectrumLayer.cpp @ 265:a3a54632cd4c
* fixes to spectrum harmonic cursor etc
author | Chris Cannam |
---|---|
date | Fri, 15 Jun 2007 15:48:11 +0000 |
parents | 7e9e533f1863 |
children | 4ed1446ad604 |
line wrap: on
line diff
--- a/layer/SpectrumLayer.cpp Fri Jun 15 12:55:16 2007 +0000 +++ b/layer/SpectrumLayer.cpp Fri Jun 15 15:48:11 2007 +0000 @@ -256,6 +256,28 @@ } float +SpectrumLayer::getXForBin(int bin, int totalBins, float w) const +{ + if (!m_sliceableModel) return SliceLayer::getXForBin(bin, totalBins, w); + + float sampleRate = m_sliceableModel->getSampleRate(); + float binfreq = (sampleRate * bin) / (totalBins * 2); + + return getXForFrequency(binfreq, w); +} + +int +SpectrumLayer::getBinForX(float x, int totalBins, float w) const +{ + if (!m_sliceableModel) return SliceLayer::getBinForX(x, totalBins, w); + + float sampleRate = m_sliceableModel->getSampleRate(); + float binfreq = getFrequencyForX(x, w); + + return int((binfreq * totalBins * 2) / sampleRate); +} + +float SpectrumLayer::getFrequencyForX(float x, float w) const { float freq = 0;