Not a good practice to access AudioQueueBuffer.AudioData by Marshal.ReadIntPtr
- Dominant language
- C#
- Stars
- 2.9k
- Forks
- 576
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 96
Description
I am working on iOS audio. After struggling with IntPtr-s, which might be a AudioQueueBuffer*,
or pointing to raw samples, I finally managed to make things work.
But, I find below code seems not a good practice.
https://github.com/xamarin/xamarin-macios/blob/e45c3ba794e25c4ecb1c076678b733746ca184e4/src/AudioToolbox/AudioQueue.cs#L499
### Steps to Reproduce
Check the source code of AudioQueue.FillAudioData(...).
```c#
public static void FillAudioData (IntPtr audioQueueBuffer, int offset, IntPtr source, int sourceOffset, nint size)
{
// Here, location of field AudioData is almost *hard-coded*
IntPtr target = Marshal.ReadIntPtr (audioQueueBuffer, IntPtr.Size);
unsafe {
byte *targetp = (byte *) target;
byte *sourcep = (byte *) source;
Runtime.memcpy (targetp + offset, sourcep + sourceOffset, size);
}
}
```
### Expected Behavior
1. Use AudioQueueBuffer.AudioData;
2. Use AudioQueueBuffer.CopyToAudioData(IntPtr source, int size).
### Actual Behavior
The implementation seems not a good one.
### Environment
N/A
### Build Logs
N/A
### Example Project (If Possible)
N/A
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.