Linear fade-in/out of audio

Image

 

The line~ object is useful for providing a control signal. It interpolates linearly sample-by-sample to a new signal value over a specified period of time, then stays at that new value until it is instructed to change. It expects to receive a transition time in its right inlet (a ramp time), followed by a destination value in its left inlet. Alternatively, you can provide both values as a single two-item list. Its initial default value is 0. In this example, we use line~to provide a control signal (multiplier) to the *~ object in order to turn the amplitude of a sine wave up and down. When line~ receives the message 1 1000 it progresses to 1 over the course of 1 second, and when it gets the message 0 1000 it ramps back down to 0 in one second.

Ducking when changing delay time

Image

 

Whenever you change the delay time, you’re asking MSP to look at a new location in the delay buffer, which can cause a click in the output if the new sample value is very different from the previous one. One way to get around that is to quickly fade the output amplitude down to 0 whenever you make a change, then quickly fade it back up once the change has been made. In this example, whenever a new delay time comes out of the number box, it first sends a 0 to the pack object, which sends a ‘0 5’ message to line~, which fades line~’s signal down to 0 in 5 milliseconds (meaning the output signal of delay~ will get multiplied by 0, silencing it). The delay time meanwhile is held for 6 milliseconds by the pipe object, thus waiting for the fade-down to be completed by line~. Only then does the new delay time get passed on to the delay~ object, and then a 1 gets sent to pack, sending a ‘1 5’ message to line~, fading the sound back up in 5 ms. The net effect is that we do get a very quick (11-ms) fadedown/fadeup in the output of delay~, but at least it’s not a jarring click.