From 738c4cff4b2119ab803ee1d3a22b97431f9f8702 Mon Sep 17 00:00:00 2001 From: Spencer Russell Date: Sun, 20 Mar 2016 02:07:39 -0400 Subject: [PATCH] adds functionality to open a specific device instance --- src/PortAudio.jl | 21 +++++++++++++++++---- src/libportaudio.jl | 12 ++++++------ 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/src/PortAudio.jl b/src/PortAudio.jl index d777409..e08e798 100644 --- a/src/PortAudio.jl +++ b/src/PortAudio.jl @@ -17,10 +17,10 @@ Pa_Initialize() type PortAudioDevice name::UTF8String - host_api::UTF8String - max_input_channels::Int - max_output_channels::Int - device_index::PaDeviceIndex + hostapi::UTF8String + maxinchans::Int + maxoutchans::Int + idx::PaDeviceIndex end function devices() @@ -69,11 +69,24 @@ function PortAudioSink(eltype=Float32, sr=48000Hz, channels=2, bufsize=DEFAULT_B PortAudioSink(eltype, stream, sr, channels, bufsize) end +function PortAudioSink(device::PortAudioDevice, eltype=Float32, sr=48000Hz, channels=2, bufsize=DEFAULT_BUFSIZE) + params = Pa_StreamParameters(device.idx, channels, type_to_fmt[eltype], 0.0, C_NULL) + stream = Pa_OpenStream(C_NULL, pointer_from_objref(params), float(sr), bufsize, paNoFlag) + PortAudioSink(eltype, stream, sr, channels, bufsize) +end + function PortAudioSource(eltype=Float32, sr=48000Hz, channels=2, bufsize=DEFAULT_BUFSIZE) stream = Pa_OpenDefaultStream(channels, 0, type_to_fmt[eltype], float(sr), bufsize) PortAudioSource(eltype, stream, sr, channels, bufsize) end +function PortAudioSource(device::PortAudioDevice, eltype=Float32, sr=48000Hz, channels=2, bufsize=DEFAULT_BUFSIZE) + params = Pa_StreamParameters(device.idx, channels, type_to_fmt[eltype], 0.0, C_NULL) + stream = Pa_OpenStream(pointer_from_objref(params), C_NULL, float(sr), bufsize, paNoFlag) + PortAudioSource(eltype, stream, sr, channels, bufsize) +end + + # most of these methods are the same for Sources and Sinks, so define them on # the union typealias PortAudioStream{T, U} Union{PortAudioSink{T, U}, PortAudioSource{T, U}} diff --git a/src/libportaudio.jl b/src/libportaudio.jl index a23b6c0..ad1d216 100644 --- a/src/libportaudio.jl +++ b/src/libportaudio.jl @@ -13,7 +13,7 @@ typealias PaStream Ptr{Void} typealias PaStreamCallback Void typealias PaStreamFlags Culong - +const paNoFlag = PaStreamFlags(0x00) const PA_NO_ERROR = 0 const PA_INPUT_OVERFLOWED = -10000 + 19 @@ -136,18 +136,18 @@ function Pa_OpenDefaultStream(inChannels, outChannels, streamPtr[] end -function Pa_OpenStream(inParams::Pa_StreamParameters, - outParams::Pa_StreamParameters, +function Pa_OpenStream(inParams, outParams, sampleRate, framesPerBuffer, flags::PaStreamFlags) streamPtr = Ref{PaStream}(0) err = ccall((:Pa_OpenStream, libportaudio), PaError, (Ref{PaStream}, - Ref{Pa_StreamParameters}, - Ref{Pa_StreamParameters}, + Ptr{Pa_StreamParameters}, + Ptr{Pa_StreamParameters}, Cdouble, Culong, PaStreamFlags, Ref{Void}, Ref{Void}), - streamPtr, inParams, outParams, + streamPtr, + inParams, outParams, sampleRate, framesPerBuffer, flags, C_NULL, C_NULL) handle_status(err)