# The best method of create custom envelopes

DSP, Plug-in and Host development discussion.
KVRAF
3964 posts since 8 Mar, 2004 from Berlin, Germany
S0lo wrote:
Fri Jul 09, 2021 1:51 pm
But then isn't that an exp/log optimization problem?
only if you actually have to compute the exp (directly). the best optimization of exp is of course to avoid calling exp() completely and replace it by something cheaper like a multiplication

KVRAF
6462 posts since 12 Feb, 2006 from Helsinki, Finland
It might be worth observing here that Gaussians can be approximated by uniform B-spline basis functions. Since they converge reasonably fast (at least as far as the main "bump" goes) and can be formulated in terms of repeated convolution with a boxcar, they are one of the faster ways to approximate a Gaussian-blur (well, other than multi-resolution approaches)... but they can also be used for envelope purposes, for example to get brickwall limiters (ie. use a max-window convering support, then smooth it out by repeated boxcar and you get a smooth envelope that is guaranteed to never let anything over the limit).
Preferred pronouns would be "it/it" because according to this country, I'm a piece of human trash.

KVRAF
7096 posts since 17 Feb, 2005
Music Engineer wrote:
Wed Jul 14, 2021 4:12 am
seems like the approximation gets better for narrower gaussians, so it would seem to be advisable, to use a large s and pre-scale the input accordingly. but i think, the range of shapes produced by the formula is quite interesting in it's own right.
The formula is supposed to be "normalized" on the x axis to define end points to an envelope for instance. So when the s variable is set larger, the function is more accurate near Y zero. This should help realize a longer decay that fits the function before it tapers off to 0.

I haven't been experimenting as much recently, it would help to refresh my memory what the specific formula is to analytically create a "second order" decay curve. Gaussian is not what I had in mind, but now I see that's exactly what I did KVRAF
3964 posts since 8 Mar, 2004 from Berlin, Germany
Music Engineer wrote:
Wed Jul 14, 2021 4:12 am
i think, it may be worthwhile to explore this stuff further. maybe we can create sinusoids with gaussian envelopes aka "gaborets" by using a complex version of the recursion and/or compute things like y(x) = exp(i*p(x)) where p(x) is a polynomial and i the imaginary unit...i guess that may be useful to recursively create sinusoids with a polynomial frequency envelope ...as are needed in additive synthesis and sinusoidal modeling (typically cubic) ....more stuff to explore....
yes! that does indeed work! i have now figured out a recursion that uses just 3 complex multiplications per sample and can synthesize signals like this one:
SweepyGaboret.png
a sine/cosine sweep with a gaussian(ish) envelope. the instantaneous phase and log of instantaneous amplitude can both be defined as cubic polynomials, so simpler exponential envelopes are possible too (and constant ones of course also). here is the math*:

https://github.com/RobinSchmidt/RS-MET/ ... ursion.txt

and here is the code (class rsSineSweepIterator):

https://github.com/RobinSchmidt/RS-MET/ ... terators.h
https://github.com/RobinSchmidt/RS-MET/ ... rators.cpp

i think, this may be useful for an additive synthesis engine. i think, i'll do one soon...

(*) yesyesyes - i know - i have just rediscovered incremental polynomial evaluation by forward differences. it's basically this idea here:
with an exponential function thrown on top of it which turns the additions into multiplications. vadim mentioned it on page one, too. and the numerical stability of the method is a bit ...hmm...well...care has to be taken. we'll see...
You do not have the required permissions to view the files attached to this post.
Last edited by Music Engineer on Sun Jul 18, 2021 1:11 pm, edited 3 times in total.

KVRAF
3964 posts since 8 Mar, 2004 from Berlin, Germany
camsr wrote:
Thu Jul 15, 2021 12:04 pm
I haven't been experimenting as much recently, it would help to refresh my memory what the specific formula is to analytically create a "second order" decay curve. Gaussian is not what I had in mind, but now I see that's exactly what I did now i'm getting curious. what else could "2nd order decay" mean if not gaussian? i mean (exp(a*t))^2 is just exp(2*a*t) so that would not be a new shape but merely another exp-decay just with a shorter decay time
Last edited by Music Engineer on Sun Jul 18, 2021 12:33 pm, edited 1 time in total.

KVRAF
34044 posts since 11 Aug, 2008 from another dimension

How to make paper Envelope -No glue or tape, very easy DIY
Hi-de-Hi!

KVRAF
7096 posts since 17 Feb, 2005
Music Engineer wrote:
Sun Jul 18, 2021 11:26 am
now i'm getting curious. what else could "2nd order decay" mean if not gaussian?
Just the step response of a critically damped second order lowpass, analytically. That is not the gaussian curve, is it??

KVRAF
6462 posts since 12 Feb, 2006 from Helsinki, Finland
Music Engineer wrote:
Sun Jul 18, 2021 11:26 am
camsr wrote:
Thu Jul 15, 2021 12:04 pm
I haven't been experimenting as much recently, it would help to refresh my memory what the specific formula is to analytically create a "second order" decay curve. Gaussian is not what I had in mind, but now I see that's exactly what I did now i'm getting curious. what else could "2nd order decay" mean if not gaussian? i mean (exp(a*t))^2 is just exp(2*a*t) so that would not be a new shape but merely another exp-decay just with a shorter decay time
2nd order term would be something like a*t*exp(a*t).

edit: ...and to answer the question as to why would this be "2nd order" I suggest you take the Laplace transform and it should become rather obvious.
Preferred pronouns would be "it/it" because according to this country, I'm a piece of human trash.

KVRAF
3964 posts since 8 Mar, 2004 from Berlin, Germany
ah - ok - i see. we are talking about a 2nd order filter here. i guess, i was thinking too much about polynomials recently. ...and no, it's not a gaussian shape. see here:

https://lpsa.swarthmore.edu/Transient/T ... tml#Case_2

y(t) = 1 - exp(-w0*t) - w0*t*exp(-w0*t)

btw. - i tend to think, tacking a half-wing of a gaussian to a flat sustain may actually be quite nice. if i'm not mistaken, the transition should be infinitely smooth (all derivatives of the gaussian are zero at t=0). of course, whether that matters or not from a musical point of view is a different question. but i think, it's somehow mathematically satisfying

edit: wait - no - that was wrong. not all derivatives are zero
Last edited by Music Engineer on Mon Jul 19, 2021 3:31 am, edited 1 time in total.

KVRAF
7096 posts since 17 Feb, 2005
mystran wrote:
Sun Jul 18, 2021 3:15 pm
Music Engineer wrote:
Sun Jul 18, 2021 11:26 am
camsr wrote:
Thu Jul 15, 2021 12:04 pm
I haven't been experimenting as much recently, it would help to refresh my memory what the specific formula is to analytically create a "second order" decay curve. Gaussian is not what I had in mind, but now I see that's exactly what I did now i'm getting curious. what else could "2nd order decay" mean if not gaussian? i mean (exp(a*t))^2 is just exp(2*a*t) so that would not be a new shape but merely another exp-decay just with a shorter decay time

2nd order term would be something like a*t*exp(a*t).

edit: ...and to answer the question as to why would this be "2nd order" I suggest you take the Laplace transform and it should become rather obvious.
Thank you, that is the function I was looking for.

KVRAF
7096 posts since 17 Feb, 2005
Music Engineer wrote:
Sun Jul 18, 2021 3:48 pm
btw. - i tend to think, tacking a half-wing of a gaussian to a flat sustain may actually be quite nice. if i'm not mistaken, the transition should be infinitely smooth (all derivatives of the gaussian are zero at t=0). of course, whether that matters or not from a musical point of view is a different question. but i think, it's somehow mathematically satisfying
It's always useful to have another envelope variety. I think mixing them is where the challenge is. Sometimes for example I have wanted to smooth out a rough breakpoint and the only option is to add another breakpoint and wiggle them around. The worst thing that could happen there is one audible discontinuity becomes two of them. Smooth breakpoints are good sometimes, other times they aren't useful at all, so YMMV.

KVRian
1327 posts since 12 Apr, 2002
Music Engineer wrote:
Sun Jul 18, 2021 3:48 pm
ah - ok - i see. we are talking about a 2nd order filter here. i guess, i was thinking too much about polynomials recently. ...and no, it's not a gaussian shape. see here:

https://lpsa.swarthmore.edu/Transient/T ... tml#Case_2

y(t) = 1 - exp(-w0*t) - w0*t*exp(-w0*t)

btw. - i tend to think, tacking a half-wing of a gaussian to a flat sustain may actually be quite nice. if i'm not mistaken, the transition should be infinitely smooth (all derivatives of the gaussian are zero at t=0). of course, whether that matters or not from a musical point of view is a different question. but i think, it's somehow mathematically satisfying
Actually 2nd order filter's response is more like a sum (or rather a difference, I guess) of two exponents of different speeds. Like a difference of two 1-pole filters. The term t*exp(-t) appears as a limiting case of such difference when the poles (1 pole cutoffs) become identical. If there is a resonance then we have a decaying sinusoidal term instead (with the same t*exp(-t) limit as the resonance becomes small).

The Art of VA Filter Design 4.8 and p.129 in particular.

KVRist

Topic Starter

289 posts since 17 Feb, 2013 from Sayan Mountains, Siberia
Music Engineer wrote:
Wed Jul 14, 2021 5:33 am
only if you actually have to compute the exp (directly). the best optimization of exp is of course to avoid calling exp() completely and replace it by something cheaper like a multiplication
By the way, I'm testing this exponent function to calculate the envelope slope. Maybe someone will come in handy. Code: Select all

``````inline double fastexp(double x) noexcept
{
return (1680 + x * (840 + x * (180 + x * (20 + x)))) / (1680 + x * (-840 + x * (180 + x * (-20 + x))));
}``````