How to Swap Audio Channels in Ecasound

This article explains how to swap audio channels within an audio stream using Ecasound. It identifies the primary channel routing operator, breaks down how it functions, and provides practical command-line examples for exchanging the left and right channels in a stereo file without losing audio data.


In Ecasound, channel manipulation and routing are handled by the -erc (route/copy channel) chain operator. The syntax for this operator is:

-erc:from_channel,to_channel

This operator copies audio samples from from_channel to to_channel. If the destination channel does not exist in the stream yet, Ecasound dynamically creates it.

Swapping Channels Using a Temporary Channel

Because Ecasound does not feature a single, standalone "swap" command, a direct swap requires a temporary intermediate channel. If you copy channel 1 directly to channel 2 (-erc:1,2), the original audio in channel 2 is overwritten before it can be moved to channel 1.

To swap channels 1 and 2 (such as Left and Right in a stereo track), route through a temporary third channel using three consecutive -erc operators:

  1. Copy channel 1 to temporary channel 3: -erc:1,3
  2. Copy channel 2 to channel 1: -erc:2,1
  3. Copy temporary channel 3 to channel 2: -erc:3,2

Command-Line Example

To swap the left and right channels of a stereo WAV file and output a clean two-channel file, specify the audio format on the output stream to discard the temporary third channel:

ecasound -i:input.wav -erc:1,3 -erc:2,1 -erc:3,2 -f:s16_le,2,44100 -o:output.wav

In this command: