electro-music.com   Dedicated to experimental electro-acoustic
and electronic music
 
    Front Page  |  Articles  |  Radio
 |  Media  |  Forum  |  Wiki  |  Links  |  Store
Forum with support of Syndicator RSS
 FAQFAQ   CalendarCalendar   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   LinksLinks
 RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in  Chat RoomChat Room 
 Forum index » DIY Hardware and Software » Arduino
computationally efficient way of calculating envelope
Post new topic   Reply to topic
Page 1 of 1 [2 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
Author Message
remedios_dream



Joined: Apr 26, 2021
Posts: 3
Location: eternity

PostPosted: Wed Jul 21, 2021 5:36 am    Post subject: computationally efficient way of calculating envelope Reply with quote  Mark this post and the followings unread

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
View user's profile Send private message
Steveg



Joined: Apr 23, 2015
Posts: 164
Location: Perth, Australia

PostPosted: Wed Jul 21, 2021 11:58 pm    Post subject: Reply with quote  Mark this post and the followings unread

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic
Page 1 of 1 [2 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
 Forum index » DIY Hardware and Software » Arduino
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Forum with support of Syndicator RSS
Powered by phpBB © 2001, 2005 phpBB Group
Copyright © 2003 through 2009 by electro-music.com - Conditions Of Use