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):

  1. Split into Parallel Chains: Create two or more chains sharing the same multi-channel input source.
  2. Isolate Channels: Use -chorder to strip non-target channels from each chain, isolating one channel per chain.
  3. Apply Inversion: Attach -ea:-100 exclusively to the chain holding the channel requiring inversion.
  4. 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.wav

In this command:

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.