Sometimes we may want to fade-in or fade-out an effect rather than have it start and end suddenly. This article looks at how we can do this automatically within an effect. The way that we would do this manually is by duplicating the track, applying the effect to the duplicate, then crossfading the two tracks
While it is possible to call Audacity’s effects from Nyquist using Scripting Commands, it is not possible to combine Scripting Commands with Nyquist processing. Thus we can only use this technique to fade in/out effects created in the Nyquist code.
By way of example, we shall use one of Nyquist’s built-in reverb effects; JCREV. This little snippet applies a bright reverb to the selected audio, with 2 seconds decay and a 50% mix of wet / dry signals:
1 2 |
(jcrev *track* 2 0.5) |
For the purpose of illustration we shall fade in the effect over 2 seconds, and fade out the effect over the final 5 seconds (we shall assume that the entire selection is greater than 7 seconds duration). To fade the effect, we need to scale (multiply) the effect by a varying amount which we will define as a control signal.
1 2 3 4 5 6 |
; create a control signal that rises from 0 to 1 ; over 2 seconds and returns back to 0 over the ; final 5 seconds (let ((dur (get-duration 1))) (stretch-abs 1 (pwlv 0 2 1 (- dur 5) 1 dur 0))) |
Note that PWLV creates a signal at the Control Rate (1/20th of the Sound Rate) so if applied in the Nyquist Prompt the envelope will appear to be 20 times shorter than expected. This is not a problem as the length will be correct after multiplying by the effect signal (which has the same sample rate as the track).
Applying the above code to a 10 second selection produces a waveform (control signal) like this (below). Note that the length is 0.5 seconds, which is 1/20th of the original selection:
This will do nicely for fading in and out our processed audio, but to achieve a smooth crossfade we also want an envelope to process the original audio from the track. The required envelop may be easily created by subtracting the above envelope from a constant value of 1.
1 2 3 4 |
(let ((dur (get-duration 1))) (setf envelope (stretch-abs 1 (pwlv 0 2 1 (- dur 5) 1 dur 0))) (setf inverse (diff 1 envelope))) |
Now that we have the two envelopes, we can apply the first to our processed audio, the second to the original selection *track*, then mix (“add”) the two together:
1 2 3 4 5 6 |
(let ((dur (get-duration 1))) (setf envelope (stretch-abs 1 (pwlv 0 2 1 (- dur 5) 1 dur 0))) (setf inverse (diff 1 envelope)) (sum (mult envelope (jcrev *track* 2 0.5)) (mult inverse *track*))) |
Or to tidy it up a bit, envelope and inverse may be made local to the LET block.
1 2 3 4 5 6 |
(let* ((dur (get-duration 1))) (envelope (stretch-abs 1 (pwlv 0 2 1 (- dur 5) 1 dur 0))) (inverse (diff 1 envelope)) (sum (mult envelope (jcrev *track* 2 0.5)) (mult inverse *track*))) |