From 2cc49cc3e0ff0ba39202cdc8d0674904c8c9c85f Mon Sep 17 00:00:00 2001 From: Spencer Russell Date: Mon, 8 Aug 2016 21:28:34 -0400 Subject: [PATCH] fixes error with multichannel reading --- src/PortAudio.jl | 3 ++- test/runtests.jl | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/PortAudio.jl b/src/PortAudio.jl index 75fb40f..27ca07e 100644 --- a/src/PortAudio.jl +++ b/src/PortAudio.jl @@ -278,7 +278,8 @@ function SampledSignals.unsafe_read!(source::PortAudioSource, buf::SampleBuf) wait(source.ringbuf) end # in 0.4 transpose! throws an error if the range is a UInt - toread = Int(min(nreadable(source.ringbuf), CHUNKSIZE, total-nread)) + readable = div(nreadable(source.ringbuf), nchannels(source)) + toread = Int(min(readable, CHUNKSIZE, total-nread)) read!(source.ringbuf, source.chunkbuf, toread*nchannels(source)) # de-interleave the samples # TODO: don't directly access buf.data diff --git a/test/runtests.jl b/test/runtests.jl index e903250..16dd1b6 100755 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -117,8 +117,8 @@ using RingBuffers end @testset "Samplerate-converting writing" begin stream = PortAudioStream() - write(stream, SinSource(eltype(stream), samplerate(stream)*0.8, [220Hz, 330Hz]), 10s) - write(stream, SinSource(eltype(stream), samplerate(stream)*1.2, [220Hz, 330Hz]), 10s) + write(stream, SinSource(eltype(stream), samplerate(stream)*0.5, [220Hz, 330Hz]), 3s) + write(stream, SinSource(eltype(stream), samplerate(stream)*1.5, [220Hz, 330Hz]), 3s) flush(stream) close(stream) end