Page 1 of 1
Question about envelopes
Posted: Tue Apr 22, 2014 5:50 pm
by vpd
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:
Audacity says the "new" sound contains 140300 samples.
Re: Question about envelopes
Posted: Tue Apr 22, 2014 6:32 pm
by Robert J. H.
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.
Re: Question about envelopes
Posted: Tue Apr 22, 2014 6:44 pm
by vpd
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!
Re: Question about envelopes
Posted: Wed Apr 23, 2014 3:56 am
by Robert J. H.
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)))
Re: Question about envelopes
Posted: Sun Apr 27, 2014 10:07 am
by vpd
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?
Re: Question about envelopes
Posted: Sun Apr 27, 2014 1:11 pm
by steve
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)
Re: Question about envelopes
Posted: Sun Apr 27, 2014 4:32 pm
by vpd
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...

Re: Question about envelopes
Posted: Sun Apr 27, 2014 5:13 pm
by steve
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.
Re: Question about envelopes
Posted: Mon Apr 28, 2014 11:25 am
by vpd
Thank you very much, Steve!
