reworks default source/sink loading so now we get the name
This commit is contained in:
parent
f7b9b48658
commit
ee4d05fcb2
2 changed files with 25 additions and 15 deletions
|
@ -23,16 +23,17 @@ type PortAudioDevice
|
|||
idx::PaDeviceIndex
|
||||
end
|
||||
|
||||
PortAudioDevice(info::PaDeviceInfo, idx) = PortAudioDevice(
|
||||
bytestring(info.name),
|
||||
bytestring(Pa_GetHostApiInfo(info.host_api).name),
|
||||
info.max_input_channels,
|
||||
info.max_output_channels,
|
||||
idx)
|
||||
|
||||
function devices()
|
||||
ndevices = Pa_GetDeviceCount()
|
||||
infos = PaDeviceInfo[Pa_GetDeviceInfo(i) for i in 0:(ndevices - 1)]
|
||||
|
||||
[PortAudioDevice(bytestring(d.name),
|
||||
bytestring(Pa_GetHostApiInfo(d.host_api).name),
|
||||
d.max_input_channels,
|
||||
d.max_output_channels,
|
||||
i-1)
|
||||
for (i, d) in enumerate(infos)]
|
||||
PortAudioDevice[PortAudioDevice(info, idx) for (idx, info) in enumerate(infos)]
|
||||
end
|
||||
|
||||
# not for external use, used in error message printing
|
||||
|
@ -70,11 +71,6 @@ for (TypeName, Super) in ((:PortAudioSink, :SampleSink),
|
|||
end
|
||||
end
|
||||
|
||||
function PortAudioSink(eltype=Float32, sr=48000Hz, channels=2, bufsize=DEFAULT_BUFSIZE)
|
||||
stream = Pa_OpenDefaultStream(0, channels, type_to_fmt[eltype], float(sr), bufsize)
|
||||
PortAudioSink(eltype, stream, sr, channels, bufsize, "Default Sink")
|
||||
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)
|
||||
|
@ -90,11 +86,13 @@ function PortAudioSink(devname::AbstractString, args...)
|
|||
error("No PortAudio device matching \"$devname\" found.\nAvailable Devices:\n$(devnames())")
|
||||
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, "Default Source")
|
||||
function PortAudioSink(args...)
|
||||
idx = Pa_GetDefaultOutputDevice()
|
||||
device = PortAudioDevice(Pa_GetDeviceInfo(idx), idx)
|
||||
PortAudioSink(device, args...)
|
||||
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)
|
||||
|
@ -110,6 +108,12 @@ function PortAudioSource(devname::AbstractString, args...)
|
|||
error("No PortAudio device matching \"$devname\" found.\nAvailable Devices:\n$(devnames())")
|
||||
end
|
||||
|
||||
function PortAudioSource(args...)
|
||||
idx = Pa_GetDefaultInputDevice()
|
||||
device = PortAudioDevice(Pa_GetDeviceInfo(idx), idx)
|
||||
PortAudioSource(device, args...)
|
||||
end
|
||||
|
||||
|
||||
|
||||
# most of these methods are the same for Sources and Sinks, so define them on
|
||||
|
|
|
@ -111,6 +111,12 @@ Pa_GetDeviceCount() = ccall((:Pa_GetDeviceCount, libportaudio), PaDeviceIndex, (
|
|||
Pa_GetDeviceInfo(i) = unsafe_load(ccall((:Pa_GetDeviceInfo, libportaudio),
|
||||
Ptr{PaDeviceInfo}, (PaDeviceIndex,), i))
|
||||
|
||||
Pa_GetDefaultInputDevice() = ccall((:Pa_GetDefaultInputDevice, libportaudio),
|
||||
PaDeviceIndex, ())
|
||||
|
||||
Pa_GetDefaultOutputDevice() = ccall((:Pa_GetDefaultOutputDevice, libportaudio),
|
||||
PaDeviceIndex, ())
|
||||
|
||||
# Stream Functions
|
||||
|
||||
type Pa_StreamParameters
|
||||
|
|
Loading…
Reference in a new issue