Ecasound Master Gain Across Summed Chains

This article explains how Ecasound calculates and manages master output gain when multiple audio chains are summed into a single destination. It details the underlying mathematical summing model, internal sample representations, dynamic range implications, and practical methods for implementing true master gain control within Ecasound’s routing architecture.

Internal Audio Representation

Ecasound handles real-time audio routing and signal processing using internal floating-point arithmetic (typically 32-bit float or 64-bit double, depending on compilation flags). Audio samples streamed through chains are normalized to a standard floating-point range where:

Because internal processing operates in the floating-point domain, audio headroom within Ecasound's internal buffers can exceed +1.0 or drop below -1.0 without instantaneous distortion or digital flat-line truncation.

Summation Mechanism Across Chains

When multiple chains are assigned to the same output object (such as an ALSA soundcard, a JACK port, or an audio file), Ecasound performs linear arithmetic summation.

For an output receiving audio from \(M\) independent chains at discrete sample index \(n\), the combined output sample \(S_{\text{out}}[n]\) is calculated as:

\[S_{\text{out}}[n] = \sum_{i=1}^{M} S_{i}[n]\]

Where:

Ecasound does not apply automatic gain compensation, normalization, or division by the number of active chains (\(1/M\)). If two identical, fully coherent signals peaking at \(0\text{ dBFS}\) (\(1.0\)) are routed to the same output, the linear summation yields a peak amplitude of \(2.0\), which corresponds to an increase of \(+6.02\text{ dBFS}\).

Output Conversion and Clipping Behavior

The implications of Ecasound's linear summation depend entirely on the target output format:

Controlling Master Output Gain

Because Ecasound treats outputs as passive targets rather than active processing nodes, there is no native "master fader" parameter directly attached to an output device. To establish master output gain across multiple summed chains, two primary approaches are used:

1. Individual Chain Attenuation

You can attenuate each chain independently using amplitude operators before the summing stage:

To prevent clipping across \(M\) uncorrelated channels summing to unity, you can set individual chain levels using the formula:

\[\text{Attenuation (dB)} = -10 \cdot \log_{10}(M)\]

For fully correlated signals, the worst-case formula is:

\[\text{Attenuation (dB)} = -20 \cdot \log_{10}(M)\]

2. Loop Device Topology (Dedicated Master Bus)

To create a true unified master gain control, route all active audio chains into an intermediate loop device (loop,master_bus). The loop device is then assigned as the input to a dedicated master chain that holds the global gain operator:

  1. Submix Chains: Route input sources through individual chains (chain1, chain2, etc.) and set their output to loop,master_bus.
  2. Master Chain: Create a dedicated chain (chain_master) whose input is loop,master_bus and whose output is the physical audio device or target file.
  3. Master Volume Operator: Place an -ea or -eadb operator on chain_master.

In this configuration, linear summation occurs when the audio enters the loop device. The master chain then scales the summed signal via floating-point multiplication before the audio reaches the output stage:

\[S_{\text{final}}[n] = G_{\text{master}} \cdot \sum_{i=1}^{M} S_{i}[n]\]

This prevents fixed-point integer clipping at the final output while providing a single, controllable master volume fader.