[Portaudio] architecture question: two audio threads?

Ross Bencina rossb-lists at audiomulch.com
Mon Feb 19 22:13:10 EST 2018


Hi Diemo,

> Is it somehow possible to run two audio threads, the outputs of which
> get mixed? Maybe by opening the same output devide twice?

This might work with some host APIs. PortAudio doesn't officially 
support, or not-support this. If the native API allows the same device 
to be opened multiple times by one application, then hopefully PortAudio 
supports it. YMMV however.


> Will the synchronisation still be assured,

PortAudio would be oblivious to the two streams using the same device, 
so it would be down to the native API behavior whether the two streams a 
synchronised. My guess would be on MacOS: NO, with ALSA: Maybe, with 
JACK: probably.

> or can I rely on the time
> reporting of the audio callback?

On Mac, definitely, on Linux, not sure, probably. But keep in mind that 
the time reporting will have some jitter/noise -- so the timing will 
need some filtering too.


> Two threads are good for distributing the load of time-stretching, and
> it would be nice if I could avoid the complexity of fifo-ing two
> self-managed worker threads' results into the audio thread.

I think that's the more predictable and portable option though. You 
could compute one of your threads on the main audio callback, and some a 
kind of spin-barrier to kick off the secondary thread: then you don't 
need a FIFO, just some synchronous buffering. On Linux you can use 
isolcpus to ensure that the secondary thread gets its own dedicated core.

Cheers,

Ross.


More information about the Portaudio mailing list