[LAD] Realtime and helper threads

Olivier Guilyardi ml at xung.org
Fri Aug 22 18:26:42 UTC 2008


Hi everyone,

In Jackbeat I perform sample rate conversion using libsamplerate in the realtime
thread. I have recently realized that might be a mistake in regard to
performance. The SRC is used on audio samples which sample rate might differ
from the external (Jack) one, and also as a simple pitch shifter.

But the point is that I do not need to do this heavy computation in realtime.
The audio samples content is known in advance, it isn't as operating on live
audio input.

To my understanding, in the realtime thread one is located in some sort of
abstract instant, between (input) now and (output) now, and therefore one has
very little time. If some computation can be moved out of the RT thread, it
ought to be.

In this regard, I thought about setting a (or several) non-RT helper thread(s)
up, where the heavy stuff would happen, and feed the converted content into the
RT thread through a ringbuffer. I understand that this approach would require
implementing a sync callback for the helper threads to get ready (fill buffers,
etc...) whenever the transport position changes.

I'm asking this because the SRC computation load currently has an impact on the
output quality (ticks, xruns) with many tracks or on slower systems, and I'm
thinking about adding real pitch and time shifting using Rubberband in the near
future, which is certainly going to be a lot heavier.

Is my idea of a helper thread correct? Any clue to set things up properly?

Cheers,

-- 
  Olivier Guilyardi / Samalyse



More information about the Linux-audio-dev mailing list