How to Generate Arbitrary Waveforms as Envelopes
Forum rules
This forum is for Audacity on Windows.
Please state which version of Windows you are using,
and the exact three-section version number of Audacity from "Help menu > About Audacity".
Audacity 1.2.x and 1.3.x are obsolete and no longer supported. If you still have those versions, please upgrade at https://www.audacityteam.org/download/.
The old forums for those versions are now closed, but you can still read the archives of the 1.2.x and 1.3.x forums.
Please state which version of Windows you are using,
and the exact three-section version number of Audacity from "Help menu > About Audacity".
Audacity 1.2.x and 1.3.x are obsolete and no longer supported. If you still have those versions, please upgrade at https://www.audacityteam.org/download/.
The old forums for those versions are now closed, but you can still read the archives of the 1.2.x and 1.3.x forums.
How to Generate Arbitrary Waveforms as Envelopes
I am looking for the capability to apply an arbitrary waveform envelope to an audio signal. Something more complex than what can be implemented with ADSR. Is there any way this can be accomplished in Audacity?
CoolEdit/Audition has a drag-and-drop graphical editor for this purpose, but I wouldn't mind typing in a sequence of X values. Maybe some rounding bewtween points would be useful, as well as fields to set the number of X data points, and the repetition rate of the envelope.
Any suggestions along these lines would be greatly appreciated.
Peter Nielsen
CoolEdit/Audition has a drag-and-drop graphical editor for this purpose, but I wouldn't mind typing in a sequence of X values. Maybe some rounding bewtween points would be useful, as well as fields to set the number of X data points, and the repetition rate of the envelope.
Any suggestions along these lines would be greatly appreciated.
Peter Nielsen
Re: How to Generate Arbitrary Waveforms as Envelopes
If it is a relatively simple envelope, you can use the Envelope Tool: http://manual.audacityteam.org/o/man/envelope_tool.html
If you want an envelope with dozens, or even thousands of points and have a formula to generate the points, it would be possible to create an envelope using a Nyquist Script (Nyquist is a simple programming language that is built into Audacity).
A Nyquist script can either be run in the Nyquist Prompt effect (http://manual.audacityteam.org/o/man/ny ... rompt.html)
or can be made into a plug-in (http://manual.audacityteam.org/o/man/ef ... st_Effects)
An example of a simple Nyquist script that will apply a 1.0 Hz sine wave envelope to the selected track (copy and paste into the Nyquist Prompt effect to apply this to a selected track) :
If you want an envelope with dozens, or even thousands of points and have a formula to generate the points, it would be possible to create an envelope using a Nyquist Script (Nyquist is a simple programming language that is built into Audacity).
A Nyquist script can either be run in the Nyquist Prompt effect (http://manual.audacityteam.org/o/man/ny ... rompt.html)
or can be made into a plug-in (http://manual.audacityteam.org/o/man/ef ... st_Effects)
An example of a simple Nyquist script that will apply a 1.0 Hz sine wave envelope to the selected track (copy and paste into the Nyquist Prompt effect to apply this to a selected track) :
Code: Select all
(mult s 0.5 (sum 1 (hzosc 1)))9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)
-
kozikowski
- Forum Staff
- Posts: 68902
- Joined: Thu Aug 02, 2007 5:57 pm
- Operating System: macOS 10.13 High Sierra
Re: How to Generate Arbitrary Waveforms as Envelopes
Audacity only has the draw tool which only works on individual samples. I think it was intended as a repair tool rather than a production generation tool.
Koz
Koz
Re: How to Generate Arbitrary Waveforms as Envelopes
A more complex example. Try applying this to a generated tone:
Code: Select all
(setf adsr (pwlv 0 0.05 1 0.3 0.4 0.5 0.4 1 0))
(setq wiggle 0.3)
(setq wigglerate 3)
(setf envelope
(sim (mult adsr (- 1 (* 2 wiggle)))
(mult adsr wiggle (sum 1 (hzosc wigglerate)))))
(mult envelope s)
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)
Re: How to Generate Arbitrary Waveforms as Envelopes
The envelope tool is very useful, as is the Nyquist "env" function.
But I was thinking of something more like a look-up table, where amplitude points (Y values) are entered at preset X intervals. In other words, a manual process that does not rely upon algebraic functions. The objective is to maximize flexibility. Even a 10x40 grid would provide a workable resolution for many applications.
Useful refinements might include an optional smoothing function and user-defined repetition rate for the generated envelope.
Is something like this beyond the scope of an Audacity plug-in?
But I was thinking of something more like a look-up table, where amplitude points (Y values) are entered at preset X intervals. In other words, a manual process that does not rely upon algebraic functions. The objective is to maximize flexibility. Even a 10x40 grid would provide a workable resolution for many applications.
Useful refinements might include an optional smoothing function and user-defined repetition rate for the generated envelope.
Is something like this beyond the scope of an Audacity plug-in?
Re: How to Generate Arbitrary Waveforms as Envelopes
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.pnielsen wrote:Is something like this beyond the scope of an Audacity plug-in?
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
Code: Select all
(pwlv 0.1 0.5 1 1 0)
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:
Code: Select all
(mult s
(pwlv 0.1 0.5 1 1 0))
Code: Select all
(setf point-list (list 0.1 0.5 1 1 0))
(mult s
(pwlv-list point-list))
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))
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.
Code: Select all
; this line will be ignored9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)
-
Robert J. H.
- Posts: 3633
- Joined: Thu May 31, 2012 8:33 am
- Operating System: Windows 10
Re: How to Generate Arbitrary Waveforms as Envelopes
... and there's Steve's Text Envelope plug-in, where you can enter the values into a text field (I usually Import the values from Excel).
Smoothing and Looping are currently not supported (possible Features?).
Smoothing and Looping are currently not supported (possible Features?).
Re: How to Generate Arbitrary Waveforms as Envelopes
Link: http://wiki.audacityteam.org/wiki/Nyqui ... t_EnvelopeRobert J. H. wrote:... and there's Steve's Text Envelope plug-in, where you can enter the values into a text field (I usually Import the values from Excel).
I doubt that there is enough user demand to make it a standard feature, but it would probably not be hard to add as a custom feature.Robert J. H. wrote:Smoothing and Looping are currently not supported (possible Features?).
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)
Re: How to Generate Arbitrary Waveforms as Envelopes
Here's an idea that you may like:
4. Open, import or generate a track to apply the envelope to.
5. Select the track and run this code in the Nyquist prompt.
- Create some silence in a mono track,
- Zoom in really close
- Switch to the Draw Tool and draw an envelope shape.
Code: Select all
(let ((envlist '()))
(do ((val (snd-fetch s)(snd-fetch s)))
((not val))
(push val envlist))
(putprop '*SCRATCH* envlist 'envlist))
(print "done")
5. Select the track and run this code in the Nyquist prompt.
Code: Select all
;; The next line tells the code to reset (remove) the
;; envelope after processing.
;; Change to 0 if you don't want to reset.
(setq reset 1)
(setf amp-list (get '*SCRATCH* 'envlist))
(setf point-list (list (first amp-list)))
(let ((num (1- (length amp-list))))
(dotimes (count num)
(push (- 1.0 (/ count (float num))) point-list)
(push (nth (1+ count) amp-list) point-list))
(setf point-list point-list))
; (print point-list)
(when (= reset 1)
(remprop '*SCRATCH* 'envlist))
(mult s
(pwlv-list point-list))
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)