MIDI mapping to amplitude

Mapping one range of values to another needed range of values is a crucial technique in computer music. In this example, we want to map MIDI data values that range from 0 to 127 into a useful range for controlling the amplitude—and thus the loudness—of a sound in MSP.

Using a sustain point in a function object

When you play a note with MIDI, you usually want the note to sustain as long as the key is held down, then you want it to turn off (either immediately or gradually) when the key is released (when the note-off message is received). Because MIDI is designed to function in real time, in live performance, there is no duration information contained in a note-on message. The duration can only be known once the key has been released.

Amplitude and decibels

A linear fade-in or fade-out of audio is okay for quick changes that take place in a fraction of a second, but for slower fades one should generally take into account that our subjective sense of loudness more closely conforms to an exponential change in amplitude. This patch allows you to use the slider (or the mod wheel from a MIDI controller) to control the amplitude of white noise in one of three different ways: with straight linear mapping, exponentially (with an exponent of 4), or using a range of 60 decibels.

Test interaural intensity difference

One of the ways we determine where a sound is located is by comparing the sound's intensity in our two ears. A sound that is located to one side of us goes more directly into the ear that's on that side, whereas the sound has to diffract around our head to get to the other ear, so the intensity is usually greater on the side where the sound is located. That distinction is known as interaural intensity difference (IID).

Amplitude control in decibels

This patch is an abstraction for supplying an amplitude factor to control the level of an audio signal. The output of this abstraction is intended to go to a *~ object to scale the volume of a sound. The amplitude factor is expressed in decibels, which is generally a more intuitive way to refer to the volume of a sound. The abstraction fades to the new amplitude in a specified amount of time. Perceptually, a linear fade in decibels (which yields an exponential fade in amplitude) sounds smoother than a linear fade in amplitude.