Mercurial > hg > may
changeset 405:1f055d9a76ab resample
Adjust output duration for interpolate/decimate if input has known duration
author | Chris Cannam |
---|---|
date | Fri, 27 Sep 2013 14:35:52 +0100 |
parents | fbcdcfaf4813 |
children | b84718e7d3b1 |
files | src/may/stream/resample.yeti |
diffstat | 1 files changed, 16 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/src/may/stream/resample.yeti Fri Sep 27 14:35:22 2013 +0100 +++ b/src/may/stream/resample.yeti Fri Sep 27 14:35:52 2013 +0100 @@ -38,33 +38,42 @@ println "kaiserSincFilterFor: filter length is \(vec.length sw)"; bf.multiply sw kw); +durationAdjusterFor factor s = + case s.available of + Known n: manip.withDuration (int (n * factor)); + _: id; + esac; interpolated factor s = //!!! factor must be an integer [how to enforce this??] if factor == 1 then s else + adjuster = durationAdjusterFor factor s; nzc = 13; attenuation = 80; filter = kaiserSincWindow nzc factor attenuation; // println "interpolated: filter length \(vec.length filter)"; - out = manip.delayedBy (- (nzc * factor)) - (convolve.convolvedWith [Framesize 1024] - (mat.newMatrix (RowMajor ()) (map \filter [1..s.channels])) - (manip.spaced factor s)); + out = adjuster + (manip.delayedBy (- (nzc * factor)) + (convolve.convolvedWith [Framesize 1024] + (mat.newMatrix (RowMajor ()) (map \filter [1..s.channels])) + (manip.spaced factor s))); out with { get sampleRate () = s.sampleRate * factor }; fi; decimated factor s = //!!! factor must be an integer [how to enforce this??] if factor == 1 then s else + adjuster = durationAdjusterFor (1/factor) s; nzc = 13; attenuation = 80; filter = kaiserSincWindow nzc factor attenuation; filtered = (convolve.convolvedWith [Framesize 1024] (mat.newMatrix (RowMajor ()) (map \filter [1..s.channels])) s); - out = manip.scaledBy (1/factor) - (manip.delayedBy (- nzc) - (manip.picked factor filtered)); + out = adjuster + (manip.scaledBy (1/factor) + (manip.delayedBy (- nzc) + (manip.picked factor filtered))); out with { get sampleRate () = s.sampleRate / factor }; fi;