changeset 99:54c4b7719ff2

Simplify a bit, add some debug out
author Chris Cannam <c.cannam@qmul.ac.uk>
date Sat, 10 May 2014 13:44:24 +0100
parents fb5bcb44277a
children 3236a2a75b42
files cpp-qm-dsp/CQInverse.cpp cpp-qm-dsp/ConstantQ.cpp cpp-qm-dsp/processfile.cpp
diffstat 3 files changed, 31 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/cpp-qm-dsp/CQInverse.cpp	Sat May 10 11:57:59 2014 +0100
+++ b/cpp-qm-dsp/CQInverse.cpp	Sat May 10 13:44:24 2014 +0100
@@ -108,6 +108,8 @@
         Resampler *r = new Resampler
             (sourceRate / factor, sourceRate, 60, 0.02);
 
+        cerr << "inverse: octave " << i << ": resample from " << sourceRate/factor << " to " << sourceRate << endl;
+
 	// See ConstantQ.cpp for discussion on latency -- output
 	// latency here is at target rate which, this way around, is
 	// what we want
--- a/cpp-qm-dsp/ConstantQ.cpp	Sat May 10 11:57:59 2014 +0100
+++ b/cpp-qm-dsp/ConstantQ.cpp	Sat May 10 13:44:24 2014 +0100
@@ -110,6 +110,8 @@
         Resampler *r = new Resampler
             (sourceRate, sourceRate / factor, 60, 0.02);
 
+        cerr << "forward: octave " << i << ": resample from " << sourceRate << " to " << sourceRate / factor << endl;
+
         // We need to adapt the latencies so as to get the first input
         // sample to be aligned, in time, at the decimator output
         // across all octaves.
--- a/cpp-qm-dsp/processfile.cpp	Sat May 10 11:57:59 2014 +0100
+++ b/cpp-qm-dsp/processfile.cpp	Sat May 10 13:44:24 2014 +0100
@@ -78,6 +78,15 @@
 		 100, sfinfo.samplerate / 3,
 		 60);
 
+    cerr << "max freq = " << cq.getMaxFrequency() << ", min freq = "
+	 << cq.getMinFrequency() << ", octaves = " << cq.getOctaves() << endl;
+
+    cerr << "octave boundaries: ";
+    for (int i = 0; i < cq.getOctaves(); ++i) {
+	cerr << cq.getMaxFrequency() / pow(2, i) << " ";
+    }
+    cerr << endl;
+
     int inframe = 0;
     int outframe = 0;
     int latency = cq.getLatency() + cqi.getLatency();
@@ -116,6 +125,11 @@
 	
 	vector<double> cqout = cqi.process(cq.process(cqin));
 
+	for (int i = 0; i < int(cqout.size()); ++i) {
+	    if (cqout[i] > 1.0) cqout[i] = 1.0;
+	    if (cqout[i] < -1.0) cqout[i] = -1.0;
+	}
+
 	if (outframe >= latency) {
 
 	    sf_writef_double(sndfileOut, 
@@ -154,26 +168,24 @@
 	outframe += cqout.size();
     }
 
-    vector<double> r1 = cqi.process(cq.getRemainingOutput());
+    vector<double> r = cqi.process(cq.getRemainingOutput());
     vector<double> r2 = cqi.getRemainingOutput();
 
-    sf_writef_double(sndfileOut, r1.data(), r1.size());
+    r.insert(r.end(), r2.begin(), r2.end());
+
+    for (int i = 0; i < int(r.size()); ++i) {
+	if (r[i] > 1.0) r[i] = 1.0;
+	if (r[i] < -1.0) r[i] = -1.0;
+    }
+
+    sf_writef_double(sndfileOut, r.data(), r.size());
     if (doDiff) {
-	for (int i = 0; i < (int)r1.size(); ++i) {
-	    r1[i] -= buffer[outframe + i - latency];
+	for (int i = 0; i < (int)r.size(); ++i) {
+	    r[i] -= buffer[outframe + i - latency];
 	}
-	sf_writef_double(sndDiffFile, r1.data(), r1.size());
+	sf_writef_double(sndDiffFile, r.data(), r.size());
     }
-    outframe += r1.size();
-
-    sf_writef_double(sndfileOut, r2.data(), r2.size());
-    if (doDiff) {
-	for (int i = 0; i < (int)r2.size(); ++i) {
-	    r2[i] -= buffer[outframe + i - latency];
-	}
-	sf_writef_double(sndDiffFile, r2.data(), r2.size());
-    }
-    outframe += r2.size();
+    outframe += r.size();
 
     sf_close(sndfile);
     sf_close(sndfileOut);