[linux-audio-dev] Jack and sample rate conversion : realtime or not ?
ml at xung.org
Thu Mar 24 11:28:30 UTC 2005
Tom Szilagyi wrote:
>>- convert in real time, in the process callback ?
>>- convert the whole file into memory when loading it ?
> my music player Aqualung (http://aqualung.sf.net) does the former,
> however not in the JACK process callback (since it also supports ALSA
> and OSS output) but in the disk thread which reads and decodes audio
> files and resamples them (if necessary) in a buffer-by-buffer manner
> via libsamplerate so it can be sent to the output thread.
Thanks for pointing that third option :
- convert in the disk thread
> If you're interested in the details, you may look at src/core.c in the
> Aqualung codebase. Beware, though, that it's not particularly easily
> readable by humans :)
I'll try and check that out when I'm about to add support for streaming from disk.
> Loading the whole file into memory sounds a bit pathologic IMHO (no
> offense incl.)
I ain't that pathologic for a sequencer/drummachine as my application Jackbeat
(http://xung.org/jackbeat), where sound files are often small ones. But I want
to add configurable support for disk-streaming at some point in the future. For
now, loading the sample into memory is a simple and efficient method, which
AFAIK is pretty common in trackers, for example.
Additionally, because Jackbeat is supposed to support an unlimited number of
tracks, it may be required to stream many (16,32,64,..) sound files from disk in
parallel, which is not very smart either.
The main reason I was afraid of putting the sample rate conversion routines in
the realtime Jack thread is CPU load : the best quality libsamplerate converter
is pretty heavy. Imagine that with 32 tracks... Now, I could add an option like
"Which libsamplerate's converter do you want to use ?", so that people can tweak
it according to their CPU power.
However, IMHO, converting when loading the sample has the advantage to allow
slow CPUs to use the best converter. Currently "loading" means allocating
memory, but that could also mean creating temporary files, and streaming from these.
Needs a bit more thinking though.
More information about the Linux-audio-dev