Ecasound Sample Rate Mismatches in Chainsetups

Ecasound processes multitrack audio under a unified processing engine, which means that every chain within an active chainsetup must adhere to a single global sample rate. When inputs, outputs, or individual chains contain conflicting sample rates, Ecasound does not run independent, asynchronous clock domains across those chains. Instead, it resolves mismatches through global format negotiation, integration with underlying sound architectures, integrated resampling algorithms, or by reporting configuration errors.

The Global Clock Rule in Ecasound

An Ecasound chainsetup strictly operates on a single master sample rate. When a chainsetup is initialized, Ecasound establishes its engine parameters—specifically sample format, channel count, and sample rate—either derived from an explicit global format argument (-f), negotiated from the primary audio device, or inherited from the first defined audio input.

Because every processing chain in a chainsetup executes concurrently within the same processing loop, audio buffers must contain the exact same number of samples per unit of time across all chains. Ecasound cannot process one chain at 44.1 kHz and another chain at 96 kHz simultaneously inside the same internal mixing graph.

File Input Handling and Automatic Resampling

When reading from audio files (such as WAV, FLAC, or AIFF) that possess a sample rate different from the chainsetup's designated rate, Ecasound's behavior depends on the audio file library it was compiled with:

Real-Time Devices: ALSA, JACK, and OSS

Real-time audio backends introduce hard constraints when dealing with rate discrepancies across chains:

Manual Sample Rate Conversion Operators

For precise control over quality and resource usage, Ecasound includes native rate conversion operators that can be inserted into individual chains.

Behavior with Raw Audio Streams

When using raw, headerless audio streams (-i:stdin, raw audio files, or pipes), Ecasound has no metadata to detect a mismatch. If a raw stream recorded at 48 kHz is fed into a chain configured for 44.1 kHz, Ecasound will process the samples at the chainsetup's rate without resampling. This results in pitch alteration and speed distortion (the audio plays back slower or faster) rather than a software error.

Summary of Resolution Methods

To maintain stability across chains with mismatched rates:

  1. Define a Master Format: Explicitly state the target rate using the global -f flag (e.g., -f:s16_le,2,48000) so the engine establishes a definitive processing standard.
  2. Use Software Device Plugins: Use ALSA's plughw or software wrappers to standardize hardware rates before they reach Ecasound.
  3. Pre-convert Sources: Use offline tools like sox to resample disparate audio files prior to assembling the chainsetup, ensuring minimal CPU overhead and optimal synchronization.