Mercurial > hg > may
changeset 21:6c5d2fe1b260
Some fixes to file opening & playback
author | Chris Cannam |
---|---|
date | Thu, 20 Dec 2012 12:12:11 +0000 |
parents | 0b04bc5d2e53 |
children | 5d130537fcc2 |
files | playback.yeti stream.yeti |
diffstat | 2 files changed, 23 insertions(+), 23 deletions(-) [+] |
line wrap: on
line diff
--- a/playback.yeti Thu Dec 20 11:58:48 2012 +0000 +++ b/playback.yeti Thu Dec 20 12:12:11 2012 +0000 @@ -11,19 +11,7 @@ import java.nio: ByteBuffer, ByteOrder; -open { rate, channels } = - (format = new AudioFormat(AudioFormat$Encoding#PCM_SIGNED, rate, 16, - channels, channels * 2, rate, false); - line = AudioSystem#getSourceDataLine(format); - line#open(format); - line#start(); - { - line, - channels = line#getFormat()#getChannels(), - close () = line#close(), - }); - -playBlock { line is ~SourceDataLine } b = +playBlock line b is ~SourceDataLine -> 'a -> () = (len = block.length b; samples = block.unblock b; nb = len * 2; @@ -38,10 +26,23 @@ play line blocks = for blocks (playBlock line); +open { rate, channels } = + (format = new AudioFormat(AudioFormat$Encoding#PCM_SIGNED, rate, 16, + channels, channels * 2, rate, false); + line = AudioSystem#getSourceDataLine(format); + line#open(format); + line#start(); + { + line, + play = play line, + channels = line#getFormat()#getChannels(), + close () = (line#drain(); line#close()), + }); + playStream stream = (line = open { rate = stream.sampleRate, channels = stream.channels }; blocksize = 10240; - play line (map (ch.mixedFromInterleavedTo line.channels stream.channels) + line.play (map (ch.mixedFromInterleavedTo line.channels stream.channels) (fr.frames blocksize stream)); line.close());
--- a/stream.yeti Thu Dec 20 11:58:48 2012 +0000 +++ b/stream.yeti Thu Dec 20 12:12:11 2012 +0000 @@ -2,7 +2,7 @@ module stream; monoStream box = - (readAll box = box.read (box.len - box.position); + (readAll' box = box.read (box.len - box.position); { get position () = box.position, get channels () = 1, @@ -12,15 +12,14 @@ read = box.read, readInterleaved = box.read, readMono = box.read, - readAll = readAll box, - readAllInterleaved = readAll box, - readAllMono = readAll box, + readAll () = readAll' box, + readAllInterleaved () = readAll' box, + readAllMono () = readAll' box, close = box.close, }); stream box = - (readAll box = box.read (box.len - box.position); - { + ({ get position () = box.position, get channels () = box.channels, get sampleRate () = box.rate, @@ -29,9 +28,9 @@ read = box.read, readInterleaved = box.readInterleaved, readMono = box.readMono, - readAll = box.read (box.len - box.position), - readAllInterleaved = box.readInterleaved (box.len - box.position), - readAllMono = box.readMono (box.len - box.position), + readAll () = box.read (box.len - box.position), + readAllInterleaved () = box.readInterleaved (box.len - box.position), + readAllMono () = box.readMono (box.len - box.position), close = box.close, });