changeset 45:73152bc3bb26

Start to address some padding and latency issues
author Chris Cannam <c.cannam@qmul.ac.uk>
date Fri, 22 Nov 2013 14:47:41 +0000
parents 337d3b324c75
children 9c47e5beaebf
files cpp-qm-dsp/ConstantQ.cpp cpp-qm-dsp/Makefile cpp-qm-dsp/test.cpp
diffstat 3 files changed, 68 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/cpp-qm-dsp/ConstantQ.cpp	Thu Nov 21 17:04:19 2013 +0000
+++ b/cpp-qm-dsp/ConstantQ.cpp	Fri Nov 22 14:47:41 2013 +0000
@@ -174,7 +174,22 @@
 
     //!!!! need some mechanism for handling remaining samples at the end
 
-    while ((int)m_buffers[0].size() >= m_bigBlockSize) {
+    while (true) {
+
+	// We could have quite different remaining sample counts in
+	// different octaves, because (apart from the predictable
+	// added counts for decimator output on each block) we also
+	// have variable additional latency per octave
+	bool enough = true;
+	for (int i = 0; i < m_octaves; ++i) {
+	    int required = m_p.fftSize * pow(2, m_octaves - i - 1);
+	    cerr << "for octave " << i << ", buf len =  "<< m_buffers[i].size() << " (need " << required << ")" << endl;
+
+	    if ((int)m_buffers[i].size() < required) {
+		enough = false;
+	    }
+	}
+	if (!enough) break;
 
         int base = out.size();
         int totalColumns = pow(2, m_octaves - 1) * m_p.atomsPerFrame;
@@ -216,9 +231,29 @@
 vector<vector<double> >
 ConstantQ::getRemainingBlocks()
 {
-    int n = m_bigBlockSize + m_bigBlockSize - m_buffers[0].size();
-    vector<double> pad(n, 0.0);
-    return process(pad);
+/*    int n = 0;
+    for (int i = 0; i < m_octaves; ++i) {
+	int latency = 0;
+	if (i > 0) latency = m_decimators[i]->getLatency() * pow(2, i);
+	if (latency > n) n = latency;
+    }
+*/
+    int n = ceil(double(m_totalLatency) / m_bigBlockSize) * m_bigBlockSize;
+/*
+	int blockSize = m_p.fftSize * pow(2, m_octaves - i - 1);
+	int neededHere = blockSize + blockSize - (int)m_buffers[i].size();
+	cerr << "getRemainingBlocks: neededHere = " << neededHere << endl;	
+	if (neededHere > n) n = neededHere;
+    }
+*/
+    cerr << "getRemainingBlocks: n = " << n << endl;	
+
+    if (n > 0) {
+	vector<double> pad(n, 0.0);
+	return process(pad);
+    } else {
+	return vector<vector<double> > ();
+    }
 }
 
 vector<vector<double> >
--- a/cpp-qm-dsp/Makefile	Thu Nov 21 17:04:19 2013 +0000
+++ b/cpp-qm-dsp/Makefile	Fri Nov 22 14:47:41 2013 +0000
@@ -3,8 +3,8 @@
 
 CFLAGS := -I../.. $(CFLAGS) $(DEFINES)
 
-#CXXFLAGS := -I../.. -fPIC -Wall -g $(CXXFLAGS) $(DEFINES)
-CXXFLAGS := -I../.. -fPIC -Wall -O3 -ffast-math -ftree-vectorize $(CXXFLAGS) $(DEFINES)
+CXXFLAGS := -I../.. -fPIC -Wall -g $(CXXFLAGS) $(DEFINES)
+#CXXFLAGS := -I../.. -fPIC -Wall -O3 -ffast-math -ftree-vectorize $(CXXFLAGS) $(DEFINES)
 
 LDFLAGS := $(LDFLAGS)
 
--- a/cpp-qm-dsp/test.cpp	Thu Nov 21 17:04:19 2013 +0000
+++ b/cpp-qm-dsp/test.cpp	Fri Nov 22 14:47:41 2013 +0000
@@ -6,16 +6,40 @@
 
 using std::vector;
 using std::cerr;
+using std::cout;
 using std::endl;
 
+#include <cstdio>
+
 int main(int argc, char **argv)
 {
-    ConstantQ k(48000, 50, 24000, 24);
+    vector<double> in;
 
-    vector<double> in(65536*4, 0.0);
+    for (int i = 0; i < 64; ++i) {
+	in.push_back(sin(i * M_PI / 2.0));
+    }
+
+    ConstantQ k(8, 1, 4, 4);
+
     vector<vector<double> > out = k.process(in);
+    vector<vector<double> > rest = k.getRemainingBlocks();
 
+    out.insert(out.end(), rest.begin(), rest.end());
 
-    cerr << "got " << out.size() << " back" << endl;
+    cerr << "got " << out.size() << " back (" << out[0].size() << " in each?)" << endl;
+
+    for (int b = 0; b < out.size() / 8; ++b) {
+	printf("\nColumns %d to %d:\n\n", b * 8, b * 8 + 7);
+	for (int j = int(out[0].size()) - 1; j >= 0; --j) {
+	    for (int i = 0; i < 8; ++i) {
+		if (i + b * 8 < out.size()) {
+		    double v = out[i + b * 8][j];
+		    if (v < 0.0001) printf("  0      ");
+		    else printf("  %.4f ", out[i + b * 8][j]);
+		}
+	    }
+	    printf("\n");
+	}
+    }
 }