Optimization - DSP_PARAMETER_FFT get spectrum big GC allocations overhead

Hi guys,
So, I’m creating a mobile Unity game in which important part is music visualization. I am using FFT DSP to get spectrum from music and update visualization.
When I was optimizing my game I noticed big GC allocation peaks especially on mobile devices. They’ve been creating really nasty frame drops even on high end device. So what turned out the reason was get spectrum method from DSP_PARAMETER_FFT struct (fmod_dsp.cs)

Every time we are accessing spectrum data we allocate great amount of memory for big spectrum array, and it allocates over 4 KB of memory (in my case every frame) - not very cool…
So I created my own method that fill pre created array with data instead of creating new one.

There is a screen with original code and my own (2nd one) and Unity profiler data:

I decided to share what I learned here - it may help someone with similar problem.
And for FMOD team - I really think you should fix that stuff in Unity integration update - it’s really not a very good way to write code especially considering it’s a part of low-level fmod integration. There are probably many people that doesn’t realize how big overhead it creates.

Best regards,
Radek

Thanks for the feedback, that does seem like it would be a nicer method, especially for an example.

I’ll make sure this gets changed for a future update.