A common problem for people that are new to Nyquist is how to modify audio samples, for example, to set certain sample values to zero (silence). The temptation may be to read the audio sample by sample and modify them as necessary. In the vast majority of cases this is NOT the best approach as sample-by-sample processing in LISP is invariably very slow. In most cases it is much faster and much more efficient to use Nyquist’s built in DSP functions.
In this example we look at silencing part of a track.
A simple way to silence audio is to “amplify” (multiply) it by zero (-inf dB):
[cc lang=”lisp”](mult s 0)
Similarly, multiplying by 1 will result in no change to the audio.
[cc lang=”lisp”](mult s 1)[/cc]
So to set part of an audio track to silence and leave the rest unchanged, all we need to do is to create a control signal that has a value of 1 at the parts that we do not want to change, and value 0 at the parts that we want to silence.
Control signals that vary piece-wise can be created with the “pwl” (piece-wise linear) or “pwe” (piece-wise exponential) family of envelope functions. (see Piece-wise Approximations)
The piece-wise approximation functions create control signals at the *control-rate*, which by default is 1/20th of the default sound sample rate *sound-srate*. This may be useful for faster processing and lower memory requirements, but it reduces the accuracy of the control signal, so if we need sample accuracy the control signal needs to be generated at the sound sample rate. Fortunately we can do this easily by wrapping the control generating code inside a function that sets the control rate.
[cc lang=”lisp”](control-srate-abs *sound-srate*
… control signal code … )[/cc]
So let’s have a look at one of these piece-wise approximation functions:
(pwlv 1 0.2 1 1 0))[/cc]
What this does is to create a control signal that starts at value 1, and remains at 1 until time “0.2”. The signal then drops until at time “1” the level is zero. The times refer to “local time” which for an Audacity plug-in is relative to the length of the selection.
… to be continued …