Sound synthesizers, both digital and analog, often include a parameter section for shaping the amplitude of a sound wave over time. This parameter section is commonly known as an "ADSR EG" (attack, decay sustain, release; envelope generator).
I included a parameter for shaping the curvature of three different lines within the piecewise function describing my envelope generator.
An abstract example of my parameter would look like this:
Linear function $y$
Piecewise function $ADSR\ EG(x)$
$y=(x-x_1)^{curvature}\frac{y_2-y_1}{x_2-x_1}+y_1$
$y\in ADSR\ EG(x)$
where $curvature$ it's the slope shaping parameter I'm referring to, so when $curvature=1$ is a straight line, when $curvature>1$ is a concave curve, when $0<curvature<1$ it's a convex curve.
I attached a file with the mathematical description of the envelope generating function I tried to prototype in Wolfram Mathematica. I also attached a beta version of the prototype as a CDF file for someone here to inspect. The free application Wolfram CDF Player needs to be installed to open the cdf file I attached and analyze the code.
The curvature parameter it's not working as expected in my Mathematica program; the lines with the curvature parameter included are not bending smoothly in place when I drag the corresponding slider and I can't spot the error in typing by myself. Can someone please analyze the attached files and tell me how to fix the problem in Mathematica? The curvature parameters have labels designated "Attack time slope," "Decay time slope" and "Release time slope." The rest of the sliders behave exactly in the manner I expected. Thank you in advance.
Link to CDF file: https://www.mediafire.com/?aadebzqlsyiebln
Wolfram Language code:
Manipulate[
Plot[
Piecewise[
{{0,
time <= n0*n5},
{(((time - n0*n5)^n8)*((n0 + n1)*n5 - 0)/((n0 + n1)*n5 - n0*n5) + 0)*(n6*Piecewise[{{10^(n11/20), -120 < n11 <= 12}, {0, n11 == -120}}])/((n0 + n1)*n5),
n0*n5 < time <= (n0 + n1)*n5},
{(((time - (n0 + n1)*n5)^n9)*((n0 + n1)*n5*n7 - (n0 + n1)*n5)/((n0 + n1 + n2)*n5 - (n0 + n1)*n5) + (n0 + n1)*n5)*(n6*Piecewise[{{10^(n11/20), -120 < n11 <= 12}, {0, n11 == -120}}])/((n0 + n1)*n5),
(n0 + n1)*n5 < time <= (n0 + n1 + n2)*n5},
{((time - (n0 + n1 + n2)*n5)*((n0 + n1)*n5*n7 - (n0 + n1)*n5*n7)/((n0 + n1 + n2 + n3)*n5 - (n0 + n1 + n2)*n5) + (n0 + n1)*n5*n7)*(n6*Piecewise[{{10^(n11/20), -120 < n11 <= 12}, {0, n11 == -120}}])/((n0 + n1)*n5),
(n0 + n1 + n2)*n5 < time <= (n0 + n1 + n2 + n3)*n5},
{(((time - (n0 + n1 + n2 + n3)*n5)^n10)*(0 - (n0 + n1)*n5*n7)/((n0 + n1 + n2 + n3 + n4)*n5 - (n0 + n1 + n2 + n3)*n5) + (n0 + n1)*n5*n7)*(n6*Piecewise[{{10^(n11/20), -120 < n11 <= 12}, {0, n11 == -120}}])/((n0 + n1)*n5),
(n0 + n1 + n2 + n3)*n5 < time <= (n0 + n1 + n2 + n3 + n4)*n5},
{0,
time > (n0 + n1 + n2 + n3 + n4)*n5}}
],
{time, 0, (n0 + n1 + n2 + n3 + n4)*n5},
AxesLabel -> {"Time", "Amplitude"}
],
{{n0, 500, "Delay time"}, 0, 5000, 1/1000},
{{n1, 500, "Attack time"}, 1/1000, 5000, 1/1000},
{{n2, 500, "Decay time"}, 1/1000, 5000, 1/1000},
{{n3, 500, "Sustain time"}, 1/1000, 5000, 1/1000},
{{n4, 500, "Release time"}, 1/1000, 5000, 1/1000},
{{n5, 1, "Envelope lenght"}, 1/100, 2, 1/100},
{{n6, 1, "Envelope depth"}, -1, 1, 1/100},
{{n7, 1/2, "Sustain amplitude"}, 0, 1, 1/100},
{{n8, 1, "Attack time slope"}, 1/100, 2, 1/100},
{{n9, 1, "Decay time slope"}, 1/100, 2, 1/100},
{{n10, 1, "Release time slope"}, 1/100, 2, 1/100},
{{n11, 0, "Volume"}, -120, 12, 1/10}
]