# HG changeset patch # User Chris Cannam # Date 1356005531 0 # Node ID 6c5d2fe1b260fb4ce953fcb1cb38ff9091080e7e # Parent 0b04bc5d2e53881e05e072bbe62b6e964625087b Some fixes to file opening & playback diff -r 0b04bc5d2e53 -r 6c5d2fe1b260 playback.yeti --- 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()); diff -r 0b04bc5d2e53 -r 6c5d2fe1b260 stream.yeti --- 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, });