
166 Make: Radio
lasts as long as a key is held down (on a synth with a keyboard) or as long as
the note is specified to be played. When the key is released or the note ends,
the release phase starts, and the amplitude drops to 0 with a rate specified
by the release value.
The variable remaining, defined on line 36, keeps track of how many
samples are left until the sustain phase ends. The variable s on line 33
holds one audio sample in the form of a 16-bit integer (which is what the
audio system expects), and the variable e on line 34 is the envelope value.
The for loop beginning on line 37 produces the audio samples. Lines 39–61
are the envelope ...