diff --git a/src/AudioToolbox/AudioFile.cs b/src/AudioToolbox/AudioFile.cs index a490d489..41ca53e3 100644 --- a/src/AudioToolbox/AudioFile.cs +++ b/src/AudioToolbox/AudioFile.cs @@ -1003,7 +1003,7 @@ public IntPtr GetProperty (AudioFileProperty property, out int size) try { var r = AudioFileGetProperty (handle, property, ref size, buffer); if (r == 0){ - T t = *(T*) buffer; + T t = (T) Marshal.PtrToStructure (buffer, typeof (T)); return t; } diff --git a/src/AudioToolbox/AudioQueue.cs b/src/AudioToolbox/AudioQueue.cs index 8b255534..a139d8c4 100644 --- a/src/AudioToolbox/AudioQueue.cs +++ b/src/AudioToolbox/AudioQueue.cs @@ -831,8 +831,7 @@ public IntPtr GetProperty (AudioQueueProperty property, out int size) try { r = AudioQueueGetProperty (handle, property, buffer, ref size); if (r == 0){ - T result; - result = *(T*) buffer; + T result = (T) Marshal.PtrToStructure (buffer, typeof (T)); return result; } @@ -1057,11 +1056,11 @@ public AudioQueueStatus SetChannelAssignments (params AudioQueueChannelAssignmen } } - unsafe static IntPtr MarshalArray (ref T[] array, out int totalSize) where T : struct + unsafe static IntPtr MarshalArray (ref AudioQueueChannelAssignment[] array, out int totalSize) { - int elementSize = sizeof (T); + int elementSize = sizeof (AudioQueueChannelAssignment); totalSize = elementSize * array.Length; - var array_ptr = (T*) Marshal.AllocHGlobal (totalSize); + var array_ptr = (AudioQueueChannelAssignment*) Marshal.AllocHGlobal (totalSize); for (int i = 0; i < array.Length; i++) array_ptr [i] = array [i];