# HG changeset patch # User Chris Cannam # Date 1380391899 -3600 # Node ID 3ee42c8029fb4ec9510fd253f87420c331547ec7 # Parent ad99cd603b75464282d8b1ca5732ceed911fdcf9 Fix wrong args to columnSlice diff -r ad99cd603b75 -r 3ee42c8029fb src/may/stream/resample.yeti --- 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,