m4_include(`header.html')
Issues to consider when porting programs to JACK
Sample bit width assumptions
A lot existing Linux audio software tends to assume that audio samples
are 8 or 16 bits wide, and uses short
to store them. This
does not work with JACK, where all sample data, regardless of the
original data format in which it was obtained (e.g. from disk), is
stored as a floating point value normalized to the range -1.0 to +1.0.
Channel interleaving assumptions
Almost all existing Linux audio software assumes that when delivering
a sample stream with more than one channel, the samples should be
interleaved. This does not work with JACK, where all sample streams
are mono.
Block-on-write or block-on-read assumptions
Quite a lot of existing Linux audio software tends to be structured
around the blocking behaviour of a call to write(2) or read(2) when
the file descriptor concerned refers to the audio interface. They
often have this structure:
// Playback
while (1) {
get_sample_date_from_somewhere (buf);
write (audiofd, buf, bufsize);
}
// Capture
while (1) {
read (audiofd, buf, bufsize);
put_sample_data_somewhere (buf);
}
These structures don't work with JACK, which is entirely callback
driven and moves audio data by copying it to and from memory
locations, not files. Instead, its necessary to define a
process()
callback which does this:
// playback
int
process (nframes_t nframes)
{
get_nframes_of_data_from_somewhere_without_blocking (buf);
sample_t *addr = jack_port_get_buffer (playback_port);
memcpy (addr, buf, nframes * sizeof (sample_t));
}
// capture
int
process (nframes_t nframes)
{
sample_t *addr = jack_port_get_buffer (capture_port);
memcpy (buf, addr, nframes * sizeof (sample_t));
put_nframes_of_data_somewhere_without_blocking (buf);
}
The code in the process()
function should not under
(almost) any circumstances block: that is, it may not read/write data
from/to a file, it may not call malloc(), it may not use
pthread_mutex_lock(), and it should generally avoid system calls. the
process()
callback will be executed when the JACK server
decides it should be, and it cannot be used to time other parts of the
program.
m4_include(`trailer.html')