diff 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
line wrap: on
line diff
--- a/data/model/FFTModel.cpp	Tue Mar 03 17:09:19 2015 +0000
+++ b/data/model/FFTModel.cpp	Wed Mar 04 12:01:04 2015 +0000
@@ -159,7 +159,7 @@
                                            fillFromColumn);
 }
 
-int
+sv_samplerate_t
 FFTModel::getSampleRate() const
 {
     return isOK() ? m_server->getModel()->getSampleRate() : 0;
@@ -198,7 +198,7 @@
 QString
 FFTModel::getBinName(int n) const
 {
-    int sr = getSampleRate();
+    sv_samplerate_t sr = getSampleRate();
     if (!sr) return "";
     QString name = tr("%1 Hz").arg((n * sr) / ((getHeight()-1) * 2));
     return name;
@@ -209,10 +209,10 @@
 {
     if (!isOK()) return false;
 
-    int sampleRate = m_server->getModel()->getSampleRate();
+    sv_samplerate_t sampleRate = m_server->getModel()->getSampleRate();
 
     int fftSize = m_server->getFFTSize() >> m_yshift;
-    frequency = float((double(y) * sampleRate) / fftSize);
+    frequency = float((y * sampleRate) / fftSize);
 
     if (x+1 >= getWidth()) return false;
 
@@ -291,7 +291,7 @@
     // exceed the median.  For pitch adaptivity, we adjust the window
     // size to a roughly constant pitch range (about four tones).
 
-    int sampleRate = getSampleRate();
+    sv_samplerate_t sampleRate = getSampleRate();
 
     std::deque<float> window;
     std::vector<int> inrange;
@@ -373,7 +373,7 @@
 }
 
 int
-FFTModel::getPeakPickWindowSize(PeakPickType type, int sampleRate,
+FFTModel::getPeakPickWindowSize(PeakPickType type, sv_samplerate_t sampleRate,
                                 int bin, float &percentile) const
 {
     percentile = 0.5;
@@ -381,7 +381,7 @@
     if (bin == 0) return 3;
 
     int fftSize = m_server->getFFTSize() >> m_yshift;
-    double binfreq = (double(sampleRate) * bin) / fftSize;
+    double binfreq = (sampleRate * bin) / fftSize;
     double hifreq = Pitch::getFrequencyForPitch(73, 0, binfreq);
 
     int hibin = int(lrint((hifreq * fftSize) / sampleRate));
@@ -403,7 +403,7 @@
     if (!isOK()) return peaks;
     PeakLocationSet locations = getPeaks(type, x, ymin, ymax);
 
-    int sampleRate = getSampleRate();
+    sv_samplerate_t sampleRate = getSampleRate();
     int fftSize = m_server->getFFTSize() >> m_yshift;
     int incr = getResolution();