Question about envelopes

Using Nyquist scripts in Audacity.
Post and download new plug-ins.
Forum rules
If you require help using Audacity, please post on the forum board relevant to your operating system:
Windows
Mac OS X
GNU/Linux and Unix-like
Post Reply
vpd
Posts: 103
Joined: Tue Feb 26, 2013 4:28 pm
Operating System: Linux Debian

Question about envelopes

Post by vpd » Tue Apr 22, 2014 5:50 pm

Is it possible to create an envelope that doesn't start and/or end with a 0?

(pwl t1 l1 t2 l2 ... tn) and (env t1 t2 t4 l1 l2 l3 dur) - start and end with 0, so I found (pwlv l1 t2 l2 t3 l3 ... tn ln)
(pwlv l1 t2 l2 t3 l3 ... tn ln) - Creates a piece-wise linear envelope with breakpoints at (0, l1), (t2, l2), etc., ending with (tn, ln)
I thought this one should work, but it didn't. It also produces little fade-in in the beginning and little fade-out in the end.

And one more thing. Using pwl, env and pwlv in Nyquist prompt makes the sound smaller with a few samples.
For example: my source sound contains 140304 samples, after I apply:

Code: Select all

(mult s (pwlv 0 1 1))
Audacity says the "new" sound contains 140300 samples.

Robert J. H.
Posts: 3633
Joined: Thu May 31, 2012 8:33 am
Operating System: Windows 10

Re: Question about envelopes

Post by Robert J. H. » Tue Apr 22, 2014 6:32 pm

Pwl works at a sample-rate "control-srate" thich is normally a 20th of the actual sample rate.
This produces a fade-in over 20 samples and does also shorten the sound in some cases (where the remaining samples falls under 10 samples or so)
You can use (control-srate-abs *sound-srate* <Pwl expression>) to work at sample-level.

vpd
Posts: 103
Joined: Tue Feb 26, 2013 4:28 pm
Operating System: Linux Debian

Re: Question about envelopes

Post by vpd » Tue Apr 22, 2014 6:44 pm

Thank you very much Robert!
I just tested:

Code: Select all

(mult s (control-srate-abs *sound-srate* (pwlv 0 1 1)))
and it works as advertised (with no fade-out in the end).
Thank you for your help!

Robert J. H.
Posts: 3633
Joined: Thu May 31, 2012 8:33 am
Operating System: Windows 10

Re: Question about envelopes

Post by Robert J. H. » Wed Apr 23, 2014 3:56 am

vpd wrote:Thank you very much Robert!
I just tested:

Code: Select all

(mult s (control-srate-abs *sound-srate* (pwlv 0 1 1)))
and it works as advertised (with no fade-out in the end).
Thank you for your help!
You are welcome.
I usually use the low-level function 'snd-pwl', especially for cases where accuracy and independence from the selected audio is demanded.
Providing the start time and sample rate is required.

Code: Select all

(snd-pwl 0 44100 '(0 0.0 88200 1.0 88200))
The times are in samples and integers, whereas the sample values have to be flonums.
Calculations have to be enclosed in a list:

Code: Select all

(snd-pwl 0 *sound-srate* (list 0 (rrandom) (truncate len) (float (/ 3 2)) (truncate len)))

vpd
Posts: 103
Joined: Tue Feb 26, 2013 4:28 pm
Operating System: Linux Debian

Re: Question about envelopes

Post by vpd » Sun Apr 27, 2014 10:07 am

I decided not to start a new thread, but to continue here, because it's related, I think.

I want to make a plugin (so I can call it with a keyboard shortcut) to "interpolate" the sound.
I read that I can't access the sound beyond selection with nyquist, so I decided to use the first half of selection as source and to crossfade out/in its sound to the second half (to repair some "problem").

So this is the code I came up with:

Code: Select all

(defun inplt (s)
(let* (
(fitable (control-srate-abs *sound-srate* (pwlv 0 1 1)))
(fotable (control-srate-abs *sound-srate* (pwlv 1 1 0)))
(s1 (extract 0 0.5 s))
(s2 (extract 0.5 1 s))
(s3 (sum (mult s1 fotable) (mult s2 fitable))))
(extract 0 1 (seq s1 s3))))

(multichan-expand #'inplt s)
Any idea why the samples in the end of selection change?

steve
Site Admin
Posts: 80677
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: Question about envelopes

Post by steve » Sun Apr 27, 2014 1:11 pm

Is this the result you are after?

Code: Select all

(defun inplt (sig)
  (let* ((fade-in (control-srate-abs *sound-srate* (pwlv 0 0.5 1)))
         (fade-out (control-srate-abs *sound-srate* (pwlv 1 0.5 0)))
         (s1 (extract 0 0.5 sig))
         (s2 (extract 0.5 1 sig))
         (s3 (sum (mult s1 fade-out) (mult s2 fade-in))))
    (seq s1 s3)))

(multichan-expand #'inplt s)
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

vpd
Posts: 103
Joined: Tue Feb 26, 2013 4:28 pm
Operating System: Linux Debian

Re: Question about envelopes

Post by vpd » Sun Apr 27, 2014 4:32 pm

steve wrote:Is this the result you are after?
Absolutely quite YES!!! Thank you, Steve!!!

So the result wasn't what I wanted, because of changing the start/stop time with (extract)? I'm still confused about that... :?

steve
Site Admin
Posts: 80677
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: Question about envelopes

Post by steve » Sun Apr 27, 2014 5:13 pm

vpd wrote:So the result wasn't what I wanted, because of changing the start/stop time with (extract)? I'm still confused about that... :?
The result wasn't what you wanted because your "fade-in" and "fade-out" control signals faded over a duration of "1" (the full duration of the selection) which is double the length of S1 and S2.
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

vpd
Posts: 103
Joined: Tue Feb 26, 2013 4:28 pm
Operating System: Linux Debian

Re: Question about envelopes

Post by vpd » Mon Apr 28, 2014 11:25 am

Thank you very much, Steve! :)

Post Reply