Community Q&A

Welcome to Audiokinetic’s community-driven Q&A forum. This is the place where Wwise and Strata users help each other out. For direct help from our team, please use the Support Tickets page. To report a bug, use the Bug Report option in the Audiokinetic Launcher. (Note that Bug Reports submitted to the Q&A forum will be rejected. Using our dedicated Bug Report system ensures your report is seen by the right people and has the best chance of being fixed.)

To get the best answers quickly, follow these tips when posting a question:

  • Be Specific: What are you trying to achieve, or what specific issue are you running into?
  • Include Key Details: Include details like your Wwise and game engine versions, operating system, etc.
  • Explain What You've Tried: Let others know what troubleshooting steps you've already taken.
  • Focus on the Facts: Describe the technical facts of your issue. Focusing on the problem helps others find a solution quickly.

0 votes

Hello,

We've set up the call to AkSoundEngine.SetMultiplePositions and it is working well if we're using the AkPositionArray.Add(AkVector64 pos) every time.
However, clicking through to the source, it seems this is marshalling to a byte[] array when using add, and profiling into the project this is causing a large amount of allocations (in our case per frame). Specifically the BitConverter.GetBytes[] in the Add function (which has comments from the AK team that acknowledge this)
Is there a way around these allocations, indexing into the AkPositionArray directly or anything of the sort that we're missing?

Thanks!
(Wwise 2024.1.6 - Unity 6000.0.27f1)

in General Discussion by Arthur Wollocko (100 points)

1 Answer

0 votes

Yes, I also noticed this causes frequent GC allocations. So I switched to the following `unsafe` code: it reinterprets the `float` bit pattern as an `int` (via pointer cast) and writes it directly, avoiding the `BitConverter.GetBytes` allocation overhead.

// Previous (allocates a new byte[4] each time):
// Marshal.WriteInt32(m_Current,
// BitConverter.ToInt32(BitConverter.GetBytes(in_Forward.x), 0));

// Optimized: reinterpret the float bits as int (no GC)
System.Runtime.InteropServices.Marshal.WriteInt32(m_Current, *(int*)&in_Forward.x);
m_Current = (IntPtr)(m_Current.ToInt64() + sizeof(float));
by six six (140 points)
...