Mercurial > hg > may
changeset 507:38e7dce5fa37 redo_framer
More framer fixes and tests (still stuff to be done here)
author | Chris Cannam |
---|---|
date | Wed, 20 Nov 2013 12:17:21 +0000 |
parents | a470001a510b |
children | 3420e5f61a1b |
files | src/may/stream/framer.yeti src/may/stream/test/test_framer.yeti |
diffstat | 2 files changed, 29 insertions(+), 19 deletions(-) [+] |
line wrap: on
line diff
--- a/src/may/stream/framer.yeti Wed Nov 20 10:15:06 2013 +0000 +++ b/src/may/stream/framer.yeti Wed Nov 20 12:17:21 2013 +0000 @@ -14,6 +14,9 @@ complex = load may.complex; cm = load may.matrix.complex; manip = load may.stream.manipulate; +syn = load may.stream.syntheticstream; + +{ ceil } = load may.mathmisc; load may.stream.type; @@ -213,6 +216,11 @@ close = \(), }); +//!!! doc: padded tells us whether the original framer was padding or +//not. if not, and if the frames are overlapping, we won't reconstruct +//the original stream exactly (scaling will be wrong for the first few +//samples until we reach the point where each sample is being +//reconstructed from the requisite number of frames) streamed rate framesize options frames = (var hop = framesize; var padded = true; @@ -222,12 +230,6 @@ Padded p: padded := p; Window w: winopt := Some w; esac; - unpadder = - if padded then - manip.delayedBy (- (framesize - hop)) - else - id - fi; window = case winopt of Some w: w; @@ -235,13 +237,16 @@ // NB periodic, not symmetric if framesize == hop then win.boxcar else win.hann fi esac; - unpadder - (if framesize == hop then - //!!! tidy this - streamContiguous rate framesize frames - else - streamOverlapping rate { framesize, hop, window } frames - fi)); + if empty? frames then + syn.empty rate 1 + elif framesize == hop then + streamContiguous rate framesize frames + elif padded then + manip.delayedBy (- (framesize - hop)) + (streamOverlapping rate { framesize, hop, window } frames); + else + streamOverlapping rate { framesize, hop, window } frames; + fi); complexStreamed rate framesize options frames = (streamOptions = array [];
--- a/src/may/stream/test/test_framer.yeti Wed Nov 20 10:15:06 2013 +0000 +++ b/src/may/stream/test/test_framer.yeti Wed Nov 20 12:17:21 2013 +0000 @@ -16,13 +16,11 @@ all id (map2 do f1 f2: compareUsing mat.equal f1 f2 done frames1 (map (mat.newRowVector . vec.fromList) frames2)); -testFramesWith framesize opts length expected firstChunkSize = +testFramesInvertibleWith framesize opts length expected firstChunkSize = (f = fr.frames framesize opts (testStream length); str = fr.streamed rate framesize opts f; ts = testStream length; // newly initialised stream - compareFrames f expected and - (firstChunk = str.read firstChunkSize; compareUsing mat.equal firstChunk (ts.read firstChunkSize)) and @@ -45,13 +43,20 @@ compare str.finished? true and compare str.available (Known 0)); -testFramesInvertible framesize opts length expected = - all id (map (testFramesWith framesize opts length expected) [1..length]); - testFrames framesize opts length expected = (f = fr.frames framesize opts (testStream length); compareFrames f expected); +testFramesInvertible framesize opts length expected = + testFrames framesize opts length expected and + (all id + (map (testFramesInvertibleWith framesize opts length expected) + (reverse [1..length]))) and + (all id + (map (testFramesInvertibleWith framesize ((Padded false) :: opts) + length expected) + (reverse [1..length]))); + [ "framecount-2x2": \(