swallows STDERR to remove some spurrious warnings from PortAudio and OSX

This commit is contained in:
Spencer Russell 2016-08-16 19:19:35 -04:00
parent fcf87c0c61
commit 80af028efb

View file

@ -26,7 +26,9 @@ const CHUNKSIZE=128
function __init__() function __init__()
# initialize PortAudio on module load # initialize PortAudio on module load
swallow_stderr() do
Pa_Initialize() Pa_Initialize()
end
# the portaudio callbacks are parametric on the sample type # the portaudio callbacks are parametric on the sample type
global const pa_callbacks = Dict{Type, Ptr{Void}}() global const pa_callbacks = Dict{Type, Ptr{Void}}()
@ -118,8 +120,10 @@ type PortAudioStream{T, U}
end end
this.bufinfo = CallbackInfo(inchans, this.source.ringbuf, this.bufinfo = CallbackInfo(inchans, this.source.ringbuf,
outchans, this.sink.ringbuf, synced) outchans, this.sink.ringbuf, synced)
this.stream = Pa_OpenStream(inparams, outparams, float(sr), blocksize, this.stream = swallow_stderr() do
Pa_OpenStream(inparams, outparams, float(sr), blocksize,
paNoFlag, pa_callbacks[T], fieldptr(this, :bufinfo)) paNoFlag, pa_callbacks[T], fieldptr(this, :bufinfo))
end
Pa_StartStream(this.stream) Pa_StartStream(this.stream)
@ -333,6 +337,18 @@ function portaudio_callback{T}(inptr::Ptr{T}, outptr::Ptr{T},
end end
"""Call the given function and discard stdout and stderr"""
function swallow_stderr(f)
origerr = STDERR
(errread, errwrite) = redirect_stderr()
result = f()
redirect_stderr(origerr)
close(errwrite)
close(errread)
result
end
memset(buf, val, count) = ccall(:memset, Ptr{Void}, memset(buf, val, count) = ccall(:memset, Ptr{Void},
(Ptr{Void}, Cint, Csize_t), (Ptr{Void}, Cint, Csize_t),
buf, val, count) buf, val, count)