I’m making a basic sampler, each sample has their own envelope that can be adjusted in real time, as standard on most sample players. I know I can apply gain ramps for things like attack and release, but what happens when the user adjusts their settings? The code looks destructive, surely there is no record being kept of the original data value which has now been changed. Do I need to keep a record of my gain ramp, then apply the inverse before I apply a different gain ramp?
Also, are all gain ramps linear? What if I wanted to support a knee? Should I just do it manually? 1 sample at a time based on my own function?