fix bug, test

This commit is contained in:
Brandon Taylor 2022-07-24 11:54:55 -04:00
parent fbcd539a76
commit 06c6fd0495
2 changed files with 19 additions and 4 deletions

View file

@ -48,6 +48,7 @@ using .LibPortAudio:
Pa_Initialize, Pa_Initialize,
paInputOverflowed, paInputOverflowed,
Pa_IsStreamStopped, Pa_IsStreamStopped,
paNoDevice,
paNoFlag, paNoFlag,
Pa_OpenStream, Pa_OpenStream,
paOutputUnderflowed, paOutputUnderflowed,
@ -195,12 +196,22 @@ function show(io::IO, device::PortAudioDevice)
print(io, device.output_bounds.max_channels) print(io, device.output_bounds.max_channels)
end end
function check_device_exists(device_index, device_type)
if device_index == paNoDevice
throw(ArgumentError("No $device_type device available"))
end
end
function get_default_input_index() function get_default_input_index()
handle_status(Pa_GetDefaultInputDevice()) device_index = Pa_GetDefaultInputDevice()
check_device_exists(device_index, "input")
device_index
end end
function get_default_output_index() function get_default_output_index()
handle_status(Pa_GetDefaultOutputDevice()) device_index = Pa_GetDefaultOutputDevice()
check_device_exists(device_index, "output")
device_index
end end
# we can look up devices by index or name # we can look up devices by index or name

View file

@ -11,6 +11,7 @@ using PortAudio:
get_output_type, get_output_type,
handle_status, handle_status,
initialize, initialize,
name,
PortAudioException, PortAudioException,
PortAudio, PortAudio,
PortAudioDevice, PortAudioDevice,
@ -18,7 +19,7 @@ using PortAudio:
safe_load, safe_load,
seek_alsa_conf, seek_alsa_conf,
terminate, terminate,
name write_buffer
using PortAudio.LibPortAudio: using PortAudio.LibPortAudio:
Pa_AbortStream, Pa_AbortStream,
PaError, PaError,
@ -109,7 +110,9 @@ using Test: @test, @test_logs, @test_nowarn, @testset, @test_throws
initialize() initialize()
end end
if !isempty(devices()) if isempty(devices())
@test_throws ArgumentError("No input device available") get_default_input_index()
else
@testset "Tests with sound" begin @testset "Tests with sound" begin
# these default values are specific to local machines # these default values are specific to local machines
input_name = get_device(get_default_input_index()).name input_name = get_device(get_default_input_index()).name
@ -130,6 +133,7 @@ if !isempty(devices())
sleep(1) sleep(1)
println("Testing pass-through") println("Testing pass-through")
stream = PortAudioStream(input_name, output_name, 2, 2; adjust_channels = true) stream = PortAudioStream(input_name, output_name, 2, 2; adjust_channels = true)
write_buffer(stream.sink_messenger.buffer, acquire_lock = false)
sink = stream.sink sink = stream.sink
source = stream.source source = stream.source
@test sprint(show, stream) == """ @test sprint(show, stream) == """