Ecasound -f Flag: Format, Channels, Sample Rate

The -f flag in Ecasound sets the audio stream parameters for inputs, outputs, and internal processing chains by defining the sample format, channel count, and sampling rate. It is critical when dealing with raw, headerless audio files or when converting between different formats in a signal chain. By using a strict, comma-separated syntax, the -f option tells Ecasound precisely how to interpret or encode binary audio data.

Syntax of the -f Flag

The -f argument accepts values in a structured, comma-separated string:

-f:sample_format,channels,sample_rate[,interleaving]

Each parameter must appear in this exact order. The fourth parameter (interleaving) is optional and defaults to standard interleaved audio.

Parameter Breakdown

1. Sample Format (sample_format)

The sample format defines the bit depth, numeric type, and endianness of each audio sample. Common format descriptors include:

  • Bit representation: s (signed integer), u (unsigned integer), or f (floating point).
  • Bit depth: 8, 16, 24, or 32 bits.
  • Endianness: _le (little-endian) or _be (big-endian). Omitting the endian specifier (e.g., s16) defaults to the host machine's native architecture.

Common examples:

  • s16_le: Signed 16-bit integer, little-endian (standard CD/WAV format).
  • s24_le: Signed 24-bit integer, little-endian (standard high-resolution studio format).
  • s32_le: Signed 32-bit integer, little-endian.
  • f32_le: 32-bit floating point, little-endian (standard for high-precision digital signal processing).
  • u8: Unsigned 8-bit integer.

2. Channel Count (channels)

This parameter defines the number of discrete audio channels as an integer:

  • 1: Mono
  • 2: Stereo
  • 4, 6, 8: Multi-channel or surround setups (such as 5.1 audio using 6).

3. Sample Rate (sample_rate)

The sample rate defines the sampling frequency measured in Hertz (Hz):

  • 44100: Standard CD audio (44.1 kHz).
  • 48000: Standard broadcast and video audio (48 kHz).
  • 88200 or 96000: High-resolution audio.

Scope and Positioning

In Ecasound, order of execution matters. The -f flag affects the objects that follow it or sets global defaults depending on its position:

  • Before an input or output (-i or -o): When placed immediately before an input or output, -f explicitly defines the format for that stream. This is required for raw PCM files (e.g., .raw) that do not possess headers to supply audio metadata.
  • Format conversion: When reading a headered file (like a .wav) with one format and specifying a different -f flag before an output, Ecasound automatically handles resamplers, bit-depth conversions, and channel routing.

Practical Examples

Configuring a standard CD-quality raw file:

ecasound -f:s16_le,2,44100 -i raw_audio.raw -o output.wav

Converting a 44.1 kHz stereo file to 48 kHz, 32-bit floating-point mono output:

ecasound -i input.wav -f:f32_le,1,48000 -o output.wav