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):
(mult *track* 0)
Similarly, multiplying by 1 will result in no change to the audio.
(mult *track* 1)
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.
1 2 3 |
(control-srate-abs *sound-srate* ... control signal code ... ) |
So let’s have a look at one of these piece-wise approximation functions:
1 2 3 |
(control-srate-abs *sound-srate* (pwlv 1 0.2 1 1 0)) |
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 …
Hello.
In some articles including this, Nyquist codes don’t seem to be displayed correctly.
They’re just plain text lines surrounded by
[cc lang=”lisp”]
and[/cc]
instead of code blocks on my browser Chrome.Thanks for the feedback Phroneris. I’m aware of this issue which is due to an incompatibility between an old, discontinued plug-in for displaying code with syntax highlighting, and the new up to date replacement. I’ll gradually be working through the old posts to update them so that they display correctly. Apologies for the inconvenience.