AD Envelope node skipping its attack

When the Attack Time of an AD Envelope is cached in a Value (Float) node, the output of the envelope instantly hits 1.0, waits for the duration of the attack time, and then starts decaying - instead of interpolating towards 1.0 over the attack time.

It Init Value of the Value node is set to a non-zero value, it works as it should.

Steps to Reproduce

  1. Set up an AD Envelope in an empty metasound and log its results.
  2. Connect a Value (Float) node to the Attack Time.
  3. Set the Target Value to more than zero.
  4. Play the metasound, trigger the Value node, and trigger the AD Envelope node.

Sorry for the delayed response. It looks to me like this is current bug. I’ll work on getting a fix for 5.8 and will post it here so you can incorporate it if you are building from source.

Without code changes the only workarounds I can think of are:

1. Set Init Value to match Target Value (best option)

Set the Value node’s Init Value to the same value as your Target Value. The bug only triggers when Init Value is 0, so a non-zero Init Value (even a tiny one like

0.001) prevents it. Setting it to your actual intended attack time means the envelope behaves correctly whether or not the Value node has been triggered yet.

2. Don’t use a Value node

If the attack time doesn’t need to change at runtime, just set it directly as a literal on the AD Envelope’s Attack Time pin. No Value node, no problem.

3. Delay the envelope trigger

Ensure the Value node is triggered (and its output has propagated) in a block before the AD Envelope trigger fires — e.g., by gating the envelope trigger through a

small Delay node. This is fragile and awkward, so option 1 is much better.

The code fix is to delete the following lines from MetasoundADEnvelopeNode.cpp:

// if there is no attack phase, we jump to 1.f on the first frame
if(EnvState.AttackSampleCount == 0)
{
	EnvState.CurrentEnvelopeValue = 1.f;
}

It was skipping the attack phase before the envelope was even triggered. The zero attack phase time is handled correctly with existing logic.