changeset 57:65575499e4b9

Fix min frequency calculation in accessor, add bin frequency accessor
author Chris Cannam <c.cannam@qmul.ac.uk>
date Thu, 30 Jan 2014 12:11:53 +0000
parents e2b7f7462618
children daf7c92058da
files cpp-qm-dsp/ConstantQ.cpp cpp-qm-dsp/ConstantQ.h
diffstat 2 files changed, 17 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/cpp-qm-dsp/ConstantQ.cpp	Thu Jan 30 10:33:38 2014 +0000
+++ b/cpp-qm-dsp/ConstantQ.cpp	Thu Jan 30 12:11:53 2014 +0000
@@ -45,15 +45,22 @@
     delete m_kernel;
 }
 
+double
+ConstantQ::getMinFrequency() const
+{
+    return m_p.minFrequency / pow(2.0, m_octaves - 1);
+}
+
+double
+ConstantQ::getBinFrequency(int bin) const
+{
+    return getMinFrequency() * pow(2, (double(bin) / getBinsPerOctave()));
+}
+
 void
 ConstantQ::initialise()
 {
     m_octaves = int(ceil(log2(m_maxFrequency / m_minFrequency)));
-    double actualMinFreq =
-        (m_maxFrequency / pow(2.0, m_octaves)) * pow(2.0, 1.0/m_binsPerOctave);
-
-//    cerr << "actual min freq = " << actualMinFreq << endl;
-
     m_kernel = new CQKernel(m_sampleRate, m_maxFrequency, m_binsPerOctave);
     m_p = m_kernel->getProperties();
     
@@ -238,7 +245,7 @@
             }
         }
     }
-    
+
     return out;
 }
 
@@ -272,7 +279,7 @@
 
     vector<C> cqrowvec = m_kernel->process(cv);
 
-    // Reform into a column matrix 
+    // Reform into a column matrix
     vector<vector<double> > cqblock;
     for (int j = 0; j < m_p.atomsPerFrame; ++j) {
         cqblock.push_back(vector<double>());
--- a/cpp-qm-dsp/ConstantQ.h	Thu Jan 30 10:33:38 2014 +0000
+++ b/cpp-qm-dsp/ConstantQ.h	Thu Jan 30 12:11:53 2014 +0000
@@ -19,13 +19,14 @@
     ~ConstantQ();
 
     double getSampleRate() const { return m_sampleRate; }
-    double getMaxFrequency() const { return m_p.maxFrequency; }
-    double getMinFrequency() const { return m_p.minFrequency; } // actual min, not that provided to ctor
     int getBinsPerOctave() const { return m_binsPerOctave; }
     int getOctaves() const { return m_octaves; }
     int getTotalBins() const { return m_octaves * m_binsPerOctave; }
     int getColumnHop() const { return m_p.fftHop / m_p.atomsPerFrame; }
     int getLatency() const { return m_outputLatency; } 
+    double getMaxFrequency() const { return m_p.maxFrequency; }
+    double getMinFrequency() const; // actual min, not that passed to ctor
+    double getBinFrequency(int bin) const;
 
     std::vector<std::vector<double> > process(const std::vector<double> &);
     std::vector<std::vector<double> > getRemainingBlocks();