Unfortunately it is not possible to define custom bindings. However, since 2022.1, we have internally the ability to make Spans cross the native/managed boundary without buffer copy. I’ll file a ticket about this API, don’t hesitate to propose others
Thank you! Another APIs commonly used by rhythm games are AudioSource.GetOutputData and AudioSource.GetSpectrumData (also AudioListener.GetOutputData, AudioListener.GetSpectrumData).
I’m mostly using burst and NativeArrays, hopefully new Span<byte>(nativeArray.GetUnsafeReadOnlyPtr(), nativeArray.Length); will work fine.
I have a library that allows you to do this, though unfortunately as of Unity 2023 the internal AudioClip::SetData/AudioClip::GetData methods are only available in the editor and in development builds. In release builds, SoundHandleAPI::SetData/SoundHandleAPI::GetData is used instead, which requires you to know the location of a field inside AudioClip (this isn’t too hard to figure out, but it depends on your Unity version.)
Note that obviously Unity likely won’t give you any support for using this technique, as it’s rather low-level and dangerous if not done correctly. It’s also worth noting that the library only supports Windows currently (both editor and builds), because it uses DIA to process the PDBs that ship with Unity, and DIA is a Windows-only API.
Speaking of GetData(), I ended up moving to FMOD (unity also uses fmod but old version). They simply give IntPtr buffer I can use with both array and NativeArray, way more flexible.