-
Notifications
You must be signed in to change notification settings - Fork 516
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AudioUnit allocates on the heap for every RenderCallback #8836
Comments
I've done some more looking at this. Each call from the native code uses the same underlying buffer (confirmed by printing the memory address of the IntPtr on each call.) Whoever wrote the c# wrapper code doesn't seem to be worried about the caller keeping a reference to the AudioBuffers instance because it is disposed immediately. (which does nothing because in this case AudioBuffers doesn't own the pointer so the dispose returns without doing anything) Given these two things I propose the following: I am happy to provide a pull request that does this. |
It would be nice to get an indication if such a change is likely to be accepted before I go ahead and implement it and submit a merge request. |
Being able to improve this API to be less allocation friendly would be a solid improvement, if we can do it in a backward compatible way. Unfortuntely AudioBuffers is a public class, so converting it to a struct would be a hard API break. On:
I'll let @dalexsoto comment on how viable that is before you work up a PR. |
@trampster the probability of acceptance depends a lot on not having breaking changes in the public API. Since
However that does not makes changes impossible, just a bit harder (to keep existing code working).
I'm no expert on AudioUnit (or our bindings for it), other people will chime in when back at work. Still that sounds like a reasonable approach. I suggest you to put out a more complete proposal first (it can be a pull request or here in the bug). It might take a few iterations to solve the issue, without creating compatibility problems, but it's clearly worth it :) |
Also note that it looks like RenderCallback (and InputCallback) are bound incorrectly, some of their arguments should be |
Steps to Reproduce
Expected Behavior
No heap allocations during audio playback
Actual Behavior
A new AudioBuffer is allocated for every call for me this is 50 times a second. This will be slow, and increase the frequency of Garbage collection calls, resulting in GC pauses during playback which could impact audio quality.
Environment
You can see this by looking at the github code
Possible solutions:
The text was updated successfully, but these errors were encountered: