Next: Major triad Up: Examples Previous: Amplitude control in decibels Contents Index

## Smoothed amplitude control with an envelope generator

As Figure 1.6 shows, one way to make smooth amplitude changes in a signal without clicks is to multiply it by the output of an envelope generator as shown in block diagram form in Figure 1.7. This may be implemented in Pd using the `line~` object:

: envelope generator. The output is a signal which ramps linearly from one value to another over time, as determined by the messages received. The inlets take messages to specify target values (left inlet) and time delays (right inlet). Because of a general rule of Pd messages, a pair of numbers sent to the left inlet suffices to specify a target value and a time together. The time is in milliseconds (taking into account the sample rate), and the target value is unitless, or in other words, its output range should conform to whatever input it may be connected to.

Example A03.line.pd demonstrates the use of a `line~` object to control the amplitude of a sinusoid. The active part is shown in Figure 1.12 (part b). The six message boxes are all connected to the `line~` object, and are activated by clicking on them; the top one, for instance, specifies that the `line~` ramp (starting at wherever its output was before receiving the message) to the value 0.1 over two seconds. After the two seconds elapse, unless other messages have arrived in the meantime, the output remains steady at 0.1. Messages may arrive before the two seconds elapse, in which case the `line~` object abandons its old trajectory and takes up a new one.

Two messages to `line~` might arrive at the same time or so close together in time that no DSP computation takes place between the two; in this case, the earlier message has no effect, since `line~` won't have changed its output yet to follow the first message, and its current output, unchanged, is then used as a starting point for the second segment. An exception to this rule is that, if `line~` gets a time value of zero, the output value is immediately set to the new value and further segments will start from the new value; thus, by sending two pairs, the first with a time value of zero and the second with a nonzero time value, one can independently specify the beginning and end values of a segment in `line~`'s output.

The treatment of `line~`'s right inlet is unusual among Pd objects in that it forgets old values; a message with a single number such as "0.1" is always equivalent to the pair, "0.1 0". Almost any other object will retain the previous value for the right inlet, instead of resetting it to zero.

Example A04.line2.pd shows the `line~` object's output graphically. Using the various message boxes, you can recreate the effects shown in Figure 1.6.

Next: Major triad Up: Examples Previous: Amplitude control in decibels Contents Index