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:
- Audio Inputs and Outputs (
-iand-o): Physical soundcards via ALSA, virtual endpoints via JACK, or audio files. - Chains (
-a:chain_id): Signal flow pathways through which audio is passed, mixed, and processed. - Routing Operators (
-erc,-chcopy,-chmix): Tools to route specific channel indices across chains. - Amplitude Operators (
-eaor-eadb): Controls to adjust the gain of specific crosspoints.
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_42. 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,3A 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_4In this setup:
-chcopy:X,Ycopies audio from input channelXto destination channelY.-ea:Zapplies a linear gain percentage (\(0\) to \(100+\)) to that channel segment.- You can substitute
-eadb:dBto set gain values in decibels directly (e.g.,-eadb:-6for a 6 dB cut).
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:0Inside 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=2868You 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 80cop-add -ea:0adds an amplification operator set to 0%.cop-set 1 1 80updates operator parameter index 1 on chainch1_to_out2to 80% volume in real time.
Low Latency Tuning
Matrix mixers require minimal processing latency. Ensure your Ecasound command includes optimized buffer settings:
-B:rt: Enables real-time buffering mode.-b:128: Sets the internal buffer size to 128 frames (adjust according to your audio interface's hardware period size).-r:50: Increases the engine execution rate to reduce event handling latency.