changeset 1790:dd51797e528e time-frequency-boxes

Some tidying
author Chris Cannam
date Wed, 25 Sep 2019 09:43:34 +0100
parents baafe1bb7e51
children c2388289fce8
files data/model/FFTModel.cpp data/model/FFTModel.h
diffstat 2 files changed, 40 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/data/model/FFTModel.cpp	Fri Sep 20 14:18:38 2019 +0100
+++ b/data/model/FFTModel.cpp	Wed Sep 25 09:43:34 2019 +0100
@@ -106,12 +106,6 @@
     return c;
 }
 
-sv_samplerate_t
-FFTModel::getSampleRate() const
-{
-    return m_sampleRate;
-}
-
 void
 FFTModel::setMaximumFrequency(double freq)
 {
@@ -143,10 +137,13 @@
 QString
 FFTModel::getBinName(int n) const
 {
-    sv_samplerate_t sr = getSampleRate();
-    if (!sr) return "";
-    QString name = tr("%1 Hz").arg((double(n) * sr) / m_fftSize);
-    return name;
+    return tr("%1 Hz").arg(getBinValue(n));
+}
+
+float
+FFTModel::getBinValue(int n) const
+{
+    return float((m_sampleRate * n) / m_fftSize);
 }
 
 FFTModel::Column
--- a/data/model/FFTModel.h	Fri Sep 20 14:18:38 2019 +0100
+++ b/data/model/FFTModel.h	Wed Sep 25 09:43:34 2019 +0100
@@ -60,26 +60,45 @@
 
     // DenseThreeDimensionalModel and Model methods:
     //
+    bool isOK() const override;
+    int getCompletion() const override;
+    
     int getWidth() const override;
     int getHeight() const override;
-    float getValueAt(int x, int y) const override { return getMagnitudeAt(x, y); }
-    bool isOK() const override;
-    sv_frame_t getStartFrame() const override { return 0; }
+    
+    float getValueAt(int x, int y) const override {
+        return getMagnitudeAt(x, y);
+    }
+    sv_frame_t getStartFrame() const override {
+        return 0;
+    }
     sv_frame_t getTrueEndFrame() const override {
         return sv_frame_t(getWidth()) * getResolution() + getResolution();
     }
-    sv_samplerate_t getSampleRate() const override;
-    int getResolution() const override { return m_windowIncrement; }
-    virtual int getYBinCount() const { return getHeight(); }
+    sv_samplerate_t getSampleRate() const override {
+        return m_sampleRate;
+    }
+    int getResolution() const override {
+        return m_windowIncrement;
+    }
+    
     float getMinimumLevel() const override { return 0.f; } // Can't provide
     float getMaximumLevel() const override { return 1.f; } // Can't provide
+
     Column getColumn(int x) const override; // magnitudes
-    virtual Column getPhases(int x) const;
+
+    bool hasBinValues() const override {
+        return true;
+    }
+    QString getBinValueUnit() const override {
+        return "Hz";
+    }
+    bool shouldUseLogValueScale() const override {
+        return true;
+    }
+    float getBinValue(int n) const override;
     QString getBinName(int n) const override;
-    bool shouldUseLogValueScale() const override { return true; }
-    int getCompletion() const override;
-    virtual QString getError() const { return m_error; }
-    virtual sv_frame_t getFillExtent() const { return getEndFrame(); }
+
     QString toDelimitedDataString(QString, DataExportOptions,
                                   sv_frame_t, sv_frame_t) const override {
         return "";
@@ -87,6 +106,8 @@
 
     // FFTModel methods:
     //
+    QString getError() const { return m_error; }
+
     int getChannel() const { return m_channel; }
     WindowType getWindowType() const { return m_windowType; }
     int getWindowSize() const { return m_windowSize; }
@@ -100,6 +121,7 @@
     
     float getMagnitudeAt(int x, int y) const;
     float getMaximumMagnitudeAt(int x) const;
+    Column getPhases(int x) const;
     float getPhaseAt(int x, int y) const;
     void getValuesAt(int x, int y, float &real, float &imaginary) const;
     bool getMagnitudesAt(int x, float *values, int minbin = 0, int count = 0) const;