How Ecasound Handles Integer Bit Depths
This article provides an overview of how the Ecasound command-line digital audio workstation handles integer sample bit depths, specifically 16-bit, 24-bit, and 32-bit formats. It explores Ecasound's internal processing pipeline, the conversion mechanisms used when reading and writing integer streams, format configuration syntax, and important considerations regarding quantization and clipping.
Internal Floating-Point Architecture
Regardless of the input or output format, Ecasound does not process
audio using integer arithmetic. Internally, Ecasound converts all
incoming audio streams into single-precision 32-bit floating-point
samples (represented as the sample_t type). This internal
pipeline ensures that mixing, level adjustments, filtering, and effects
processing maintain high precision and avoid the dynamic range
limitations, truncation noise, and headroom issues associated with
fixed-point integer calculations.
Ingestion: Converting Integers to Floats
When an audio source with an integer format is ingested—whether from
a file, an ALSA/JACK device, or standard input—Ecasound unpacks the
integer data and normalizes it to a normalized floating-point range of
[-1.0, 1.0]:
- 16-bit Integer (
s16_le/s16_be): The 16-bit signed integer values (ranging from -32,768 to +32,767) are divided by 32,768.0 to map them into the floating-point domain. - 24-bit Integer (
s24_le/s24_3le): Ecasound supports both packed 3-byte formats (s24_3le) and 4-byte aligned formats (s24_le). The 24-bit range is scaled down to[-1.0, 1.0]with no loss of precision. - 32-bit Integer (
s32_le/s32_be): 32-bit signed integers are mapped directly to the float domain, though slight rounding can occur due to the 24-bit mantissa of 32-bit single-precision floats.
Format Specification Syntax
Ecasound uses the -f flag to define format parameters
for inputs and outputs that do not contain explicit header information
(such as raw PCM streams, soundcard devices, or headerless files). The
syntax follows this order:
-f:sample_format,channels,sample_rate,interleaving
Common integer format identifiers include:
s16_le: Signed 16-bit, little-endians24_le: Signed 24-bit in 32-bit containers, little-endians24_3le: Packed signed 24-bit (3 bytes per sample), little-endians32_le: Signed 32-bit, little-endian
For standard container formats like WAV or AIFF, Ecasound reads the bit depth directly from the file header, converting the designated integer type to floating-point automatically upon import.
Output: Quantization and Clamping
When routing internal audio to an integer output target (such as writing a 16-bit or 24-bit WAV file, or sending a stream to a hardware soundcard), Ecasound performs the reverse conversion:
- Clamping: Because floating-point operations can
exceed
+1.0or-1.0during mixing or amplification, the audio engine clips any values outside this boundary before converting to integer formats. If internal signals peak above 0 dBFS, digital clipping will occur in the integer output. - Quantization: The float values within
[-1.0, 1.0]are multiplied back into the integer range of the target bit depth and rounded. For example, rendering to 16-bit integer multiplies the float values by 32,767.0 and casts them to signed 16-bit integers. - Dithering Considerations: Ecasound focuses primarily on fast, real-time routing and processing. Direct sample-format downsampling (such as converting internal floats to 16-bit outputs) relies on standard truncation and rounding unless explicitly routed through a dedicated dithering plugin or external processor. For high-resolution mastering, processing at 24-bit or 32-bit float output preserves resolution and minimizes quantization distortion.