MIDI Note Gating for Audio in Ecasound
This article explains how Ecasound utilizes MIDI note-on and note-off messages to gate audio signals in real time. By routing incoming MIDI events to chain operator parameters—specifically volume and amplification controls—Ecasound can open the audio path upon receiving a note-on command and silence it immediately when a corresponding note-off command is detected.
The Underlying Control Mechanism
Ecasound treats dynamic signal adjustments through its chain controller subsystem. Rather than operating as a full-featured digital audio workstation with built-in graphical MIDI routing, Ecasound relies on mapping MIDI triggers directly to audio processing parameters using command-line arguments or interactive control commands.
Gating an audio track via MIDI requires binding an amplitude operator
to a MIDI controller input. This is typically achieved using the
-ea (amplify) effect coupled with the -km
(MIDI continuous controller) or note-tracking controller options.
Capturing MIDI Events
To accept MIDI data, Ecasound must be bound to a MIDI driver,
commonly the ALSA sequencer (alsaseq) or raw MIDI interface
(rawmidi):
-Md:alsaseq,defaultOnce initialized, Ecasound registers an ALSA client port, allowing external hardware controllers, software sequencers, or virtual keyboards to route events directly into the processing engine.
Mapping Note-On and Note-Off to Gate Audio
A standard gate requires two states: closed (silence) and open (pass-through). In Ecasound, this behavior is established using the following principles:
- Volume Modulation Operator: The chain must contain
an amplify effect, such as
-ea:0, which initializes the channel in a muted or closed state. - Controller Attachment (
-km): The-kmoption maps incoming MIDI messages to the target effect parameter. The syntax establishes the target parameter, minimum value, maximum value, MIDI channel, and controller type. - Note-On Behavior: When a MIDI note-on event arrives, Ecasound translates the event into a parameter change. If velocity sensitivity is enabled, the velocity value (1–127) scales the parameter between the minimum (0%) and maximum (e.g., 100% or higher) amplitude. If configured as a static gate, any note-on event sets the gain directly to the designated upper threshold.
- Note-Off Behavior: Standard MIDI protocol sends a note-off event (or a note-on event with a velocity of 0) when a key is released. Ecasound interprets this change by resetting the mapped amplitude parameter back to the baseline minimum value (0%), instantaneously closing the gate and silencing the track.
Practical Implementation
In an Ecasound processing chain, the setup typically looks like this:
ecasound -B:rt -b:128 -Md:alsaseq,default \
-a:1 -i:audio_track.wav -ea:0 -km:1,0,100,1,1 -o:alsaIn this routing setup:
-ea:0initializes the audio track at 0% gain (gate closed).-km:1,0,100,1,1attaches a MIDI control mapping to parameter 1 (amplitude), scaling from 0 (closed) to 100 (open) based on incoming MIDI channel 1 messages.
Latency and Buffer Sizing
Because gating is an amplitude-based envelope operation, gate
responsiveness depends directly on Ecasound’s internal buffer
configuration. By reducing the buffer size (using the -b
flag) and running in real-time mode (-B:rt), you minimize
the delay between the physical MIDI event and the audio gate opening or
closing, ensuring tight temporal synchronization between MIDI triggers
and audio playback.