pnielsen wrote:Is something like this beyond the scope of an Audacity plug-in?
Designing a nice interface would be tricky, but the basics of entering a list of numbers and creating an envelope from them is pretty easy.
Nyquist provides a set of functions for creating "piecewise envelopes", which take lists of points and creates an envelope from those points. The lists are in the form of time/amplitude pairs.
As an example, there is the function PWLV which creates a "piece-wise linear envelope". "Linear" in the name indicates that the points are joined by straight lines (there is also an exponential version PWEV).
The time of the first point is assumed to be 0, but after that each point is defined as a pair of values (time, amplitude).
The following is a very simple example that rises from 0.1 at time 0, to an amplitude of 1 at time=0.5 and falls to silence at time=1
When used in an effect (or in the Nyquist Prompt effect), the times are, by default, relative to the length of the selection, so a time position of 1.0 refers to the end of the selection.
To apply the envelope, all that is required is to "multiply" the sound by the envelope.
Audacity passes the sound from the selection to Nyquist as a variable called "S".
So to apply the above envelope to a selected audio track, the following code can be used in the Nyquist Prompt effect:
There is also command that does the same thing, but takes a list of numbers as its input:
Code: Select all
(setf point-list (list 0.1 0.5 1 1 0))
(mult s
(pwlv-list point-list))
The list of points (which have been given the name "point-list" in this example) could have hundreds, or even thousands of points defined.
If we just wanted to add a list of amplitudes that would then be evenly spaced along the sound that we are processing, something like this could be used:
Code: Select all
(setf amp-list (list 0.1 1 0))
(setq num (1- (length amp-list)))
(setf point-list (list (first amp-list)))
(dotimes (count num)
(push (/ (+ 1.0 count) num) point-list)
(push (nth (1+ count) amp-list) point-list))
(setf point-list (reverse point-list))
(print point-list)
(mult s
(pwlv-list point-list))
where "amp-list" is out list of amplitudes (in order from left to right along the time line).
The line (print point-list) just prints out the list to the debug window so that we can check which points were used (as time/amplitude pairs). To see the debug output, click the debug button rather than the OK button.
If you were using a very long list (hundreds of points) you would probably want to disable or remove the "print" line. A code line can be disabled by putting a semicolon at the beginning of the line. This is the way that "comments" (to be ignored by the program) are added to a Nyquist script.