Sunday, July 12, 2009

Applying an amplitude envelope to array data in C++??

I have the raw data for a sound file in an array and I need to apply an amplitude envelope (attack - decay - sustain - release) to it using C++. Preferably I'd like the user to be able to adjust the times for each part of the envelope but this is not essential. I have 44100 samples in the array. I know I need to use a separate for loop to apply each part of the envelope to the necessary samples, and I've pretty much got my head around doing the attack part, but I'm having difficulty working out how to do the rest. I know the sample rate and everything, so the length of the sound can be calculated easily, it's just that when it comes down to actually applying the envelope I get confused!


I'm only making a console application, none of this visual stuff, so I just want the source code really.


Any suggestions for code, or even just ideas as to what processes I need to go through, would be much appreciated!


Many thanks!

Applying an amplitude envelope to array data in C++??
Suppose you had separate arrays for your A, D, S, R data, comprising floating point numbers, multiplication factors, between 0 and 1 inclusive.





Now allocate a floating point array equal in length to your sound sample data. Call this the "envelope array." Since you're a C++ guy, use new and remember to use delete after you're done with it.





Figure out how many samples long your attack, for example, should be. Then copy from your attack array into the floating point array you allocated... using linear extrapolation if you need more attack values, or skipping some if you need fewer.


Do the same for your decay, sustain, release. Then multiply your sample values by your envelope array values.

clematis

No comments:

Post a Comment