adds functionality to open a specific device instance

This commit is contained in:
Spencer Russell 2016-03-20 02:07:39 -04:00
parent b8e5c8786e
commit 738c4cff4b
2 changed files with 23 additions and 10 deletions

View file

@ -17,10 +17,10 @@ Pa_Initialize()
type PortAudioDevice type PortAudioDevice
name::UTF8String name::UTF8String
host_api::UTF8String hostapi::UTF8String
max_input_channels::Int maxinchans::Int
max_output_channels::Int maxoutchans::Int
device_index::PaDeviceIndex idx::PaDeviceIndex
end end
function devices() function devices()
@ -69,11 +69,24 @@ function PortAudioSink(eltype=Float32, sr=48000Hz, channels=2, bufsize=DEFAULT_B
PortAudioSink(eltype, stream, sr, channels, bufsize) PortAudioSink(eltype, stream, sr, channels, bufsize)
end 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) function PortAudioSource(eltype=Float32, sr=48000Hz, channels=2, bufsize=DEFAULT_BUFSIZE)
stream = Pa_OpenDefaultStream(channels, 0, type_to_fmt[eltype], float(sr), bufsize) stream = Pa_OpenDefaultStream(channels, 0, type_to_fmt[eltype], float(sr), bufsize)
PortAudioSource(eltype, stream, sr, channels, bufsize) PortAudioSource(eltype, stream, sr, channels, bufsize)
end 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 # most of these methods are the same for Sources and Sinks, so define them on
# the union # the union
typealias PortAudioStream{T, U} Union{PortAudioSink{T, U}, PortAudioSource{T, U}} typealias PortAudioStream{T, U} Union{PortAudioSink{T, U}, PortAudioSource{T, U}}

View file

@ -13,7 +13,7 @@ typealias PaStream Ptr{Void}
typealias PaStreamCallback Void typealias PaStreamCallback Void
typealias PaStreamFlags Culong typealias PaStreamFlags Culong
const paNoFlag = PaStreamFlags(0x00)
const PA_NO_ERROR = 0 const PA_NO_ERROR = 0
const PA_INPUT_OVERFLOWED = -10000 + 19 const PA_INPUT_OVERFLOWED = -10000 + 19
@ -136,18 +136,18 @@ function Pa_OpenDefaultStream(inChannels, outChannels,
streamPtr[] streamPtr[]
end end
function Pa_OpenStream(inParams::Pa_StreamParameters, function Pa_OpenStream(inParams, outParams,
outParams::Pa_StreamParameters,
sampleRate, framesPerBuffer, sampleRate, framesPerBuffer,
flags::PaStreamFlags) flags::PaStreamFlags)
streamPtr = Ref{PaStream}(0) streamPtr = Ref{PaStream}(0)
err = ccall((:Pa_OpenStream, libportaudio), PaError, err = ccall((:Pa_OpenStream, libportaudio), PaError,
(Ref{PaStream}, (Ref{PaStream},
Ref{Pa_StreamParameters}, Ptr{Pa_StreamParameters},
Ref{Pa_StreamParameters}, Ptr{Pa_StreamParameters},
Cdouble, Culong, PaStreamFlags, Cdouble, Culong, PaStreamFlags,
Ref{Void}, Ref{Void}), Ref{Void}, Ref{Void}),
streamPtr, inParams, outParams, streamPtr,
inParams, outParams,
sampleRate, framesPerBuffer, flags, sampleRate, framesPerBuffer, flags,
C_NULL, C_NULL) C_NULL, C_NULL)
handle_status(err) handle_status(err)