Mercurial > hg > may
changeset 183:7cfcc3a07177
Make generator function take sample number, not time in seconds -- simpler and more consistent with other uses of plain numbers in this module
author | Chris Cannam |
---|---|
date | Fri, 03 May 2013 18:11:56 +0100 |
parents | 1ab130dcf7f3 |
children | 045908c861a4 |
files | yetilab/stream/syntheticstream.yeti yetilab/stream/test/test_filter.yeti yetilab/stream/test/test_syntheticstream.yeti |
diffstat | 3 files changed, 18 insertions(+), 19 deletions(-) [+] |
line wrap: on
line diff
--- a/yetilab/stream/syntheticstream.yeti Fri May 03 18:00:48 2013 +0100 +++ b/yetilab/stream/syntheticstream.yeti Fri May 03 18:11:56 2013 +0100 @@ -8,7 +8,7 @@ load yetilab.stream.streamtype; generated sampleRate generator = - (// generator takes time in seconds as arg, returns number in -1,+1 range + (// generator takes sample number as arg, returns number in -1,+1 range var position = 0; { get position () = position, @@ -19,7 +19,7 @@ read count = ch.deinterleaved 1 (result = vec.zeros count; for [0..count-1] do i: - result[i] := generator ((position + i) / sampleRate) + result[i] := generator (position + i) done; position := position + count; block.block result), @@ -27,7 +27,7 @@ }); sinusoid rate freq = - generated rate (sin . (* (2 * pi * freq))); + generated rate (sin . (* (2 * pi * freq / rate))); whiteNoise rate = generated rate \((Math#random() * 2.0) - 1.0);
--- a/yetilab/stream/test/test_filter.yeti Fri May 03 18:00:48 2013 +0100 +++ b/yetilab/stream/test/test_filter.yeti Fri May 03 18:11:56 2013 +0100 @@ -18,7 +18,7 @@ compare str.sampleRate 2 and compare str.available (Known 3) and compare str.finished? false and - compare (bl.list ((str.read 4).getRow 0)) [ 0, 0.5, 1 ] and + compare (bl.list ((str.read 4).getRow 0)) [ 0,1,2 ] and compare str.position 3 and compare str.available (Known 0) and compare str.finished? true and @@ -32,7 +32,7 @@ compare str.sampleRate 2 and compare str.available (Known 3) and compare str.finished? false and - compare (bl.list ((str.read 4).getRow 0)) [ 0, 0.5, 1 ] and + compare (bl.list ((str.read 4).getRow 0)) [ 0,1,2 ] and compare str.position 3 and compare str.available (Known 0) and compare str.finished? true and @@ -46,7 +46,7 @@ compare str.sampleRate 2 and compare str.available (Infinite ()) and compare str.finished? false and - compare (bl.list ((str.read 4).getRow 0)) [ 0, 0.5, 1, 1.5 ] and + compare (bl.list ((str.read 4).getRow 0)) [ 0,1,2,3 ] and compare str.position 4 and compare str.available (Infinite ()) and compare str.finished? false and @@ -60,11 +60,11 @@ compare str.sampleRate 2 and compare str.available (Known 5) and compare str.finished? false and - compare (bl.list ((str.read 4).getRow 0)) [ 0, 0, 0, 0.5 ] and + compare (bl.list ((str.read 4).getRow 0)) [ 0,0,0,1 ] and compare str.position 4 and compare str.available (Known 1) and compare str.finished? false and - compare (bl.list ((str.read 4).getRow 0)) [ 1 ] and + compare (bl.list ((str.read 4).getRow 0)) [ 2 ] and compare str.position 5 and compare str.available (Known 0) and compare str.finished? true and @@ -82,7 +82,7 @@ compare str.position 1 and compare str.available (Known 4) and compare str.finished? false and - compare (bl.list ((str.read 4).getRow 0)) [ 0, 0, 0.5, 1 ] and + compare (bl.list ((str.read 4).getRow 0)) [ 0,0,1,2 ] and compare str.position 5 and compare str.available (Known 0) and compare str.finished? true and @@ -96,13 +96,13 @@ compare str.sampleRate 2 and compare str.available (Infinite ()) and compare str.finished? false and - compare (bl.list ((str.read 2).getRow 0)) [ 0, 0 ] and + compare (bl.list ((str.read 2).getRow 0)) [ 0,0 ] and compare str.position 2 and compare str.finished? false and - compare (bl.list ((str.read 2).getRow 0)) [ 0, 0.5 ] and + compare (bl.list ((str.read 2).getRow 0)) [ 0,1 ] and compare str.position 4 and compare str.finished? false and - compare (bl.list ((str.read 2).getRow 0)) [ 1, 1.5 ] and + compare (bl.list ((str.read 2).getRow 0)) [ 2,3 ] and compare str.position 6 and compare str.finished? false and ( str.close (); true ) @@ -116,7 +116,7 @@ compare str.available (Infinite ()) and compare str.finished? false and compare (map bl.list (mat.asRows (str.read 4))) - [[0,0.5,1.0,1.5], [0,-0.5,-1,-1.5]] and + [[0,1,2,3], [0,-1,-2,-3]] and compare str.available (Infinite ()) and compare str.position 4 and ( str.close (); true ) @@ -129,8 +129,7 @@ compare str.sampleRate 2 and compare str.available (Known 3) and compare str.finished? false and - compare (map bl.list (mat.asRows (str.read 4))) - [[0,0.5,1.0], [0,-0.5,-1]] and + compare (map bl.list (mat.asRows (str.read 4))) [[0,1,2], [0,-1,-2]] and compare str.available (Known 0) and compare str.finished? true and compare str.position 3 and @@ -146,7 +145,7 @@ compare str.sampleRate 2 and compare str.available (Known 2) and compare str.finished? false and - compare (map bl.list (mat.asRows (str.read 4))) [[1,2], [0,-0.5]] and + compare (map bl.list (mat.asRows (str.read 4))) [[1,2], [0,-1]] and compare str.available (Known 0) and compare str.finished? true and compare str.position 2 and @@ -163,7 +162,7 @@ compare str.sampleRate 2 and compare str.available (Known 2) and compare str.finished? false and - compare (map bl.list (mat.asRows (str.read 4))) [[1,2], [3,4], [0,-0.5]] and + compare (map bl.list (mat.asRows (str.read 4))) [[1,2], [3,4], [0,-1]] and compare str.available (Known 0) and compare str.finished? true and compare str.position 2 and @@ -180,7 +179,7 @@ compare str.sampleRate 2 and compare str.available (Known 2) and compare str.finished? false and - compare (map bl.list (mat.asRows (str.read 4))) [[1,2], [3,4], [0,-0.5]] and + compare (map bl.list (mat.asRows (str.read 4))) [[1,2], [3,4], [0,-1]] and compare str.available (Known 0) and compare str.finished? true and compare str.position 2 and
--- a/yetilab/stream/test/test_syntheticstream.yeti Fri May 03 18:00:48 2013 +0100 +++ b/yetilab/stream/test/test_syntheticstream.yeti Fri May 03 18:11:56 2013 +0100 @@ -21,7 +21,7 @@ compare str.sampleRate 2 and compare str.available (Infinite ()) and compare str.finished? false and - compare (bl.list ((str.read 4).getRow 0)) [ 0, 0.5, 1, 1.5 ] and + compare (bl.list ((str.read 4).getRow 0)) [ 0,1,2,3 ] and compare str.position 4 ),