Mercurial > hg > may
changeset 495:8af5e23f2873
Add extendedBy, paddedBy
author | Chris Cannam |
---|---|
date | Tue, 19 Nov 2013 14:18:46 +0000 |
parents | 120a2dc3d93b |
children | 4b85578159e1 |
files | src/may/stream/manipulate.yeti src/may/stream/test/test_manipulate.yeti |
diffstat | 2 files changed, 135 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/may/stream/manipulate.yeti Mon Nov 18 16:54:46 2013 +0000 +++ b/src/may/stream/manipulate.yeti Tue Nov 19 14:18:46 2013 +0000 @@ -82,6 +82,38 @@ close = s.close }); +extendedBy nsamples s = //!!! doc: nsamples may *not* be -ve + (var pos = 0; + var toAdd = nsamples; + { + get position () = pos, + get channels () = s.channels, + get sampleRate () = s.sampleRate, + get available () = + case s.available of + Known a: Known (a + toAdd); + other: other; + esac, + get finished? () = (toAdd <= 0) and s.finished?, + read count = + (r = s.read count; + got = mat.width r; + pos := pos + got; + if got >= count then r + else + zc = min toAdd (count - got); + pos := pos + zc; + toAdd := toAdd - zc; + mat.concatHorizontal + [r, mat.zeroMatrix { rows = s.channels, columns = zc }]; + fi), + close = s.close + }); + +// with nsamples zeros added at both start and end (if finite) +paddedBy nsamples s = + delayedBy nsamples (extendedBy nsamples s); + scaledBy factor s = s with { @@ -337,6 +369,8 @@ { withDuration is number -> stream -> stream, delayedBy is number -> stream -> stream, + extendedBy is number -> stream -> stream, + paddedBy is number -> stream -> stream, scaledBy is number -> stream -> stream, inverted is stream -> stream, mixedTo is number -> stream -> stream,
--- a/src/may/stream/test/test_manipulate.yeti Mon Nov 18 16:54:46 2013 +0000 +++ b/src/may/stream/test/test_manipulate.yeti Tue Nov 19 14:18:46 2013 +0000 @@ -63,7 +63,7 @@ ( str.close (); true ) ), -"extendedTo-\(name)": \( +"withDuration-\(name)": \( // not using withDuration wrapper above for the outer call, because // we're actually testing manip.withDuration here rather than just // generating a stream for use in another test. The inner call @@ -220,6 +220,106 @@ ( str.close (); true ) ), +"extendedBy-0-3-\(name)": \( + str = manip.extendedBy 0 (maybeDuration 3 (syn.generated 2 id)); + compare str.position 0 and + compare str.channels 1 and + compare str.sampleRate 2 and + compare str.available (maybeKnown 3) and + compare str.finished? false and + compare (vec.list (mat.getRow 0 (str.read 4))) [ 0,1,2 ] and + compare str.position 3 and + compare str.available (Known 0) and + compare str.finished? true and + ( str.close (); true ) +), + +"extendedBy-0-inf-\(name)": \( + str = manip.extendedBy 0 (syn.generated 2 id); + compare str.position 0 and + compare str.channels 1 and + compare str.sampleRate 2 and + compare str.available (Infinite ()) and + compare str.finished? false and + compare (vec.list (mat.getRow 0 (str.read 4))) [ 0,1,2,3 ] and + compare str.position 4 and + compare str.available (Infinite ()) and + compare str.finished? false and + ( str.close (); true ) +), + +"extendedBy-2-3-\(name)": \( + str = manip.extendedBy 2 (maybeDuration 3 (syn.generated 2 id)); + compare str.position 0 and + compare str.channels 1 and + compare str.sampleRate 2 and + compare str.available (maybeKnown 5) and + compare str.finished? false and + compare (vec.list (mat.getRow 0 (str.read 4))) [ 0,1,2,0 ] and + compare str.position 4 and + compare str.available (Known 1) and // Known now, even if stream was Unknown + compare str.finished? false and + compare (vec.list (mat.getRow 0 (str.read 4))) [ 0 ] and + compare str.position 5 and + compare str.available (Known 0) and + compare str.finished? true and + ( str.close (); true ) +), + +"extendedBy-2-3b-\(name)": \( + str = manip.extendedBy 2 (maybeDuration 3 (syn.generated 2 id)); + compare str.position 0 and + compare str.channels 1 and + compare str.sampleRate 2 and + compare str.available (maybeKnown 5) and + compare str.finished? false and + compare (vec.list (mat.getRow 0 (str.read 1))) [ 0 ] and + compare str.position 1 and + compare str.available (maybeKnown 4) and + compare str.finished? false and + compare (vec.list (mat.getRow 0 (str.read 4))) [ 1,2,0,0 ] and + compare str.position 5 and + compare str.available (Known 0) and + compare str.finished? true and + ( str.close (); true ) +), + +"extendedBy-2-3c-\(name)": \( + str = manip.extendedBy 2 (maybeDuration 3 (syn.generated 2 id)); + compare str.position 0 and + compare str.channels 1 and + compare str.sampleRate 2 and + compare str.available (maybeKnown 5) and + compare str.finished? false and + compare (vec.list (mat.getRow 0 (str.read 7))) [ 0,1,2,0,0 ] and + compare str.position 5 and + compare str.available (Known 0) and + compare str.finished? true and + ( str.close (); true ) +), + +"extendedBy-2-inf-\(name)": \( + str = manip.extendedBy 2 (syn.generated 2 id); + compare str.position 0 and + compare str.channels 1 and + compare str.sampleRate 2 and + compare str.available (Infinite ()) and + compare str.finished? false and + compare (vec.list (mat.getRow 0 (str.read 2))) [ 0,1 ] and + compare str.position 2 and + compare str.finished? false and + compare (vec.list (mat.getRow 0 (str.read 2))) [ 2,3 ] and + compare str.position 4 and + compare str.finished? false and + compare (vec.list (mat.getRow 0 (str.read 2))) [ 4,5 ] and + compare str.position 6 and + compare str.finished? false and + ( str.close (); true ) +), + + + + "mixedTo-1-2-\(name)": \( str = manip.mixedTo 2 (maybeDuration 3 (syn.generated 2 id)); compare str.position 0 and