Author |
Message |
remedios_dream
Joined: Apr 26, 2021 Posts: 3 Location: eternity
|
Posted: Wed Jul 21, 2021 5:36 am Post subject:
computationally efficient way of calculating envelope |
 |
|
Hi all,
I'm doing a research about alternative ways of computing some basic shapes of envelopes (linear decay for now).
The mcu of my choice is stm32f401 (84MHz, fpu unit) and for now I handle 7 voices karplus-strong algorithm. I want to add at least decay to each of the voice but here comes the limitations.
For a linear decay I use this simple formula:
Code: | decay -= 1.0f / (float)SAMPLING_RATE; |
After adding decay part, synthesizer crushes when more than few voices are active. I assume that there are too many calculations (floating division, 42k times a second).
What I did already but leaves much to be desired:
- instead 1/42000 each loop I hardcoded the result -> 0.0000238 and then subtract it
- I created 4.2k records lookup table in flash for a decay values from 1.0 to 0.0 next with help of modulo I read the values from the table and subtract
Second approach works best for now but it still crushes sometimes e.g all voices are active.
Do you have any alternative solutions or things that I could investigate first? |
|
Back to top
|
|
 |
Steveg

Joined: Apr 23, 2015 Posts: 184 Location: Perth, Australia
|
Posted: Wed Jul 21, 2021 11:58 pm Post subject:
|
 |
|
Try using fixed point rather than floating point then you can use shifts to get the division. You'll want to use a buffer size that is a power of 2 as well.
if you are not familiar with "fixed point representation" you can google it, but it is a way of using integers to represent decimal values.
So you probably want to use an 32767 value array of 32 bit integers. To get the decay value right shift the integer by 15 ... in C
decay = value >> 15;
Possibly much faster than floating point (but occasionally not in processors with internal FP support) remembering each value has to be divided by 2^31. |
|
Back to top
|
|
 |
|