next up previous contents index
Next: major triad Up: Examples Previous: amplitude control in decibels   Contents   Index


smoothed amplitude control with an envelope generator

As figure 1.3 shows, one way to make smooth amplitude changes in a signal without clicks is to multiply by an envelope generator; one is invoked in figure 1.4. This may be implemented in Pd using the line~ class:


\fbox{ $ \mathrm{line}\sim $}: 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 rather, its units should conform to whatever input it may be connected to.

Patch 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.8(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; thus, a message with a single number such as "0.1" is always equivalent to the pair, "0.1 0". Most Pd objects will keep the previous value for the right inlet, instead of filling in zero.

Patch A04.line2.pd  shows the line~ object's output graphically, so that you can see the principles of Figure 1.4 in action.


next up previous contents index
Next: major triad Up: Examples Previous: amplitude control in decibels   Contents   Index
Miller Puckette 2005-04-01