AttachAndDetach
This commit is contained in:
parent
43f1924faa
commit
ae4b762908
3 changed files with 57 additions and 0 deletions
10
Raylib-cs/types/AudioCallback.cs
Normal file
10
Raylib-cs/types/AudioCallback.cs
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Raylib_cs;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Audio stream processor.
|
||||||
|
/// Used with Raylib.AttachAudioMixedProcessor()
|
||||||
|
/// and Raylib.DetachAudioMixedProcessor()
|
||||||
|
/// </summary>
|
||||||
|
public delegate void AudioCallback<T>(Span<T> buffer);
|
||||||
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1261,6 +1261,30 @@ public static unsafe partial class Raylib
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Attach audio stream processor to the entire audio pipeline
|
||||||
|
/// </summary>
|
||||||
|
public static void AttachAudioMixedProcessor(AudioCallback<float> processor)
|
||||||
|
{
|
||||||
|
if (AudioMixed.Callback == null)
|
||||||
|
{
|
||||||
|
AudioMixed.Callback = processor;
|
||||||
|
AttachAudioMixedProcessor(&AudioMixed.Processor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Detach audio stream processor from the entire audio pipeline
|
||||||
|
/// </summary>
|
||||||
|
public static void DetachAudioMixedProcessor(AudioCallback<float> processor)
|
||||||
|
{
|
||||||
|
if (AudioMixed.Callback == processor)
|
||||||
|
{
|
||||||
|
DetachAudioMixedProcessor(&AudioMixed.Processor);
|
||||||
|
AudioMixed.Callback = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static string SubText(this string input, int position, int length)
|
public static string SubText(this string input, int position, int length)
|
||||||
{
|
{
|
||||||
return input.Substring(position, Math.Min(length, input.Length));
|
return input.Substring(position, Math.Min(length, input.Length));
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue