actually, this might be nicer as a macro

This commit is contained in:
Brandon Taylor 2021-05-18 13:48:54 -04:00
parent 08681d135d
commit c969b8b349

View file

@ -95,10 +95,8 @@ mutable struct PortAudioStream{T}
# finalizer(close, this) # finalizer(close, this)
this.sink = PortAudioSink{T}(outdev.name, this, outchans) this.sink = PortAudioSink{T}(outdev.name, this, outchans)
this.source = PortAudioSource{T}(indev.name, this, inchans) this.source = PortAudioSource{T}(indev.name, this, inchans)
this.stream = suppress_err() do this.stream = @stderr_as_debug Pa_OpenStream(inparams, outparams, sr, 0, paNoFlag,
Pa_OpenStream(inparams, outparams, sr, 0, paNoFlag,
nothing, nothing) nothing, nothing)
end
Pa_StartStream(this.stream) Pa_StartStream(this.stream)
# pre-fill the output stream so we're less likely to underrun # pre-fill the output stream so we're less likely to underrun
@ -369,9 +367,11 @@ function discard_input(source::PortAudioSource)
end end
end end
function suppress_err(dofunc::Function) macro stderr_as_debug(expression)
debug_message = @suppress_err dofunc() quote
@debug debug_message debug_message = @capture_err $(esc(expression))
@debug debug_message
end
end end
function __init__() function __init__()
@ -407,9 +407,7 @@ function __init__()
# junk to STDOUT on initialization, so we swallow it. # junk to STDOUT on initialization, so we swallow it.
# TODO: actually check the junk to make sure there's nothing in there we # TODO: actually check the junk to make sure there's nothing in there we
# don't expect # don't expect
suppress_err() do @stderr_as_debug Pa_Initialize()
Pa_Initialize()
end
atexit() do atexit() do
Pa_Terminate() Pa_Terminate()