Mirror Audio to Disk and Speakers with Ecasound
Ecasound is fully capable of mirroring an incoming audio stream directly to disk while simultaneously routing it to physical speakers in real time. This article explains how Ecasound's multitrack architecture enables audio duplication across multiple endpoints, provides the exact command-line syntax required to implement this routing, and covers essential settings for sample formats and buffer management.
How Audio Duplication Works in Ecasound
Ecasound handles signal flow using "chains." A chain is a signal path that connects inputs, audio effects, and outputs. To mirror an incoming signal to two separate destinations, Ecasound assigns a single audio input to multiple chains at the same time. One chain is configured to direct the stream to an audio file on disk, while the second chain directs the stream to a hardware audio device connected to physical speakers.
The Command Structure
The core mechanism relies on the chain assignment flag
(-a). By defining multiple chain identifiers
simultaneously, you can map one input to both chains before splitting
their outputs.
A standard command using the ALSA sound subsystem follows this structure:
ecasound -a:1,2 -i:alsahw:1,0 -a:1 -o:recording.wav -a:2 -o:alsahw:0,0Command Breakdown
-a:1,2 -i:alsahw:1,0: Creates Chain 1 and Chain 2, assigning the input audio stream from the specified capture device (alsahw:1,0) to both chains concurrently.-a:1 -o:recording.wav: Selects Chain 1 and routes the stream to a local WAV file on the disk.-a:2 -o:alsahw:0,0: Selects Chain 2 and routes the stream to the specified audio output device (alsahw:0,0), delivering sound to your physical speakers.
If using generic ALSA device aliases instead of specific hardware
numbers, alsa or default can be used:
ecasound -a:1,2 -i:alsa -a:1 -o:output.wav -a:2 -o:alsaFormat and Buffer Configuration
To ensure audio fidelity and prevent underruns or buffer overruns
(xruns) during simultaneous disk writes and speaker playback, specify
the audio parameters explicitly using the -f flag:
ecasound -f:s16_le,2,44100 -a:1,2 -i:alsahw:1,0 -a:1 -o:recording.wav -a:2 -o:alsahw:0,0This configuration locks the format to signed 16-bit little-endian
(s16_le), stereo (2), and a 44.1 kHz sample
rate (44100).
To optimize performance and minimize monitoring latency through the
speakers, adjust the global audio buffer size using the -b
option (specifying the buffer size in samples):
ecasound -b:256 -f:s16_le,2,44100 -a:1,2 -i:alsahw:1,0 -a:1 -o:recording.wav -a:2 -o:alsahw:0,0A smaller buffer reduces monitoring latency to the speakers, while a larger buffer provides higher stability against buffer dropouts on slower storage media.