From 6830452b9cf3914743de3f4688a476af474a17b3 Mon Sep 17 00:00:00 2001 From: Spencer Russell Date: Sat, 19 Mar 2016 22:45:00 -0400 Subject: [PATCH] multichannel output working now --- src/PortAudio.jl | 9 +++++---- src/libportaudio.jl | 23 +---------------------- 2 files changed, 6 insertions(+), 26 deletions(-) diff --git a/src/PortAudio.jl b/src/PortAudio.jl index dafb245..ab82b34 100644 --- a/src/PortAudio.jl +++ b/src/PortAudio.jl @@ -92,8 +92,10 @@ end # end function sinktask(sink::PortAudioSink) - println("starting sink task") buffer = Array(eltype(sink), sink.bufsize, nchannels(sink)) + # as of portaudio 19.20140130 (which is the HomeBrew version as of 20160319) + # noninterleaved data is not supported for the read/write interface on OSX + transbuf = Array(eltype(sink), nchannels(sink), sink.bufsize) try while sink.open total = Pa_GetStreamWriteAvailable(sink.stream) @@ -101,8 +103,8 @@ function sinktask(sink::PortAudioSink) while(written < total) tocopy = min(size(buffer, 1), total - written) read!(sink.ringbuf, sub(buffer, 1:tocopy, :)) - # TODO: this will only work for mono streams - Pa_WriteStream(sink.stream, buffer, tocopy, true) + transpose!(transbuf, buffer) + Pa_WriteStream(sink.stream, transbuf, tocopy, true) written += tocopy end sleep(0.005) @@ -111,7 +113,6 @@ function sinktask(sink::PortAudioSink) warn("PortAudio Sink Task died with exception: $ex") Base.show_backtrace(STDOUT, catch_backtrace()) end - println("sink task finished") end # function sourcetask(sink::PortAudioSource) diff --git a/src/libportaudio.jl b/src/libportaudio.jl index 2a58ebc..3348056 100644 --- a/src/libportaudio.jl +++ b/src/libportaudio.jl @@ -27,36 +27,15 @@ const paInt8 = PaSampleFormat(0x10) const paUInt8 = PaSampleFormat(0x20) const paNonInterleaved = PaSampleFormat(0x80000000) -const fmt_to_type = Dict{PaSampleFormat, Type}( - 1 => Float32, - 2 => Int32, - # 4 => Int24, - 8 => Int16, - 16 => Int8, - 32 => UInt8 -) - -# const type_to_fmt = Dict{Type, PaSampleFormat}( -# Float32 => 1 | paNonInterleaved, -# Int32 => 2 | paNonInterleaved, -# # Int24 => 4 | paNonInterleaved, -# Int16 => 8 | paNonInterleaved, -# Int8 => 16 | paNonInterleaved, -# UInt8 => 3 | paNonInterleaved -# ) -# - -# TODO: temporary for testing mono const type_to_fmt = Dict{Type, PaSampleFormat}( Float32 => 1, Int32 => 2, - # Int24 =>, + # Int24 => 4, Int16 => 8, Int8 => 16, UInt8 => 3 ) - function Pa_Initialize() err = ccall((:Pa_Initialize, libportaudio), PaError, ()) handle_status(err)