Dynamic Audio Routing in Ecasound with ECI
Ecasound Control Interface (ECI) scripts provide powerful programmatic control over audio processing, but they cannot directly alter native routing topologies while the playback engine is running. While ECI allows extensive real-time manipulation of effect parameters, controller values, and volume levels during playback, modifying the core structure of chains, inputs, and outputs requires the engine to be stopped. However, audio engineers can achieve seamless or near-seamless dynamic rerouting through specific architectural strategies, such as pre-routing with channel mutes or offloading stream routing to the JACK Audio Connection Kit.
Native Engine Constraints
In Ecasound's architecture, audio processing takes place inside an
active chainsetup. When the processing engine starts via the
start command, Ecasound locks the active chainsetup's
topology.
Commands that modify structural routing—such as adding inputs
(ai-add), adding outputs (ao-add), creating
new chains (c-add), or altering chain attachments—are
rejected by the engine if it is in a running state. Attempting to issue
structural configuration commands through ECI while playback is active
returns an error stating that the operation requires the engine to be
stopped.
Workaround 1: Pre-Configured Chains and Muting
To dynamically change routing without stopping the engine, you can pre-allocate all required routing paths in the chainsetup prior to starting playback. Once running, ECI can alter the flow of audio instantly without stopping the stream:
- Muting and Bypassing: Use
c-muteandc-bypassto silence or activate specific chains on demand. - Volume Crossfading: Insert volume operators
(
cop-add pan-volumeor amplifier stages) on separate chains. An ECI script can automate crossfades between different chains usingcop-setto divert audio from one destination to another smoothly without audio dropouts or clicks.
Workaround 2: Routing via the JACK Audio Connection Kit
If genuine dynamic rerouting of physical inputs and outputs is required during runtime, the industry-standard solution is running Ecasound with the JACK driver:
- Configure Ecasound's audio inputs and outputs as JACK client ports
(for example,
ai-add jackandao-add jack). - Start the Ecasound engine; it will register its audio ports with the JACK server.
- Use ECI or separate JACK routing tools (such as
jack_connectandjack_disconnect, or the JACK C/Python APIs) to rewire audio between applications, hardware interfaces, and Ecasound chains.
Because JACK handles the interconnects outside of Ecasound's internal engine lock, connections can be patched and unpatched dynamically without interrupting Ecasound’s internal playback loop.
Workaround 3: Fast Programmatic Stop-and-Restart
If routing topology must change internally within Ecasound and JACK is not an option, ECI can be used to stop, modify, and restart the engine in a single automated sequence:
- Call
stop. - Apply changes (
c-add,ai-add,ao-add, or select an alternative prepared chainsetup usingcs-select). - Call
prepareandstart.
Using ECI via local sockets or compiled language bindings (such as C, C++, or Python), this cycle typically completes within a few milliseconds. However, this approach will cause a brief momentary interruption in the audio buffer, making it unsuitable for applications requiring uninterrupted continuous streaming.