Inverting Audio Phase by Channel in Ecasound
This article explains how to achieve phase inversion on specific audio channels using the command-line digital audio workstation Ecasound. Ecasound processes phase inversion through its amplitude scaling effect by applying a negative gain value. Because processing effects in Ecasound apply globally across all channels within a given processing chain, selectively inverting an individual channel requires routing individual audio channels into independent chains, applying the inversion operator, and recombining them into a unified multi-channel output stream.
The Mechanism of Phase Inversion in Ecasound
Phase inversion (often referred to as phase reversal or a 180-degree polarity flip) is mathematically achieved by multiplying every audio sample’s amplitude by -1. Ecasound natively provides this capability through its amplify effect operator:
-ea:gain_%
When given a positive parameter, -ea changes the volume
linearly (e.g., -ea:100 leaves the audio unchanged). By
supplying a negative percentage—specifically -ea:-100—the
signal’s amplitude values are multiplied by -1 without altering the
volume level, resulting in an exact polarity inversion.
The Channel-Isolation Challenge
In Ecasound, any effect applied to a chain
(-a:chain_name) affects every channel flowing through that
chain simultaneously. If you apply -ea:-100 directly to a
standard stereo or multi-channel file without separation, all channels
will be inverted.
To invert a single channel (for example, the right channel of a stereo file) while leaving other channels untouched, you must isolate the target channel into its own chain before applying the effect.
Step-by-Step Channel Processing
The standard workflow uses Ecasound's multi-chain architecture paired
with channel routing operators (-chorder or
-erc):
- Split into Parallel Chains: Create two or more chains sharing the same multi-channel input source.
- Isolate Channels: Use
-chorderto strip non-target channels from each chain, isolating one channel per chain. - Apply Inversion: Attach
-ea:-100exclusively to the chain holding the channel requiring inversion. - Merge to Output: Route all active chains into a single multi-channel output file.
Concrete Example: Inverting the Right Channel of a Stereo File
The following command demonstrates inverting only the right channel (channel 2) of a stereo file while preserving the left channel (channel 1):
ecasound \
-a:ch_left -i:input.wav -chorder:1 \
-a:ch_right -i:input.wav -chorder:2 -ea:-100 \
-a:ch_left,ch_right -o:output.wavIn this command:
-a:ch_leftdefines a chain for the first channel. It pullsinput.wavand uses-chorder:1to discard channel 2, leaving channel 1 intact at standard polarity.-a:ch_rightdefines a chain for the second channel. It pullsinput.wav, isolates channel 2 via-chorder:2, and applies-ea:-100to invert its polarity.-a:ch_left,ch_right -o:output.wavassigns both chains to the output file. Ecasound automatically interleaves the mono signals from each chain sequentially, mappingch_leftto output channel 1 andch_rightto output channel 2.
Working with Multi-Channel Files (>2 Channels)
For files with more than two channels, extend the pattern by creating
a chain for every channel that must remain untouched, and dedicated
chains with -ea:-100 for the specific channels needing
phase inversion. When mapped to the output, list the chains in the exact
order the channels should be interleaved in the resulting file.