Mercurial > hg > svgui
changeset 265:a3a54632cd4c
* fixes to spectrum harmonic cursor etc
author | Chris Cannam |
---|---|
date | Fri, 15 Jun 2007 15:48:11 +0000 |
parents | 7e9e533f1863 |
children | aee39d8c0b83 |
files | layer/SliceLayer.h layer/SpectrumLayer.cpp layer/SpectrumLayer.h |
diffstat | 3 files changed, 27 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/layer/SliceLayer.h Fri Jun 15 12:55:16 2007 +0000 +++ b/layer/SliceLayer.h Fri Jun 15 15:48:11 2007 +0000 @@ -105,8 +105,8 @@ void modelAboutToBeDeleted(Model *); protected: - float getXForBin(int bin, int totalBins, float w) const; - int getBinForX(float x, int totalBins, float w) const; + virtual float getXForBin(int bin, int totalBins, float w) const; + virtual int getBinForX(float x, int totalBins, float w) const; virtual QString getFeatureDescription(View *v, QPoint &, bool includeBinDescription,
--- 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;
--- a/layer/SpectrumLayer.h Fri Jun 15 12:55:16 2007 +0000 +++ b/layer/SpectrumLayer.h Fri Jun 15 15:48:11 2007 +0000 @@ -100,6 +100,9 @@ virtual void getBiasCurve(BiasCurve &) const; BiasCurve m_biasCurve; + virtual float getXForBin(int bin, int totalBins, float w) const; + virtual int getBinForX(float x, int totalBins, float w) const; + float getFrequencyForX(float x, float w) const; float getXForFrequency(float freq, float w) const;