Build a Multi-Channel Matrix Mixer with Ecasound

Ecasound is a powerful command-line multitrack audio processing tool capable of complex signal routing, filtering, and real-time level adjustment on Linux and Unix systems. This guide provides a direct walkthrough of configuring Ecasound as a flexible multi-channel matrix mixer, allowing you to route any combination of inputs to any combination of outputs with independent gain control using native chain operators and the Ecasound Control Interface (ECI).

Matrix Mixer Fundamentals in Ecasound

A matrix mixer routes \(M\) audio inputs to \(N\) audio outputs, allowing variable levels at every intersection point (crosspoint). In Ecasound, this is accomplished by using:

Basic Architecture: 4x4 Matrix Example

In this example, we configure a 4-channel input device routed to a 4-channel output device, creating a fully addressable 4x4 matrix mixer using JACK audio connections.

1. Defining Chains for Crosspoint Control

To adjust individual crosspoints independently, assign a distinct chain for each input-to-output path, or organize chains by target output channel. Grouping by output channel allows individual input levels to be summed into each output bus.

ecasound \
  -f:f32_le,4,48000 \
  -a:in -i jack,system:capture_ \
  -a:bus1,bus2,bus3,bus4 -i null \
  -a:out1 -f:f32_le,1,48000 -o jack,system:playback_1 \
  -a:out2 -f:f32_le,1,48000 -o jack,system:playback_2 \
  -a:out3 -f:f32_le,1,48000 -o jack,system:playback_3 \
  -a:out4 -f:f32_le,1,48000 -o jack,system:playback_4

2. Splitting and Routing Channels

To construct the matrix within a single command using ALSA or JACK, you can use the channel copy/mix routing operator -erc:from_channel,to_channel alongside chain-specific gain operators:

ecasound -B:rt -r:50 \
  -a:matrix_in -i alsa,default -f:s16_le,4,44100 \
  -a:out_ch1,out_ch2,out_ch3,out_ch4 -i null \
  -a:out_ch1 -f:s16_le,1,44100 -o alsa,hw:0,0 \
  -a:out_ch2 -f:s16_le,1,44100 -o alsa,hw:0,1 \
  -a:out_ch3 -f:s16_le,1,44100 -o alsa,hw:0,2 \
  -a:out_ch4 -f:s16_le,1,44100 -o alsa,hw:0,3

A more modular approach uses internal looping devices (loop,label) to route multi-channel inputs across parallel chains:

ecasound -B:rt \
  -a:input -i jack,system:capture_ -f:f32_le,4,48000 -o loop,input_bus \
  -a:mix1,mix2,mix3,mix4 -i loop,input_bus \
  -a:mix1 -chcopy:1,1 -ea:100 -chcopy:2,1 -ea:50  -f:f32_le,1,48000 -o jack,system:playback_1 \
  -a:mix2 -chcopy:1,1 -ea:0   -chcopy:2,1 -ea:100 -f:f32_le,1,48000 -o jack,system:playback_2 \
  -a:mix3 -chcopy:3,1 -ea:75  -chcopy:4,1 -ea:25  -f:f32_le,1,48000 -o jack,system:playback_3 \
  -a:mix4 -chcopy:1,1 -ea:25  -chcopy:4,1 -ea:100 -f:f32_le,1,48000 -o jack,system:playback_4

In this setup:

Real-Time Matrix Control

A static matrix mixer is rarely sufficient; you often need dynamic adjustments of crosspoint levels without restarting the audio engine. Ecasound accommodates this via its interactive mode or background daemon mode.

Interactive Mode

Run Ecasound with the -c flag to enter interactive mode:

ecasound -c -B:rt \
  -a:1 -i jack,system:capture_1 -o jack,system:playback_1 -ea:100 \
  -a:2 -i jack,system:capture_1 -o jack,system:playback_2 -ea:0

Inside the interactive prompt, you can change gains dynamically:

c-select 2
ea-set 75

This selects Chain 2 and immediately updates its amplification operator to 75%.

Automated and Remote Control with Net-ECI

For building graphical user interfaces or external hardware controllers (such as MIDI or OSC bridges), start Ecasound with a TCP control server:

ecasound --daemon --server --server-tcp-port=2868

You can then send text commands over a TCP socket from any programming language:

# Connect using netcat or telnet
nc localhost 2868

# Example session commands
c-add ch1_to_out2
c-select ch1_to_out2
ai-add jack,system:capture_1
ao-add jack,system:playback_2
cop-add -ea:0
start
cop-set 1 1 80

Low Latency Tuning

Matrix mixers require minimal processing latency. Ensure your Ecasound command includes optimized buffer settings: