changeset 78:4a3005934850

Try chaining the resamplers
author Chris Cannam <c.cannam@qmul.ac.uk>
date Fri, 04 Apr 2014 13:50:27 +0100
parents f2d747d234d5
children 021f69b2987a
files cpp-qm-dsp/ConstantQ.cpp
diffstat 1 files changed, 7 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/cpp-qm-dsp/ConstantQ.cpp	Fri Apr 04 13:29:16 2014 +0100
+++ b/cpp-qm-dsp/ConstantQ.cpp	Fri Apr 04 13:50:27 2014 +0100
@@ -111,8 +111,10 @@
 
         int factor = pow(2, i);
 
+        // Each octave uses an identical fs/2 resampler fed with the
+        // output from that of the octave above
         Resampler *r = new Resampler
-            (sourceRate, sourceRate / factor, 60, 0.02);
+            (sourceRate, sourceRate / 2, 60, 0.02);
 
         // We need to adapt the latencies so as to get the first input
         // sample to be aligned, in time, at the decimator output
@@ -144,7 +146,7 @@
 	// use that to compensate in a moment, when we've discovered
 	// what the longest latency across all octaves is.
 
-        latencies.push_back(r->getLatency() * factor);
+        latencies.push_back(r->getLatency() + latencies[i-1]);
         m_decimators.push_back(r);
     }
 
@@ -220,8 +222,10 @@
 {
     m_buffers[0].insert(m_buffers[0].end(), td.begin(), td.end());
 
+    vector<double> dec(td);
+
     for (int i = 1; i < m_octaves; ++i) {
-        vector<double> dec = m_decimators[i]->process(td.data(), td.size());
+        dec = m_decimators[i]->process(dec.data(), dec.size());
         m_buffers[i].insert(m_buffers[i].end(), dec.begin(), dec.end());
     }