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:
1.0represents maximum positive full-scale (\(0\text{ dBFS}\)).-1.0represents maximum negative full-scale (\(-0\text{ dBFS}\)).0.0represents absolute silence.
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:
- \(S_{i}[n]\) represents the processed sample value from chain \(i\) at index \(n\).
- \(M\) is the total number of chains routed to that target output.
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:
- Floating-Point Destinations (e.g., 32-bit Float WAV, JACK): If the output preserves floating-point representation, summed values exceeding \(\pm 1.0\) are written directly without clipping. Downstream software or floating-point audio servers can attenuate the signal later without loss of dynamic range.
- Fixed-Point Hardware and Formats (e.g., 16-bit or 24-bit PCM): When writing to fixed-point audio devices or standard integer files, Ecasound clamps (hard-clips) any value outside the range of \([-1.0, 1.0]\). A summed value of \(1.4\) is truncated to \(1.0\), resulting in severe digital harmonic distortion.
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:
-ea:gain%(Linear percentage, where 100 is unity gain)-eadb:gain_dB(Logarithmic decibel scaling)
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:
- Submix Chains: Route input sources through
individual chains (
chain1,chain2, etc.) and set their output toloop,master_bus. - Master Chain: Create a dedicated chain
(
chain_master) whose input isloop,master_busand whose output is the physical audio device or target file. - Master Volume Operator: Place an
-eaor-eadboperator onchain_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.