How Ecasound Processes Multi-Track CAF Files
This article explains how the Ecasound command-line audio utility handles multi-track Core Audio Format (CAF) files. It covers the underlying libraries responsible for decoding the CAF container, how multi-channel streams are split into processing chains, and the specific routing options available for manipulating multi-track audio effectively.
Decoding CAF Files via libsndfile
Ecasound does not parse the Core Audio Format specification directly;
instead, it relies on libsndfile as its underlying audio
file I/O engine. Because modern versions of libsndfile
support Apple’s CAF specification, Ecasound automatically recognizes
.caf files upon input.
When Ecasound opens a CAF file, it queries libsndfile to
detect the container's structural parameters, such as sample rate, bit
depth, and total channel count. This enables Ecasound to overcome the 4
GB file size limitation common to standard 32-bit RIFF/WAV headers,
making CAF ideal for recording and processing long, high-resolution,
multi-track sessions.
Chain Architecture and Channel Allocation
Ecasound manages audio streams using an architecture based on
"chains." A multi-track CAF file contains interleaved audio channels
within a single container. To process these channels independently,
Ecasound maps the file’s internal tracks to distinct processing chains
using the -a option.
By default, an input file assigned to a single chain reads all channels simultaneously. However, when dealing with multi-track CAF files, you typically route individual channels or sub-mixes into separate chains using channel-routing operators:
-chcopy:src,dst: Copies an audio channel from an input slot to an internal processing slot.-chorder:ch1,ch2,...: Reorders or selects specific channels from the input stream.-chmove:src,dst: Moves a channel, clearing the source slot.
Practical Multi-Track Workflow
To work with a multi-track CAF file, you instantiate the file as an input across multiple chains, then configure channel filtering on each chain.
For example, processing a 4-channel CAF file by splitting tracks 1 and 2 into one stereo chain and tracks 3 and 4 into another is structured as follows:
ecasound \
-a:1 -i:multitrack.caf -chorder:1,2 -o:stereo_mix1.wav \
-a:2 -i:multitrack.caf -chorder:3,4 -o:stereo_mix2.wavIn this command:
-a:1creates the first chain, definesmultitrack.cafas the input, and selects channels 1 and 2 with-chorder:1,2.-a:2creates the second chain, accesses the same file simultaneously, and isolates channels 3 and 4 with-chorder:3,4.- Ecasound reads the interleaved CAF stream, and its internal routing engine dispatches the respective audio samples to the assigned chain buffers before rendering the output.
Real-Time Handling and Buffering
When running multi-track CAF processing in real-time, buffer
management is controlled using the -b:buffersize and
-z:feature flags (such as double-buffering or real-time
priority). Because multi-track audio multiplies the data throughput per
processing cycle, Ecasound reads interleaved multi-channel blocks into
memory, de-interleaves them for internal chain effects or dynamic DSP
plugins (such as LADSPA), and re-interleaves them if the output format
requires it.