changeset 48:16e02c47bfe9

Towards handling the hop alignment (which in the MATLAB is handled on output) at the input end
author Chris Cannam <c.cannam@qmul.ac.uk>
date Thu, 28 Nov 2013 10:24:57 +0000
parents 3d6397e43671
children 0cecb0f8455b
files cpp-qm-dsp/CQKernel.cpp cpp-qm-dsp/ConstantQ.cpp cpp-qm-dsp/ConstantQ.h cpp-qm-dsp/test.cpp
diffstat 4 files changed, 36 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/cpp-qm-dsp/CQKernel.cpp	Wed Nov 27 14:14:10 2013 +0000
+++ b/cpp-qm-dsp/CQKernel.cpp	Thu Nov 28 10:24:57 2013 +0000
@@ -58,10 +58,14 @@
     m_p.atomsPerFrame = floor
         (1.0 + (m_p.fftSize - ceil(maxNK / 2.0) - m_p.firstCentre) / m_p.atomSpacing);
 
+    cerr << "atomsPerFrame = " << m_p.atomsPerFrame << " (atomHopFactor = " << atomHopFactor << ")" << endl;
+
     int lastCentre = m_p.firstCentre + (m_p.atomsPerFrame - 1) * m_p.atomSpacing;
 
     m_p.fftHop = (lastCentre + m_p.atomSpacing) - m_p.firstCentre;
 
+    cerr << "fftHop = " << m_p.fftHop << endl;
+
     m_fft = new FFT(m_p.fftSize);
 
     for (int k = 1; k <= m_p.binsPerOctave; ++k) {
--- a/cpp-qm-dsp/ConstantQ.cpp	Wed Nov 27 14:14:10 2013 +0000
+++ b/cpp-qm-dsp/ConstantQ.cpp	Thu Nov 28 10:24:57 2013 +0000
@@ -118,14 +118,31 @@
 
     cerr << "max actual latency = " << maxLatency << endl;
     
-    m_totalLatency = ceil(double(maxLatency) / m_bigBlockSize) * m_bigBlockSize;
+    // Now add in the extra padding and compensate for hops that must
+    // be dropped in order to align the atom centres across octaves
+
+    int emptyHops = m_p.firstCentre / m_p.atomSpacing; //!!! round?
+
+    vector<int> drops;
+    for (int i = 0; i < m_octaves; ++i) {
+	//!!! simplify
+	int factor = pow(2, i);
+	int dropHops = emptyHops * pow(2, m_octaves - i - 1) - emptyHops;
+	int drop = ((dropHops * m_p.fftHop) * factor) / m_p.atomsPerFrame;
+	cerr << "octave " << i << " dropHops = " << dropHops << " drop = " << drop << endl;
+	drops.push_back(drop);
+//	drops.push_back(0);
+    }
+
+    int maxDrop = *std::max_element(drops.begin(), drops.end());
+    cerr << "maxDrop " << maxDrop << endl;
+    
+    m_totalLatency = ceil(double(maxLatency + maxDrop) / m_bigBlockSize) * m_bigBlockSize;
 
 //    m_totalLatency = MathUtilities::nextPowerOfTwo(maxLatency);
     cerr << "total latency = " << m_totalLatency << endl;
         //!!! should also round up so that total latency is a multiple of the big block size
 
-    int emptyHops = m_p.firstCentre / m_p.atomSpacing; //!!! round?
-
     for (int i = 0; i < m_octaves; ++i) {
 
 	double factor = pow(2, i);
@@ -136,7 +153,7 @@
 	// and then convert it back into the sample rate appropriate
 	// for the output latency of this decimator.
 
-	double extraLatency = double(m_totalLatency - latencies[i]) / factor;
+	double extraLatency = double(m_totalLatency - latencies[i] - drops[i]) / factor;
 
         int pad = m_p.fftSize * pow(2, m_octaves-i-1);
 
@@ -151,9 +168,9 @@
 
 
 
-	cerr << "for octave " << i << ", latency for decimator = " << extraLatency << ", fixed padding = " << pad << ", visual inspection pad = " << pad2 << ", hops to drop would be " << drop << ", 2^i = " << pow(2, i) << ", 2^o-i = " << pow(2,m_octaves-i-1) << endl;
+	cerr << "for octave " << i << ", latency for decimator = " << extraLatency << ", fixed padding = " << pad << ", visual inspection pad = " << pad2 << ", hops to drop would be " << drop << " from emptyHops = " << emptyHops << ", 2^i = " << pow(2, i) << ", 2^o-i = " << pow(2,m_octaves-i-1) << endl;
 
-	extraLatency += pad + pad2;
+	extraLatency += pad ;//+ pad2;
 
 	cerr << "then extraLatency -> " << extraLatency << endl;
 
@@ -271,6 +288,13 @@
     vector<double> ro(m_p.fftSize, 0.0);
     vector<double> io(m_p.fftSize, 0.0);
 
+    cerr << "octave " << octave << " time-domain data, first hop's worth:" << endl;
+    for (int i = 0; i < m_p.fftHop; ++i) {
+	cerr << m_buffers[octave][i] << " ";
+	if (fabs(m_buffers[octave][i]) > 0.01) cerr << "** ";
+    }
+    cerr << endl;
+
     m_fft->forward(m_buffers[octave].data(), ro.data(), io.data());
 
     vector<double> shifted;
--- a/cpp-qm-dsp/ConstantQ.h	Wed Nov 27 14:14:10 2013 +0000
+++ b/cpp-qm-dsp/ConstantQ.h	Thu Nov 28 10:24:57 2013 +0000
@@ -42,7 +42,6 @@
 
     std::vector<Resampler *> m_decimators;
     std::vector<std::vector<double> > m_buffers;
-    std::vector<int> m_dropHops;
 
     int m_totalLatency;
 
--- a/cpp-qm-dsp/test.cpp	Wed Nov 27 14:14:10 2013 +0000
+++ b/cpp-qm-dsp/test.cpp	Thu Nov 28 10:24:57 2013 +0000
@@ -16,6 +16,8 @@
     vector<double> in;
 
     for (int i = 0; i < 64; ++i) {
+//	if (i == 0) in.push_back(1);
+//	else in.push_back(0);
 	in.push_back(sin(i * M_PI / 2.0));
     }