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
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}}

View file

@ -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)