Mercurial > hg > may
changeset 24:ad5149048604
Test for, and fix, zero-padding in non-overlapping framer
| author | Chris Cannam |
|---|---|
| date | Thu, 20 Dec 2012 15:13:30 +0000 |
| parents | 1633c56b9d87 |
| children | a6b1cc001232 |
| files | block.yeti framer.yeti fvector.yeti tests.yeti |
| diffstat | 4 files changed, 26 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/block.yeti Thu Dec 20 15:08:14 2012 +0000 +++ b/block.yeti Thu Dec 20 15:13:30 2012 +0000 @@ -20,8 +20,14 @@ equal b1 b2 = list' b1 == list' b2; -copyOf b = Block (vec.copyOf (unblock b)); -range b start len = Block (vec.range (unblock b) start len); +copyOf b = + Block (vec.copyOf (unblock b)); + +range b start len = + Block (vec.range (unblock b) start len); + +resizedTo n b = + Block (vec.resizedTo n (unblock b)); { zeros, ones, @@ -30,6 +36,6 @@ length = length', list = list', equal, -copyOf, range, +copyOf, range, resizedTo, }
--- a/framer.yeti Thu Dec 20 15:08:14 2012 +0000 +++ b/framer.yeti Thu Dec 20 15:13:30 2012 +0000 @@ -9,24 +9,25 @@ if stream.finished? then (stream.close (); [] ); else - stream.readMono blocksize :. \(blockList blocksize stream); + block.resizedTo blocksize (stream.readMono blocksize) + :. \(blockList blocksize stream); fi; overlappingBlockList bs hop stream valid buffer is number -> number -> 'a -> number -> ~double[] -> 'b = (b = stream.readMono hop; - blen = block.length b; + obtained = block.length b; samples = block.unblock b; // Shift existing buffer down by hop for [hop..bs-1] do i: buffer[i-hop] := buffer[i] done; // Copy hop new elements in from samples (and extra zeros if needed) - for [0..blen-1] do i: buffer[bs-hop+i] := samples[i] done; - for [blen..hop-1] do i: buffer[bs-hop+i] := 0.0 done; + for [0..obtained-1] do i: buffer[bs-hop+i] := samples[i] done; + for [obtained..hop-1] do i: buffer[bs-hop+i] := 0.0 done; // Number of "valid" elements (not tail-end zero-padding) left in buffer - remaining = valid - (hop - blen); + remaining = valid - (hop - obtained); if remaining <= 0 then stream.close ();
--- a/fvector.yeti Thu Dec 20 15:08:14 2012 +0000 +++ b/fvector.yeti Thu Dec 20 15:13:30 2012 +0000 @@ -36,12 +36,15 @@ range v start len is ~double[] -> number -> number -> ~double[] = Arrays#copyOfRange(v, start, start + len); +resizedTo n v is number -> ~double[] -> ~double[] = + Arrays#copyOf(v, n); + { zeros, ones, vector, length = length', list = list', equal, -copyOf, range, +copyOf, range, resizedTo, }
--- a/tests.yeti Thu Dec 20 15:08:14 2012 +0000 +++ b/tests.yeti Thu Dec 20 15:13:30 2012 +0000 @@ -73,6 +73,13 @@ compare (length fr) 3 ), +"frames-2x5": \( + fr = fr.frames 2 (testStream 5); + expected = array [ [1,2], [3,4], [5,0] ]; + obtained = array (map block.list fr); + compare obtained expected; +), + "frames-4.3x4": \( fr = fr.overlappingFrames { blocksize = 4, hop = 3 } (testStream 4); expected = array [ [0,1,2,3], [3,4,0,0] ];
