From 2620e6ecb21b66b9c25702075ba24aabb812c336 Mon Sep 17 00:00:00 2001 From: Spencer Russell Date: Wed, 13 Aug 2014 12:31:56 -0400 Subject: [PATCH] fixes issue and now passes test for stereo file playback (mixing to mono) --- src/sndfile.jl | 8 +++++--- test/test_sndfile.jl | 5 ++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/sndfile.jl b/src/sndfile.jl index 4f73116..b231e68 100644 --- a/src/sndfile.jl +++ b/src/sndfile.jl @@ -183,15 +183,17 @@ function render(node::FileRenderer, device_input::AudioBuf, info::DeviceInfo) # Keep reading data from the file until the output buffer is full, but stop # as soon as no more data can be read from the file audio = Array(AudioSample, 0, node.file.sfinfo.channels) - read_audio = zeros(AudioSample, 1, node.file.sfinfo.channels) - while size(audio, 1) < info.buf_size && size(read_audio, 1) > 0 + while true read_audio = read(node.file, info.buf_size-size(audio, 1), AudioSample) audio = vcat(audio, read_audio) + if size(audio, 1) >= info.buf_size || size(read_audio, 1) <= 0 + break + end end # if the file is stereo, mix the two channels together if node.file.sfinfo.channels == 2 - return (audio[1, :] / 2) + (audio[2, :] / 2) + return (audio[:, 1] / 2) + (audio[:, 2] / 2) else return audio end diff --git a/test/test_sndfile.jl b/test/test_sndfile.jl index d091277..95c673e 100644 --- a/test/test_sndfile.jl +++ b/test/test_sndfile.jl @@ -72,10 +72,9 @@ facts("Stereo file rendering") do AudioIO.open(fname) do f node = FilePlayer(f) buf = render(node, input, test_info) - print(size(buf)) - @fact expected[1:bufsize] => buf[1:bufsize] + @fact buf[1:bufsize] => mse(expected[1:bufsize]) buf = render(node, input, test_info) - @fact expected[bufsize+1:2*bufsize] => buf[1:bufsize] + @fact buf[1:bufsize] => mse(expected[bufsize+1:2*bufsize]) end end