Ecasound Multichannel ALSA Audio Setup

This article explains how Ecasound interacts with Advanced Linux Sound Architecture (ALSA) hardware to record, process, and play back more than two channels of audio. It covers the required ALSA device specifications, channel configuration formats, and the internal routing operators Ecasound uses to manage individual audio channels across complex signal chains.

Direct ALSA Hardware Access

Standard ALSA software plugins, such as dmix or default, often restrict stream input and output to 2-channel stereo. To access all channels on a multichannel soundcard, Ecasound must communicate directly with the ALSA hardware device using the alsahw or hw interface instead of the generic alsa layer.

The device syntax follows this structure:

alsahw:CARD,DEVICE

For instance, addressing device 0 on card 1 requires -i:alsahw:1,0 for input or -o:alsahw:1,0 for output. Using direct hardware access bypasses operating system resampling and channel downmixing, exposing the full channel capability of the card.

Specifying Format and Channel Count

Ecasound requires explicit format definitions to negotiate multichannel buffers with the ALSA driver. This is configured via the audio format parameter (-f):

-f:sample_format,channels,sample_rate

When handling an 8-channel interface recording at 24-bit/48kHz, the command must explicitly request all 8 channels:

-f:s24_le,8,48000

If the channel count specified does not match the physical hardware requirements, ALSA will reject the stream. Certain interfaces require specific interleaved channel counts (e.g., must open exactly 8 or 16 channels, even if only four are needed).

Managing Multichannel Routing with Chains

Ecasound processes audio using independent processing paths called "chains." By default, an audio object attached to a chain receives all channels defined by the stream format. To process individual channels or sub-mixes independently, Ecasound uses internal channel-routing operators:

Example: Recording Multichannel Input to Separate Files

To capture specific channels from a multichannel interface into separate audio files, Ecasound assigns the ALSA input to multiple chains and isolates the channels on each:

ecasound \
  -a:1 -i:alsahw:1,0 -f:s32_le,8,48000 -erc:1,1 -o:track1.wav -f:s32_le,1,48000 \
  -a:2 -i:alsahw:1,0 -f:s32_le,8,48000 -erc:2,1 -o:track2.wav -f:s32_le,1,48000

In this setup:

  1. Two chains (1 and 2) pull from the 8-channel physical interface (alsahw:1,0).
  2. Chain 1 routes hardware input channel 1 to mono channel 1 (-erc:1,1) and outputs to track1.wav.
  3. Chain 2 routes hardware input channel 2 to mono channel 1 (-erc:2,1) and outputs to track2.wav.

Example: Multichannel Playback Routing

To route different stereo stems or mono sources out to distinct physical hardware outputs on an 8-channel interface:

ecasound \
  -a:1 -i:stereo1.wav -erc:2,2 -erc:1,1 \
  -a:2 -i:stereo2.wav -erc:2,4 -erc:1,3 \
  -a:1,2 -f:s32_le,8,48000 -o:alsahw:1,0

Here, Chain 1 assigns its stereo tracks to hardware outputs 1 and 2, while Chain 2 routes its channels to physical outputs 3 and 4. Both chains output to the combined 8-channel ALSA device.

Buffer and Latency Considerations

Multichannel operations require significantly more system bandwidth than stereo feeds. If buffer underruns (xruns) occur when opening multiple channels, buffer settings can be optimized using:

Matching the buffer size to an exact power of two (such as 128, 256, or 512) helps maintain synchronization across all active hardware channels.