Ecasound Big-Endian vs Little-Endian in Raw Files

Ecasound handles big-endian and little-endian byte ordering in raw audio files through explicit sample format definitions, host-architecture defaults, and internal sample conversion. Because raw PCM data lacks header metadata to identify byte order, Ecasound requires users to declare the endianness using specific audio format flags. Once ingested, Ecasound normalizes the audio into an internal floating-point representation, allowing seamless conversion between different byte orders during input, processing, and output.

The Necessity of Explicit Format Tags

Standard audio formats like WAV (predominantly little-endian) and AIFF (predominantly big-endian) store byte order details in their container headers. Raw files (such as .raw, .pcm, or .cdr) contain only sample data. When multi-byte samples (such as 16-bit, 24-bit, or 32-bit audio) are read, the system must know whether the most significant byte comes first (big-endian, be) or last (little-endian, le).

If raw data is read with the incorrect byte order, the resulting audio turns into loud static or noise. Ecasound solves this by making audio format parameters mandatory when opening raw files.

Endian Specifiers in Ecasound

Ecasound defines audio streams using the format parameter:

-f:sample_format,channels,sample_rate,interleave

Within the sample_format field, endianness is explicitly defined using _le (little-endian) or _be (big-endian) suffixes:

For 8-bit formats (such as u8 or s8), endianness is irrelevant because samples consist of only a single byte.

Native Endianness and Fallbacks

If a format string is provided without an endianness suffix (for example, s16 or s32), Ecasound falls back to the native endianness of the host CPU running the software.

To maintain portability and avoid processing errors across different systems, explicit suffixes (_le or _be) should always be declared when working with raw files.

Internal Normalization and Byte Swapping

Ecasound does not perform audio effects or routing directly on raw byte arrays. Instead, it converts incoming raw audio data immediately upon ingestion into an internal standard format, typically 32-bit or 64-bit floating-point samples.

During this conversion phase:

  1. Ecasound reads the byte stream matching the input format specification.
  2. If the declared input endianness differs from the host processor's native order, Ecasound performs byte-swapping operations on the input buffer.
  3. The samples are translated into normalized floating-point numbers.
  4. Any designated signal processing, mixing, or routing occurs.
  5. If the target output is also a raw file, Ecasound encodes the normalized internal float data into the target byte order specified in the output format rule, applying reverse byte swapping if necessary.

Practical Command Example

To convert a raw, 16-bit big-endian stereo file recorded at 48kHz into a standard 16-bit little-endian raw file, both format specifications must be declared:

ecasound -f:s16_be,2,48000 -i raw_input.raw -f:s16_le,2,48000 -o raw_output.raw

In this command: