From b049b4f88dad22bd6bc774a55c583294441baa1a Mon Sep 17 00:00:00 2001 From: Nicky McDonald <43690021+nickyMcDonald@users.noreply.github.com> Date: Sat, 24 Feb 2024 03:44:13 -0500 Subject: [PATCH 1/3] AttachAudioMixedProcessor Utils for easy callback (#215) --- Raylib-cs/types/AudioCallback.cs | 10 ++++++++++ Raylib-cs/types/AudioMixed.cs | 23 +++++++++++++++++++++++ Raylib-cs/types/Raylib.Utils.cs | 24 ++++++++++++++++++++++++ 3 files changed, 57 insertions(+) create mode 100644 Raylib-cs/types/AudioCallback.cs create mode 100644 Raylib-cs/types/AudioMixed.cs diff --git a/Raylib-cs/types/AudioCallback.cs b/Raylib-cs/types/AudioCallback.cs new file mode 100644 index 0000000..2f7b372 --- /dev/null +++ b/Raylib-cs/types/AudioCallback.cs @@ -0,0 +1,10 @@ +using System; + +namespace Raylib_cs; + +/// +/// Audio stream processor. +/// Used with Raylib.AttachAudioMixedProcessor() +/// and Raylib.DetachAudioMixedProcessor() +/// +public delegate void AudioCallback(Span buffer); diff --git a/Raylib-cs/types/AudioMixed.cs b/Raylib-cs/types/AudioMixed.cs new file mode 100644 index 0000000..bf98491 --- /dev/null +++ b/Raylib-cs/types/AudioMixed.cs @@ -0,0 +1,23 @@ +using System; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +namespace Raylib_cs; + +internal static unsafe class AudioMixed +{ + public static AudioCallback Callback = null; + + [UnmanagedCallersOnly(CallConvs = new[] + { + typeof(CallConvCdecl), + })] + public static void Processor(void* buffer, uint frames) + { + // The buffer is stereo audio, so we need to double our frame count. + frames = Math.Min(frames * 2, int.MaxValue); + + Span floats = new(buffer, (int)frames); + Callback?.Invoke(floats); + } +} diff --git a/Raylib-cs/types/Raylib.Utils.cs b/Raylib-cs/types/Raylib.Utils.cs index c3b2f1d..46ba915 100644 --- a/Raylib-cs/types/Raylib.Utils.cs +++ b/Raylib-cs/types/Raylib.Utils.cs @@ -1261,6 +1261,30 @@ public static unsafe partial class Raylib } } + /// + /// Attach audio stream processor to the entire audio pipeline + /// + public static void AttachAudioMixedProcessor(AudioCallback processor) + { + if (AudioMixed.Callback == null) + { + AudioMixed.Callback = processor; + AttachAudioMixedProcessor(&AudioMixed.Processor); + } + } + + /// + /// Detach audio stream processor from the entire audio pipeline + /// + public static void DetachAudioMixedProcessor(AudioCallback processor) + { + if (AudioMixed.Callback == processor) + { + DetachAudioMixedProcessor(&AudioMixed.Processor); + AudioMixed.Callback = null; + } + } + public static string SubText(this string input, int position, int length) { return input.Substring(position, Math.Min(length, input.Length)); From 47877ee2e771398988d386f0503ab37a041f3e26 Mon Sep 17 00:00:00 2001 From: Ben Parsons <9ParsonsB@users.noreply.github.com> Date: Tue, 21 May 2024 16:40:05 +1000 Subject: [PATCH 2/3] Update Language Version to C# 12 (#242) --- Examples/Examples.csproj | 2 +- Raylib-cs.Tests/Raylib-cs.Tests.csproj | 1 + Raylib-cs/Raylib-cs.csproj | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Examples/Examples.csproj b/Examples/Examples.csproj index 6fc42f2..cd05201 100644 --- a/Examples/Examples.csproj +++ b/Examples/Examples.csproj @@ -5,7 +5,7 @@ true Examples.Program $(MSBuildThisFileDirectory) - 10 + 12 enable diff --git a/Raylib-cs.Tests/Raylib-cs.Tests.csproj b/Raylib-cs.Tests/Raylib-cs.Tests.csproj index c6c27ee..fa9d3a9 100644 --- a/Raylib-cs.Tests/Raylib-cs.Tests.csproj +++ b/Raylib-cs.Tests/Raylib-cs.Tests.csproj @@ -2,6 +2,7 @@ net6.0 true + 12 diff --git a/Raylib-cs/Raylib-cs.csproj b/Raylib-cs/Raylib-cs.csproj index 48c59a0..9969b12 100644 --- a/Raylib-cs/Raylib-cs.csproj +++ b/Raylib-cs/Raylib-cs.csproj @@ -1,13 +1,13 @@ - net5.0;net6.0 + net6.0 false Raylib-cs Raylib_cs true false $(NoWarn);1591 - 10.0 + 12 From 502a583e076cf1595a12def81206be7f804002e5 Mon Sep 17 00:00:00 2001 From: JupiterRider <60042618+JupiterRider@users.noreply.github.com> Date: Tue, 21 May 2024 20:06:11 +0200 Subject: [PATCH 3/3] UnloadMesh needs a value, not a pointer (#243) --- Raylib-cs/interop/Raylib.cs | 2 +- Raylib-cs/types/Raylib.Utils.cs | 9 --------- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/Raylib-cs/interop/Raylib.cs b/Raylib-cs/interop/Raylib.cs index cebd3a8..662ee7d 100644 --- a/Raylib-cs/interop/Raylib.cs +++ b/Raylib-cs/interop/Raylib.cs @@ -2350,7 +2350,7 @@ public static unsafe partial class Raylib /// Unload mesh from memory (RAM and/or VRAM) [DllImport(NativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void UnloadMesh(Mesh* mesh); + public static extern void UnloadMesh(Mesh mesh); /// Draw a 3d mesh with material and transform [DllImport(NativeLibName, CallingConvention = CallingConvention.Cdecl)] diff --git a/Raylib-cs/types/Raylib.Utils.cs b/Raylib-cs/types/Raylib.Utils.cs index 46ba915..1b83b66 100644 --- a/Raylib-cs/types/Raylib.Utils.cs +++ b/Raylib-cs/types/Raylib.Utils.cs @@ -911,15 +911,6 @@ public static unsafe partial class Raylib } } - /// Unload mesh from memory (RAM and/or VRAM) - public static void UnloadMesh(ref Mesh mesh) - { - fixed (Mesh* p = &mesh) - { - UnloadMesh(p); - } - } - /// Set texture for a material map type (MAP_DIFFUSE, MAP_SPECULAR...) public static void SetMaterialTexture(ref Material material, MaterialMapIndex mapType, Texture2D texture) {