michaelholmes4 / NNComp

Real-time recurrent neural networks for audio plugins
MIT License
83 stars 2 forks source link

Allocating on the RT Audio thread #6

Closed olilarkin closed 11 months ago

olilarkin commented 1 year ago

This is looking really nice now!

I just noticed this though:

https://github.com/michaelholmes4/NNComp/blob/d700d83872e5aa5e5001dd5d14998219b87728f5/Plugin/NNComp/NNComp.cpp#L116

It would be better to preallocate as much memory as you might need in OnReset(), rather than allocating and freeing memory in ProcessBlock()

michaelholmes4 commented 1 year ago

Thanks Oli!

I have moved the dynamic allocation to OnReset() in 0d5f0a6.

I was doing this allocation to create an audio buffer, so I am now using GetBlockSize() to determine the buffer length. I believe this is the correct way to do it?

olilarkin commented 1 year ago

That looks better :-)

I would suggest using std::vector for the buffer rather than calling new/delete.

Here is an example of how i do it using the WDL_TypedArray and WDL_Ptrilist. (you can do similar things with std::vector) https://gist.github.com/olilarkin/1103fb82de3ace6d4c94660d534100d9

michaelholmes4 commented 1 year ago

Ok great yep, a lingering effect of my background in C. This should be better 3eea759

https://github.com/michaelholmes4/NNComp/blob/c100c25972bc36071c8921ea63be8df5713f6fde/Plugin/NNComp/projects/AudioBuffer.h#L5-L33