Map MIDI CC to Audio Gain in Ecasound

This guide explains how to map a hardware or software MIDI Continuous Controller (CC) to control audio gain in real time using Ecasound. By attaching the -km controller preset directly to Ecasound's -ea amplify effect and routing a designated MIDI input, you can dynamically modulate volume levels from any standard MIDI controller knob, slider, or fader.

1. The Audio Gain Operator (-ea)

Ecasound controls volume using the linear amplify operator:

-ea:gain_%
  • gain_%: The initial volume level represented as a percentage (e.g., 100 for unity gain / 0 dB, 0 for silence, 200 for a +6 dB boost).

Because -ea accepts one parameter, the gain percentage corresponds to parameter index 1.

2. The Controller Mapping Operator (-km)

To bind MIDI input to an effect parameter, append the -km operator directly after the effect:

-km:param_id,type,controller,channel,low,high
  • param_id: The target effect parameter index. For -ea, set this to 1.
  • type: The control response curve. Use 1 for linear scaling or 2 for logarithmic/exponential scaling.
  • controller: The MIDI Continuous Controller (CC) number (e.g., 7 for standard MIDI Volume, 1 for the Mod Wheel).
  • channel: The MIDI channel number (1 through 16).
  • low: The parameter value when the MIDI CC is at minimum (0). Typically 0 for mute.
  • high: The parameter value when the MIDI CC is at maximum (127). For example, 100 for unity gain or 150 for extra headroom.

3. Selecting the MIDI Input (-Md)

Ecasound must be instructed where to listen for MIDI messages using the -Md option:

  • ALSA Sequencer (Dynamic port): -Md:alsaseq creates an ALSA MIDI client that can be routed using tools like aconnect or qjackctl.
  • Raw MIDI Device: -Md:rawmidi,/dev/midi1 listens directly on a specific hardware device node.

4. Complete Command Examples

Linear Mapping with ALSA Sequencer

To map MIDI CC 7 (Volume) on MIDI Channel 1 to an audio stream, adjusting gain linearly from 0% to 100%:

ecasound -i:input.wav -o:alsa -Md:alsaseq -ea:100 -km:1,1,7,1,0,100

Logarithmic Response with ALSA Hardware Port

Human hearing perceives volume logarithmically. To use an exponential response curve (type 2) using CC 11 (Expression) on Channel 1 directly from an ALSA sequencer port (e.g., port 20:0):

ecasound -i:input.wav -o:alsa -Md:alsaseq,20:0 -ea:100 -km:1,2,11,1,0,120

Once executed, movement from the assigned MIDI controller instantly adjusts the audio gain in real time.