[Portaudio] Do I need to care about overflow/underflow when using the read/write API?

Spencer Russell sfr at media.mit.edu
Mon Mar 21 13:35:12 EDT 2016


> On Mar 20, 2016, at 2:24 PM, Alan Horstmann <gineera at aspect135.co.uk> wrote:
> 
> On Sunday 20 March 2016 03:46, Spencer Russell wrote:
> 
>> If the underflow is passed to the Host API, in practice are there APIs in
>> the wild that react poorly, or is it OK?
> 
> Certainly on Linux-Alsa when an underrun occurs the audio system stops.  When 
> Portaudio is notified it will attempt to restart the stream, but this can 
> take a significant amount of time, in some cases that have been reported.
> 
> On Sunday 20 March 2016 04:36, Phil Burk wrote:
>> You should avoid underflows and overflows. Those are errors and should
>> never be allowed to happen. If you don't have any signal then just write
>> silence (zeros) to keep the stream from underflowing. Or, if you don't plan
>> on doing any audio for a few minutes then you could just shut down the
>> stream and restart it when you are ready.
> 
> Agree completely - don't let underflows and overflows happen; feed zero data 
> somehow otherwise it will perform very poorly.

Thanks all for your feedback and details. I think I was conceptualizing the case where PortAudio’s read/write API was wrapping a callback API like JACK, but I see how if it’s wrapping another read/write Host API then it doesn’t really have the opportunity to protect the app from underruns and feed zeros.

I’ll rework my wrapper to use the callback API to feed data to/from Julia-land, so that any underruns stay in my wrapper and the callback gets zeros.

-s


More information about the Portaudio mailing list