Ecasound Linear Crossfade Operator Guide

This article provides a direct overview of how to perform linear crossfading between two audio streams using Ecasound. While Ecasound lacks a single dedicated "crossfade" filter, it achieves precise linear crossfading via the -klg (linear envelope) controller operator applied to the -ea (amplify) effect operator across multiple audio chains. Below is a breakdown of how the operator works, its syntax, and an implementation example.

The Linear Crossfade Operator: -klg

In Ecasound, dynamic parameter automation is handled by controller operators. The operator responsible for linear changes over time is -klg.

To crossfade between two separate streams, -klg is assigned to each stream's chain to dynamically control the amplitude parameter of the -ea operator. One chain ramps its volume down linearly, while the other ramps its volume up.

Syntax of the -klg Operator

-klg:fx_param,start_val,end_val,len,delay

The operator takes five parameters:

Implementing a Crossfade Between Two Streams

To perform a linear crossfade between two input files, configure two separate processing chains that mix into a single output.

Command Example

ecasound \
  -a:1 -i:stream1.wav -ea:100 -klg:1,100,0,5,10 \
  -a:2 -i:stream2.wav -ea:0   -klg:1,0,100,5,10 \
  -a:1,2 -o:mixed_output.wav

How the Command Works

  1. Chain Allocation (-a:1 and -a:2): Sets up two parallel processing chains for stream1.wav and stream2.wav.
  2. Stream 1 Fade-Out:
    • -ea:100 sets the base volume to 100%.
    • -klg:1,100,0,5,10 begins after a 10-second delay, linearly decreasing parameter 1 of -ea from 100% to 0% over 5 seconds.
  3. Stream 2 Fade-In:
    • -ea:0 sets the base volume to 0% (silence).
    • -klg:1,0,100,5,10 begins after a 10-second delay, linearly increasing parameter 1 of -ea from 0% to 100% over 5 seconds.
  4. Mixed Output (-a:1,2 -o:mixed_output.wav): Merges both chains into a single destination audio file with the linear crossfade applied.