AttachAudioMixedProcessor Utils for easy callback (#215)
This commit is contained in:
parent
818b52cbeb
commit
b049b4f88d
3 changed files with 57 additions and 0 deletions
23
Raylib-cs/types/AudioMixed.cs
Normal file
23
Raylib-cs/types/AudioMixed.cs
Normal file
|
|
@ -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<float> 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<float> floats = new(buffer, (int)frames);
|
||||
Callback?.Invoke(floats);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue