Performance tips

Hey !
Im new to both embedded and dsp development, so im wondering if some of you more experienced people have any tips for increasing performance on the daisy seed ? Here are a few of the things ive figured out so far.
Theres 2 sides to performance, cpu and memory. Sometimes theyre separate but most of the time they are connected.
I’ve worked on my project for a while and recently i got the ‘out of flash memory’ message from the compiler. So i read the great post:

Here i found the trick of adding the -Os flag to the compiler (makefile) and immediately reduced the memory usage of the code by 20-30%. So im wondering if there’s any other magic flags like that?

I was looking into the -ffast-math flag, that is supposed to sacrifice some float precision for cpu performance, but when i set it i immediately got the ‘out of flash memory’ again, so it seems it also has a memory cost. Do any of you have any experience with that flag?

Of course the compiler cant fix every thing for me, and ive worked out a few things in the code. Early on i dealt with the clock rate noise issue (a continues tone at clock rate / block size). So i read the long post on that:

It seems everybody has their own solutions and nobody really knows what is going on. So i first chose the easy solution of setting the block size down to 2 to keep the tone out of hearing range.

However at some point this block size couldn’t handle the amount of processing i was doing.
So i looked at the post again and i tried some of the hardware changes and found the only thing that made a difference was connecting external power. That reduced the noise. while i was troubleshooting i tried to set the block size back up (to 48) and this solved both the noise issue and the processing load issue i was having. it seemed like increasing the blocksize not only lowers the noise/tone frequency but also the amplitude. But only when power is connected. when its powered by usb the noise is back.

I’ve was doing well on cpu since increasing block size, however now ive started the work on making the whole project stereo which means doubling the load from much of the processing and ive encountered a new issue. with stereo processing i was getting cpu loads of 80 - 90 % and at that point the chip starts making weird noises and after a while just stops reacting.
So now ive started to looking for optimizations in the code. Here are some of the things ive done:

  • Reading controls in the main loop instead of the audio callback. the main loop just has System::Delay(1) so it reads controls every 1 ms.
  • I also moved parameter smoothing (fonepole) from audio to main loop.
  • Using int/size_t instead of float whenever i can.
  • Using the fast math operations from daisySP dsp.h when possible.
  • Pre calculating smooth envelopes to reduce the amount of math in the audio callback.

But now im running out of ideas. Do any of you have some things to add to this list?

Thanks for reading!

Hi!
Could you tell us more about your code? Maybe there could be something specific for your project that could be optimized.

hey Takumi
sorry i realize the post is a quite vague. i guess i was just looking for any best practices tips, and share what ive figured out so far. like the compiler flags (i ended up just keeping the memory saving -Os flag). but maybe there is no best practices. maybe everybody is just figuring out what works for their project.
ive since solved my cpu issue, going from avg 80% to avg 30-40%. the solution? Painstakingly going through every line of code removing every processing thats not absolutely necessary. Who could have guessed?
im now able to run 4 stereo buffers and 10 stereo ish effects simultaneously

Btw thank you takumi and electrosmith team! its been so nice to work with the daisy seed! im done buying instruments/effects, from now on i just build my own.

1 Like

No worries at all! Yes, I just wanted to check with you if there was something specific about your code that could be optimized. Happy to hear that your CPU issue was solved :slight_smile:

And we’re excited that working with Daisy has been a nice experience for you! Please keep us posted about your project.

1 Like