Question about envelopes

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:

(mult s (pwlv 0 1 1))

Audacity says the “new” sound contains 140300 samples.

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 ) to work at sample-level.

Thank you very much Robert!
I just tested:

(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.

(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:

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

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:

(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?

Is this the result you are after?

(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)

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… :confused:

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.

Thank you very much, Steve! :slight_smile: