Hacker News new | ask | show | jobs
by samplatt 2478 days ago
I've made some (C#) code that applies an ambisonic convoluted reverberation impulse response to an audio stream, but I'm hitting performance walls with Unity & C#. I want to go C++ & Unreal, but every time I try to learn C++ my eyes glaze over and I come down with a bad case of the Stupids.

Is there any "C++ for dummies with a bent for audio processing" material you'd recommend?

7 comments

I hate to just say it like this, but it’s unlikely that C# is really your bottleneck. It’s more likely the approach or the libraries you are using that are the issue.

Try a clean implementation of that particular logic in pure C# on .NET Core, you should be able to get it working more than adequately fast. I’m saying this as someone that (re)writes applications in C++ and rust to provide pseudo-rt guarantees.

yeah especially with Span<T> it's way easier to create high performance code, while reducing GC pressure. Also depending on the Platform P/Invoke to C/C++ is also a solution that works quite better than on Java's JNI.
>applies an ambisonic convoluted reverberation impulse response to an audio stream

Yikes. If you're doing naive convolution that's O(n^2) in real time.

Try reading up on partitioned convolution techniques via FFT. The current state of the art in FFTs is using FFTW (extremely fast, GPL licensed but a bit tricky to get a commercial license if that is unacceptable) or IPP on x86 (closed source, but works and is fast).

I'd also try looking at Facebook's Two Big Ears code for ambisonic rendering via HRTFs:

https://github.com/facebookincubator/Audio360

I got started by studying the C++ code in the sample app called Touch Fighter in one of the earliest iPhone SDKs. Michael Tyson's blog helped a lot too: http://atastypixel.com/blog/. This is in Swift but really good intro to audio processing on iOS: https://github.com/syedhali/AudioStreamer.
"The audio programming book" by MIT press is amazing, a great book that doesn't cost much. Starts with a fairly large c++ tutorial.
Have you tried using all the value types performance magic (avoid GC, use structs, avoid copying, consider stackalloc, etc)?
I've built something very similar, but in C++, my email address is in my hn profile page...
You'll for sure start to hate your life as soon as you start messing with UE4.