Envelope logic

DSP, Plugin and Host development discussion.
Post Reply New Topic
RELATED
PRODUCTS

Post

I'm working on a simple 5 stage envelope, similar to the one's found it Korg machines:
4x Time Parameters -> Attack, decay, slope and release times.
3x Level Parameters -> Attack, breakpoint(slope), and sustain level.

And there is two conditions that are bothering me.

1) (assuming mono mode here) if breakpoint and/or sustain is higher than attack level, and say you're in sustain then you leave the key and retrigger, the current level might be bigger than the final attack level - so do you clip to the attack level and immediately start the decay? Or something else?

2)if attack and breakpoint level is the same level or close enough to give precision problems( like an attack, hold, decay, release envelope), what do you do, how should I detect the 'problem' in the first place? I'm using counters and switching when "the current level reaches the target level", any hold like segment would become invalid because the levels are the same so the segment would be skipped...any ideas?

Regards
Andrew

Post

#2 Sounds like a logic problem. If you are comparing floats for equality, don't, unless you know one value will rise above a threshold, then you clip it to the exact value you need for the comparison.

Post

After some head-scratching problem No2 is easily circumvented once I realized that no "level-switching" will ever work(even in integer) if any two adjacent levels are the same(creating a timed hold segment), so each segment now has it's own clock that is not related to the output.

No1 isn't as much of a problem as it is a trade-off and trying to figure out what "a normal user would expect" issue. Say if you choose these Levels : Attack 0, Breakpoint 1, Sustain 0.5 -> you effectively have a typical Hold - Attack - Decay - Sustain - Release Envelope, now say the envelope is in release with a value of 0.8 when re-triggered do you:

1) Go to hold stage (might click), maybe smooth out over x samples/ms?
2) Figure out which level(attack,break or sustain) is of higher value than the current value and go to the preceding stage?

Now mathematically speaking No.2 is the obvious choice because it is guaranteed to be smooth, but you might end up re-triggering to any segment dependent on current release value...which might be weird(?). I suspect No1 might be 'right' way but with my audio-rate envelope the click can be pretty severe, I think an end-user would usually assume an envelope would return to the 1st stage when re-triggered. So with fading/smoothing - which shape would be best suited for quickly fading down - linear, exponential, maybe s-curve? Also, should I fade to zero or something like attack-Level/2, fading to zero would click the most, level/2 would click less and possibly sound better...

I cannot think that old digital hardware did anything fancy, they probably just updated the control signal at something like Samplerate/16 and linear-interpolated the result, which would ironically smooth out the clicks a bit, but I'd prefer not to do this.

Andrew

Post

I say do whatever makes the timing of the transient most accurate, but that may be a bit short-sighted.

Post Reply

Return to “DSP and Plugin Development”