From 1c836085bfe200c0042dc49f7fc15cb7de3f06fd Mon Sep 17 00:00:00 2001 From: Stephen Hawley Date: Tue, 30 Aug 2022 10:21:47 -0400 Subject: [PATCH 1/5] [.NET/AudioUnit] Use [UnmanagedCallersOnly] instead of [MonoPInvokeCallback] Partial Fix for #10470 --- src/AudioUnit/AUGraph.cs | 83 ++++++++++++++++++++++++++++++++++++++ src/AudioUnit/AudioUnit.cs | 75 +++++++++++++++++++++++++++++++++- 2 files changed, 157 insertions(+), 1 deletion(-) diff --git a/src/AudioUnit/AUGraph.cs b/src/AudioUnit/AUGraph.cs index 797aa5219a5..e17c3fc1929 100644 --- a/src/AudioUnit/AUGraph.cs +++ b/src/AudioUnit/AUGraph.cs @@ -140,8 +140,15 @@ public AudioUnitStatus AddRenderNotify (RenderDelegate callback) ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (callback)); AudioUnitStatus error = AudioUnitStatus.OK; +#if NET + unsafe { + if (graphUserCallbacks.Count == 0) + error = (AudioUnitStatus) AUGraphAddRenderNotify (Handle, &renderCallback, GCHandle.ToIntPtr (gcHandle)); + } +#else if (graphUserCallbacks.Count == 0) error = (AudioUnitStatus) AUGraphAddRenderNotify (Handle, renderCallback, GCHandle.ToIntPtr (gcHandle)); +#endif if (error == AudioUnitStatus.OK) graphUserCallbacks.Add (callback); @@ -156,8 +163,15 @@ public AudioUnitStatus RemoveRenderNotify (RenderDelegate callback) throw new ArgumentException ("Cannot unregister a callback that has not been registered"); AudioUnitStatus error = AudioUnitStatus.OK; +#if NET + unsafe { + if (graphUserCallbacks.Count == 0) + error = (AudioUnitStatus)AUGraphRemoveRenderNotify (Handle, &renderCallback, GCHandle.ToIntPtr (gcHandle)); + } +#else if (graphUserCallbacks.Count == 0) error = (AudioUnitStatus)AUGraphRemoveRenderNotify (Handle, renderCallback, GCHandle.ToIntPtr (gcHandle)); +#endif graphUserCallbacks.Remove (callback); // Remove from list even if there is an error return error; @@ -165,6 +179,26 @@ public AudioUnitStatus RemoveRenderNotify (RenderDelegate callback) HashSet graphUserCallbacks = new HashSet (); +#if !NET + static CallbackShared? _static_CallbackShared; + static CallbackShared static_CallbackShared { + get { + if (_static_CallbackShared is null) + _static_CallbackShared = new CallbackShared (renderCallback); + return _static_CallbackShared; + } + } +#endif + +#if NET + [UnmanagedCallersOnly] + static unsafe AudioUnitStatus renderCallback(IntPtr inRefCon, + AudioUnitRenderActionFlags* _ioActionFlags, + AudioTimeStamp* _inTimeStamp, + uint _inBusNumber, + uint _inNumberFrames, + IntPtr _ioData) +#else [MonoPInvokeCallback (typeof(CallbackShared))] static AudioUnitStatus renderCallback(IntPtr inRefCon, ref AudioUnitRenderActionFlags _ioActionFlags, @@ -172,6 +206,7 @@ static AudioUnitStatus renderCallback(IntPtr inRefCon, uint _inBusNumber, uint _inNumberFrames, IntPtr _ioData) +#endif { // getting audiounit instance var handler = GCHandle.FromIntPtr (inRefCon); @@ -183,8 +218,18 @@ static AudioUnitStatus renderCallback(IntPtr inRefCon, if (renderers.Count != 0) { using (var buffers = new AudioBuffers (_ioData)) { +#if NET + foreach (RenderDelegate renderer in renderers) { + var tempActionFlags = *_ioActionFlags; + var tempTimeStamp = *_inTimeStamp; + renderer (tempActionFlags, tempTimeStamp, _inBusNumber, _inNumberFrames, buffers); + *_ioActionFlags = tempActionFlags; + *_inTimeStamp = tempTimeStamp; + } +#else foreach (RenderDelegate renderer in renderers) renderer (_ioActionFlags, _inTimeStamp, _inBusNumber, _inNumberFrames, buffers); +#endif return AudioUnitStatus.OK; } } @@ -313,7 +358,9 @@ public AUGraphError DisconnectNodeInput (int destNode, uint destInputNumber) } Dictionary? nodesCallbacks; +#if !NET static readonly CallbackShared CreateRenderCallback = RenderCallbackImpl; +#endif public AUGraphError SetNodeInputCallback (int destNode, uint destInputNumber, RenderDelegate renderDelegate) { @@ -323,25 +370,52 @@ public AUGraphError SetNodeInputCallback (int destNode, uint destInputNumber, Re nodesCallbacks [destInputNumber] = renderDelegate; var cb = new AURenderCallbackStruct (); +#if NET + unsafe { + cb.Proc = &RenderCallbackImpl; + } +#else cb.Proc = CreateRenderCallback; +#endif cb.ProcRefCon = GCHandle.ToIntPtr (gcHandle); return AUGraphSetNodeInputCallback (Handle, destNode, destInputNumber, ref cb); } +#if NET + [UnmanagedCallersOnly] + static unsafe int RenderCallbackImpl (IntPtr clientData, int* actionFlags, AudioTimeStamp* timeStamp, uint busNumber, uint numberFrames, IntPtr data) +#else [MonoPInvokeCallback (typeof (CallbackShared))] static AudioUnitStatus RenderCallbackImpl (IntPtr clientData, ref AudioUnitRenderActionFlags actionFlags, ref AudioTimeStamp timeStamp, uint busNumber, uint numberFrames, IntPtr data) +#endif { GCHandle gch = GCHandle.FromIntPtr (clientData); var au = gch.Target as AUGraph; +#if NET + if (au?.nodesCallbacks is null) + return (int)AudioUnitStatus.InvalidParameter; + if (!au.nodesCallbacks.TryGetValue (busNumber, out var callback)) + return (int)AudioUnitStatus.InvalidParameter; +#else if (au?.nodesCallbacks is null) return AudioUnitStatus.InvalidParameter; if (!au.nodesCallbacks.TryGetValue (busNumber, out var callback)) return AudioUnitStatus.InvalidParameter; +#endif using (var buffers = new AudioBuffers (data)) { +#if NET + AudioUnitRenderActionFlags tempActionFlags = (AudioUnitRenderActionFlags)(*actionFlags); + var tempTimeStamp = *timeStamp; + var returnValue = callback (tempActionFlags, tempTimeStamp, busNumber, numberFrames, buffers); + *actionFlags = (int)tempActionFlags; + *timeStamp = tempTimeStamp; + return (int)returnValue; +#else return callback (actionFlags, timeStamp, busNumber, numberFrames, buffers); +#endif } } @@ -435,10 +509,19 @@ protected override void Dispose (bool disposing) static extern AUGraphError AUGraphInitialize (IntPtr inGraph); [DllImport (Constants.AudioToolboxLibrary)] +#if NET + static unsafe extern int AUGraphAddRenderNotify (IntPtr inGraph, delegate* unmanaged inCallback, IntPtr inRefCon ); +#else static extern int AUGraphAddRenderNotify (IntPtr inGraph, CallbackShared inCallback, IntPtr inRefCon ); +#endif +#if NET + [DllImport (Constants.AudioToolboxLibrary)] + static unsafe extern int AUGraphRemoveRenderNotify (IntPtr inGraph, delegate* unmanaged inCallback, IntPtr inRefCon ); +#else [DllImport (Constants.AudioToolboxLibrary)] static extern int AUGraphRemoveRenderNotify (IntPtr inGraph, CallbackShared inCallback, IntPtr inRefCon ); +#endif [DllImport (Constants.AudioToolboxLibrary)] static extern AUGraphError AUGraphStart (IntPtr inGraph); diff --git a/src/AudioUnit/AudioUnit.cs b/src/AudioUnit/AudioUnit.cs index 36ef16237c4..f0f07086064 100644 --- a/src/AudioUnit/AudioUnit.cs +++ b/src/AudioUnit/AudioUnit.cs @@ -135,12 +135,21 @@ internal AudioUnitException (int k) : base (Lookup (k)) delegate AudioUnitStatus CallbackShared (IntPtr /* void* */ clientData, ref AudioUnitRenderActionFlags /* AudioUnitRenderActionFlags* */ actionFlags, ref AudioTimeStamp /* AudioTimeStamp* */ timeStamp, uint /* UInt32 */ busNumber, uint /* UInt32 */ numberFrames, IntPtr /* AudioBufferList* */ data); #endif // !COREBUILD +#if NET + [StructLayout (LayoutKind.Sequential)] + public unsafe struct AURenderCallbackStruct + { + public delegate* unmanaged Proc; + public IntPtr ProcRefCon; + } +#else [StructLayout (LayoutKind.Sequential)] struct AURenderCallbackStruct { public Delegate Proc; public IntPtr ProcRefCon; } +#endif [StructLayout (LayoutKind.Sequential)] struct AudioUnitConnection @@ -349,8 +358,10 @@ public struct ImmediateStruct public class AudioUnit : DisposableObject { #if !COREBUILD +#if !NET static readonly CallbackShared CreateRenderCallback = RenderCallbackImpl; static readonly CallbackShared CreateInputCallback = InputCallbackImpl; +#endif GCHandle gcHandle; bool _isPlaying; @@ -657,26 +668,55 @@ public AudioUnitStatus SetRenderCallback (RenderDelegate renderDelegate, AudioUn gcHandle = GCHandle.Alloc (this); var cb = new AURenderCallbackStruct (); +#if NET + unsafe { + cb.Proc = &RenderCallbackImpl; + } +#else cb.Proc = CreateRenderCallback; +#endif cb.ProcRefCon = GCHandle.ToIntPtr (gcHandle); return AudioUnitSetProperty (Handle, AudioUnitPropertyIDType.SetRenderCallback, scope, audioUnitElement, ref cb, Marshal.SizeOf (cb)); } +#if NET + [UnmanagedCallersOnly] + static unsafe int RenderCallbackImpl (IntPtr clientData, int* actionFlags, AudioTimeStamp* timeStamp, uint busNumber, uint numberFrames, IntPtr data) +#else [MonoPInvokeCallback (typeof (CallbackShared))] static AudioUnitStatus RenderCallbackImpl (IntPtr clientData, ref AudioUnitRenderActionFlags actionFlags, ref AudioTimeStamp timeStamp, uint busNumber, uint numberFrames, IntPtr data) +#endif { GCHandle gch = GCHandle.FromIntPtr (clientData); var au = (AudioUnit?) gch.Target; var renderer = au?.renderer; +#if NET + if (renderer is null) + return (int)AudioUnitStatus.Uninitialized; + if (!renderer.TryGetValue (busNumber, out var render)) + return (int)AudioUnitStatus.Uninitialized; +#else if (renderer is null) return AudioUnitStatus.Uninitialized; if (!renderer.TryGetValue (busNumber, out var render)) return AudioUnitStatus.Uninitialized; +#endif using (var buffers = new AudioBuffers (data)) { +#if NET + unsafe { + var tempActionFlags = (AudioUnitRenderActionFlags)(*actionFlags); + var tempTimeStamp = *timeStamp; + var returnValue = render (tempActionFlags, tempTimeStamp, busNumber, numberFrames, buffers); + *actionFlags = (int)tempActionFlags; + *timeStamp = tempTimeStamp; + return (int)returnValue; + } +#else return render (actionFlags, timeStamp, busNumber, numberFrames, buffers); +#endif } } @@ -695,14 +735,46 @@ public AudioUnitStatus SetInputCallback (InputDelegate inputDelegate, AudioUnitS gcHandle = GCHandle.Alloc (this); var cb = new AURenderCallbackStruct (); +#if NET + unsafe { + cb.Proc = &InputCallbackImpl; + } +#else cb.Proc = CreateInputCallback; +#endif cb.ProcRefCon = GCHandle.ToIntPtr (gcHandle); return AudioUnitSetProperty (Handle, AudioUnitPropertyIDType.SetInputCallback, scope, audioUnitElement, ref cb, Marshal.SizeOf (cb)); } - +#if NET + [UnmanagedCallersOnly] + static unsafe int InputCallbackImpl (IntPtr clientData, int* actionFlags, AudioTimeStamp* timeStamp, uint busNumber, uint numberFrames, IntPtr data) +#else [MonoPInvokeCallback (typeof (CallbackShared))] static AudioUnitStatus InputCallbackImpl (IntPtr clientData, ref AudioUnitRenderActionFlags actionFlags, ref AudioTimeStamp timeStamp, uint busNumber, uint numberFrames, IntPtr data) +#endif { +#if NET + GCHandle gch = GCHandle.FromIntPtr (clientData); + var au = gch.Target as AudioUnit; + if (au is null) + return (int)AudioUnitStatus.Uninitialized; + + var inputs = au.inputs; + if (inputs is null) + return (int)AudioUnitStatus.Uninitialized; + + if (!inputs.TryGetValue (busNumber, out var input)) + return (int)AudioUnitStatus.Uninitialized; + + unsafe { + var tempActionFlags = (AudioUnitRenderActionFlags)(*actionFlags); + var tempTimeStamp = *timeStamp; + var returnValue = input (tempActionFlags, tempTimeStamp, busNumber, numberFrames, au); + *timeStamp = tempTimeStamp; + *actionFlags = (int)tempActionFlags; + return (int)returnValue; + } +#else GCHandle gch = GCHandle.FromIntPtr (clientData); var au = gch.Target as AudioUnit; if (au is null) @@ -716,6 +788,7 @@ static AudioUnitStatus InputCallbackImpl (IntPtr clientData, ref AudioUnitRender return AudioUnitStatus.Uninitialized; return input (actionFlags, timeStamp, busNumber, numberFrames, au); +#endif } #endregion From 0f3fc4e34c475ec11c4d5d2cd2e437832cd9cd2b Mon Sep 17 00:00:00 2001 From: Stephen Hawley Date: Tue, 30 Aug 2022 11:24:13 -0400 Subject: [PATCH 2/5] lose that public there --- src/AudioUnit/AudioUnit.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AudioUnit/AudioUnit.cs b/src/AudioUnit/AudioUnit.cs index f0f07086064..66f2ee19c33 100644 --- a/src/AudioUnit/AudioUnit.cs +++ b/src/AudioUnit/AudioUnit.cs @@ -137,7 +137,7 @@ internal AudioUnitException (int k) : base (Lookup (k)) #if NET [StructLayout (LayoutKind.Sequential)] - public unsafe struct AURenderCallbackStruct + unsafe struct AURenderCallbackStruct { public delegate* unmanaged Proc; public IntPtr ProcRefCon; From 90517031d514d8d4749254677b8cb9eca70cb767 Mon Sep 17 00:00:00 2001 From: Stephen Hawley Date: Wed, 31 Aug 2022 11:55:08 -0400 Subject: [PATCH 3/5] not so greasy now --- src/AudioUnit/AUGraph.cs | 16 ++++--------- src/AudioUnit/AudioUnit.cs | 49 +++++++++++++------------------------- 2 files changed, 20 insertions(+), 45 deletions(-) diff --git a/src/AudioUnit/AUGraph.cs b/src/AudioUnit/AUGraph.cs index e17c3fc1929..ca91fc07ad1 100644 --- a/src/AudioUnit/AUGraph.cs +++ b/src/AudioUnit/AUGraph.cs @@ -382,7 +382,7 @@ public AUGraphError SetNodeInputCallback (int destNode, uint destInputNumber, Re } #if NET [UnmanagedCallersOnly] - static unsafe int RenderCallbackImpl (IntPtr clientData, int* actionFlags, AudioTimeStamp* timeStamp, uint busNumber, uint numberFrames, IntPtr data) + static unsafe AudioUnitStatus RenderCallbackImpl (IntPtr clientData, AudioUnitRenderActionFlags* actionFlags, AudioTimeStamp* timeStamp, uint busNumber, uint numberFrames, IntPtr data) #else [MonoPInvokeCallback (typeof (CallbackShared))] @@ -391,28 +391,20 @@ static AudioUnitStatus RenderCallbackImpl (IntPtr clientData, ref AudioUnitRende { GCHandle gch = GCHandle.FromIntPtr (clientData); var au = gch.Target as AUGraph; -#if NET - if (au?.nodesCallbacks is null) - return (int)AudioUnitStatus.InvalidParameter; - - if (!au.nodesCallbacks.TryGetValue (busNumber, out var callback)) - return (int)AudioUnitStatus.InvalidParameter; -#else if (au?.nodesCallbacks is null) return AudioUnitStatus.InvalidParameter; if (!au.nodesCallbacks.TryGetValue (busNumber, out var callback)) return AudioUnitStatus.InvalidParameter; -#endif using (var buffers = new AudioBuffers (data)) { #if NET - AudioUnitRenderActionFlags tempActionFlags = (AudioUnitRenderActionFlags)(*actionFlags); + AudioUnitRenderActionFlags tempActionFlags = *actionFlags; var tempTimeStamp = *timeStamp; var returnValue = callback (tempActionFlags, tempTimeStamp, busNumber, numberFrames, buffers); - *actionFlags = (int)tempActionFlags; + *actionFlags = tempActionFlags; *timeStamp = tempTimeStamp; - return (int)returnValue; + return returnValue; #else return callback (actionFlags, timeStamp, busNumber, numberFrames, buffers); #endif diff --git a/src/AudioUnit/AudioUnit.cs b/src/AudioUnit/AudioUnit.cs index 66f2ee19c33..89b1041aae6 100644 --- a/src/AudioUnit/AudioUnit.cs +++ b/src/AudioUnit/AudioUnit.cs @@ -139,7 +139,11 @@ internal AudioUnitException (int k) : base (Lookup (k)) [StructLayout (LayoutKind.Sequential)] unsafe struct AURenderCallbackStruct { +#if COREBUILD public delegate* unmanaged Proc; +#else + public delegate* unmanaged Proc; +#endif public IntPtr ProcRefCon; } #else @@ -681,7 +685,7 @@ public AudioUnitStatus SetRenderCallback (RenderDelegate renderDelegate, AudioUn #if NET [UnmanagedCallersOnly] - static unsafe int RenderCallbackImpl (IntPtr clientData, int* actionFlags, AudioTimeStamp* timeStamp, uint busNumber, uint numberFrames, IntPtr data) + static unsafe AudioUnitStatus RenderCallbackImpl (IntPtr clientData, AudioUnitRenderActionFlags* actionFlags, AudioTimeStamp* timeStamp, uint busNumber, uint numberFrames, IntPtr data) #else [MonoPInvokeCallback (typeof (CallbackShared))] static AudioUnitStatus RenderCallbackImpl (IntPtr clientData, ref AudioUnitRenderActionFlags actionFlags, ref AudioTimeStamp timeStamp, uint busNumber, uint numberFrames, IntPtr data) @@ -690,29 +694,21 @@ static AudioUnitStatus RenderCallbackImpl (IntPtr clientData, ref AudioUnitRende GCHandle gch = GCHandle.FromIntPtr (clientData); var au = (AudioUnit?) gch.Target; var renderer = au?.renderer; -#if NET - if (renderer is null) - return (int)AudioUnitStatus.Uninitialized; - - if (!renderer.TryGetValue (busNumber, out var render)) - return (int)AudioUnitStatus.Uninitialized; -#else if (renderer is null) return AudioUnitStatus.Uninitialized; if (!renderer.TryGetValue (busNumber, out var render)) return AudioUnitStatus.Uninitialized; -#endif using (var buffers = new AudioBuffers (data)) { #if NET unsafe { - var tempActionFlags = (AudioUnitRenderActionFlags)(*actionFlags); + var tempActionFlags = *actionFlags; var tempTimeStamp = *timeStamp; var returnValue = render (tempActionFlags, tempTimeStamp, busNumber, numberFrames, buffers); - *actionFlags = (int)tempActionFlags; + *actionFlags = tempActionFlags; *timeStamp = tempTimeStamp; - return (int)returnValue; + return returnValue; } #else return render (actionFlags, timeStamp, busNumber, numberFrames, buffers); @@ -747,46 +743,33 @@ public AudioUnitStatus SetInputCallback (InputDelegate inputDelegate, AudioUnitS } #if NET [UnmanagedCallersOnly] - static unsafe int InputCallbackImpl (IntPtr clientData, int* actionFlags, AudioTimeStamp* timeStamp, uint busNumber, uint numberFrames, IntPtr data) + static unsafe AudioUnitStatus InputCallbackImpl (IntPtr clientData, AudioUnitRenderActionFlags* actionFlags, AudioTimeStamp* timeStamp, uint busNumber, uint numberFrames, IntPtr data) #else [MonoPInvokeCallback (typeof (CallbackShared))] static AudioUnitStatus InputCallbackImpl (IntPtr clientData, ref AudioUnitRenderActionFlags actionFlags, ref AudioTimeStamp timeStamp, uint busNumber, uint numberFrames, IntPtr data) #endif { -#if NET GCHandle gch = GCHandle.FromIntPtr (clientData); var au = gch.Target as AudioUnit; if (au is null) - return (int)AudioUnitStatus.Uninitialized; + return AudioUnitStatus.Uninitialized; var inputs = au.inputs; if (inputs is null) - return (int)AudioUnitStatus.Uninitialized; + return AudioUnitStatus.Uninitialized; if (!inputs.TryGetValue (busNumber, out var input)) - return (int)AudioUnitStatus.Uninitialized; - + return AudioUnitStatus.Uninitialized; +#if NET unsafe { - var tempActionFlags = (AudioUnitRenderActionFlags)(*actionFlags); + var tempActionFlags = *actionFlags; var tempTimeStamp = *timeStamp; var returnValue = input (tempActionFlags, tempTimeStamp, busNumber, numberFrames, au); *timeStamp = tempTimeStamp; - *actionFlags = (int)tempActionFlags; - return (int)returnValue; + *actionFlags = tempActionFlags; + return returnValue; } #else - GCHandle gch = GCHandle.FromIntPtr (clientData); - var au = gch.Target as AudioUnit; - if (au is null) - return AudioUnitStatus.Uninitialized; - - var inputs = au.inputs; - if (inputs is null) - return AudioUnitStatus.Uninitialized; - - if (!inputs.TryGetValue (busNumber, out var input)) - return AudioUnitStatus.Uninitialized; - return input (actionFlags, timeStamp, busNumber, numberFrames, au); #endif } From 581d381460679d780e36e8d8c6eb672dbca0ef2c Mon Sep 17 00:00:00 2001 From: Stephen Hawley Date: Wed, 31 Aug 2022 13:32:31 -0400 Subject: [PATCH 4/5] more degreasing --- src/AudioUnit/AUGraph.cs | 11 +++-------- src/AudioUnit/AudioUnit.cs | 14 ++------------ 2 files changed, 5 insertions(+), 20 deletions(-) diff --git a/src/AudioUnit/AUGraph.cs b/src/AudioUnit/AUGraph.cs index ca91fc07ad1..973f6155b9e 100644 --- a/src/AudioUnit/AUGraph.cs +++ b/src/AudioUnit/AUGraph.cs @@ -218,18 +218,13 @@ static AudioUnitStatus renderCallback(IntPtr inRefCon, if (renderers.Count != 0) { using (var buffers = new AudioBuffers (_ioData)) { -#if NET foreach (RenderDelegate renderer in renderers) { - var tempActionFlags = *_ioActionFlags; - var tempTimeStamp = *_inTimeStamp; - renderer (tempActionFlags, tempTimeStamp, _inBusNumber, _inNumberFrames, buffers); - *_ioActionFlags = tempActionFlags; - *_inTimeStamp = tempTimeStamp; - } +#if NET + renderer (*_ioActionFlags, *_inTimeStamp, _inBusNumber, _inNumberFrames, buffers); #else - foreach (RenderDelegate renderer in renderers) renderer (_ioActionFlags, _inTimeStamp, _inBusNumber, _inNumberFrames, buffers); #endif + } return AudioUnitStatus.OK; } } diff --git a/src/AudioUnit/AudioUnit.cs b/src/AudioUnit/AudioUnit.cs index 89b1041aae6..6811c3e9078 100644 --- a/src/AudioUnit/AudioUnit.cs +++ b/src/AudioUnit/AudioUnit.cs @@ -703,12 +703,7 @@ static AudioUnitStatus RenderCallbackImpl (IntPtr clientData, ref AudioUnitRende using (var buffers = new AudioBuffers (data)) { #if NET unsafe { - var tempActionFlags = *actionFlags; - var tempTimeStamp = *timeStamp; - var returnValue = render (tempActionFlags, tempTimeStamp, busNumber, numberFrames, buffers); - *actionFlags = tempActionFlags; - *timeStamp = tempTimeStamp; - return returnValue; + return render (*actionFlags, *timeStamp, busNumber, numberFrames, buffers); } #else return render (actionFlags, timeStamp, busNumber, numberFrames, buffers); @@ -762,12 +757,7 @@ static AudioUnitStatus InputCallbackImpl (IntPtr clientData, ref AudioUnitRender return AudioUnitStatus.Uninitialized; #if NET unsafe { - var tempActionFlags = *actionFlags; - var tempTimeStamp = *timeStamp; - var returnValue = input (tempActionFlags, tempTimeStamp, busNumber, numberFrames, au); - *timeStamp = tempTimeStamp; - *actionFlags = tempActionFlags; - return returnValue; + return input (*actionFlags, *timeStamp, busNumber, numberFrames, au); } #else return input (actionFlags, timeStamp, busNumber, numberFrames, au); From 9d28149928e535866a22e76f6f60525e4161c30e Mon Sep 17 00:00:00 2001 From: Stephen Hawley Date: Thu, 1 Sep 2022 11:07:34 -0400 Subject: [PATCH 5/5] final grease --- src/AudioUnit/AUGraph.cs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/AudioUnit/AUGraph.cs b/src/AudioUnit/AUGraph.cs index 973f6155b9e..40451db0bdf 100644 --- a/src/AudioUnit/AUGraph.cs +++ b/src/AudioUnit/AUGraph.cs @@ -394,12 +394,7 @@ static AudioUnitStatus RenderCallbackImpl (IntPtr clientData, ref AudioUnitRende using (var buffers = new AudioBuffers (data)) { #if NET - AudioUnitRenderActionFlags tempActionFlags = *actionFlags; - var tempTimeStamp = *timeStamp; - var returnValue = callback (tempActionFlags, tempTimeStamp, busNumber, numberFrames, buffers); - *actionFlags = tempActionFlags; - *timeStamp = tempTimeStamp; - return returnValue; + return callback (*actionFlags, *timeStamp, busNumber, numberFrames, buffers); #else return callback (actionFlags, timeStamp, busNumber, numberFrames, buffers); #endif