multichannel output working now

This commit is contained in:
Spencer Russell 2016-03-19 22:45:00 -04:00
parent 4cb94e168d
commit 6830452b9c
2 changed files with 6 additions and 26 deletions

View file

@ -92,8 +92,10 @@ end
# end # end
function sinktask(sink::PortAudioSink) function sinktask(sink::PortAudioSink)
println("starting sink task")
buffer = Array(eltype(sink), sink.bufsize, nchannels(sink)) 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 try
while sink.open while sink.open
total = Pa_GetStreamWriteAvailable(sink.stream) total = Pa_GetStreamWriteAvailable(sink.stream)
@ -101,8 +103,8 @@ function sinktask(sink::PortAudioSink)
while(written < total) while(written < total)
tocopy = min(size(buffer, 1), total - written) tocopy = min(size(buffer, 1), total - written)
read!(sink.ringbuf, sub(buffer, 1:tocopy, :)) read!(sink.ringbuf, sub(buffer, 1:tocopy, :))
# TODO: this will only work for mono streams transpose!(transbuf, buffer)
Pa_WriteStream(sink.stream, buffer, tocopy, true) Pa_WriteStream(sink.stream, transbuf, tocopy, true)
written += tocopy written += tocopy
end end
sleep(0.005) sleep(0.005)
@ -111,7 +113,6 @@ function sinktask(sink::PortAudioSink)
warn("PortAudio Sink Task died with exception: $ex") warn("PortAudio Sink Task died with exception: $ex")
Base.show_backtrace(STDOUT, catch_backtrace()) Base.show_backtrace(STDOUT, catch_backtrace())
end end
println("sink task finished")
end end
# function sourcetask(sink::PortAudioSource) # function sourcetask(sink::PortAudioSource)

View file

@ -27,36 +27,15 @@ const paInt8 = PaSampleFormat(0x10)
const paUInt8 = PaSampleFormat(0x20) const paUInt8 = PaSampleFormat(0x20)
const paNonInterleaved = PaSampleFormat(0x80000000) 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}( const type_to_fmt = Dict{Type, PaSampleFormat}(
Float32 => 1, Float32 => 1,
Int32 => 2, Int32 => 2,
# Int24 =>, # Int24 => 4,
Int16 => 8, Int16 => 8,
Int8 => 16, Int8 => 16,
UInt8 => 3 UInt8 => 3
) )
function Pa_Initialize() function Pa_Initialize()
err = ccall((:Pa_Initialize, libportaudio), PaError, ()) err = ccall((:Pa_Initialize, libportaudio), PaError, ())
handle_status(err) handle_status(err)