changeset 411:3ee42c8029fb resample

Fix wrong args to columnSlice
author Chris Cannam
date Sat, 28 Sep 2013 19:11:39 +0100
parents ad99cd603b75
children aad4c4136321
files src/may/stream/resample.yeti
diffstat 1 files changed, 17 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/src/may/stream/resample.yeti	Fri Sep 27 19:24:00 2013 +0100
+++ b/src/may/stream/resample.yeti	Sat Sep 28 19:11:39 2013 +0100
@@ -55,7 +55,6 @@
         nzc = 13;
         attenuation = 80;
         filter = kaiserSincWindow nzc factor attenuation;
-//        println "interpolated: filter length \(vec.length filter)";
         out = adjuster
            (manip.delayedBy (- (nzc * factor))
                (convolve.convolvedWith [Framesize 1024]
@@ -131,7 +130,7 @@
     // exclude... what?
 
     //!!! ponder
-
+/*
     filt = kaiserSincFilterFor {
         n = peakToPole,
         attenuation = 140,
@@ -139,15 +138,15 @@
         bandwidth = lower / 100,
         samplerate = lower
     };
+*/
 
-/*
     filt = kaiserSincFilterFor {
         n = peakToPole, 
         attenuation = 80, 
         bandwidth = 1, 
         samplerate = higher
     };
-*/
+
     // Now we have a filter of (odd) length flen in which the lower
     // sample rate corresponds to every n'th point and the higher rate
     // to every m'th where n and m are higher and lower rates divided
@@ -188,13 +187,11 @@
     halflen = int (flen/2); // actual filter length is halflen + halflen + 1
     spacedInput = manip.spaced (targetRate / g) s;
     
-    initialFill = spacedInput.read halflen;
-
-    println "initialFill = \(initialFill) (requested \(halflen))";
+    initialFill = spacedInput.read (halflen + 1);
 
     var buffer = mat.toRowMajor
        (mat.concat (Horizontal ())
-           [mat.zeroMatrix { rows = s.channels, columns = halflen + 1 },
+           [mat.zeroMatrix { rows = s.channels, columns = halflen },
             initialFill]);
     var pos = 0;
 
@@ -205,15 +202,17 @@
         esac;
 
     reconstructOne ch =
-       (var out = 0;
-        var series = mat.getRow ch buffer; //!!! check this has length flen
+       (series = mat.getRow ch buffer;
+        var out = 0;
         for [0..(vec.length series)-1] do i:
             x = vec.at series i;
             if x != 0 then
                 out := out + x * (vec.at filt i);
             fi;
         done;
-        out);
+        if sourceRate <= targetRate then out
+        else out / (sourceRate / targetRate)
+        fi);
 
     readOne () =
         if expired? () then
@@ -221,16 +220,12 @@
         else
             result = mat.newColumnVector
                (vec.fromList (map reconstructOne [0 .. s.channels-1]));
-//        println "result = \(result)";
-print ".";
             m = sourceRate / g;
             next = spacedInput.read m;
             buffer := mat.concat (Horizontal ())
-               [mat.columnSlice buffer m (flen - m), next];
-//println "dropped \(m), read \(mat.width next), buffer now \(mat.width buffer)";
+               [mat.columnSlice buffer m flen, next];
             remaining := if remaining > 0 then remaining - 1 else 0 fi;
             pos := pos + 1;
-//println "returning \(result)";
             result
         fi;
     
@@ -245,19 +240,16 @@
             esac,
         get finished? () = expired? (),
         read n = 
-           (result = 
-                mat.toRowMajor
-                   (mat.concat (Horizontal ()) (map do _: readOne () done [1..n]));
-            println "returning from read: \(result)";
-            result)
+            mat.toRowMajor
+               (mat.concat (Horizontal ()) (map do _: readOne () done [1..n])),
     });
 
-//resampledTo = resampledSplendidlyTo;
+resampledTo = resampledSplendidlyTo;
 
-//interpolated factor s = resampledTo (s.sampleRate * factor) s;
-//decimated factor s = resampledTo (s.sampleRate / factor) s;
+interpolated factor s = resampledTo (s.sampleRate * factor) s;
+decimated factor s = resampledTo (s.sampleRate / factor) s;
 
-resampledTo = resampledSlowlyTo;
+//resampledTo = resampledSlowlyTo;
 
 {
     kaiserSincWindow, kaiserSincFilterFor,