mirror of
https://github.com/ahwootech/BRUTAL.git
synced 2026-11-29 06:28:25 +01:00
first
This commit is contained in:
parent
bd62d51ec9
commit
b578433e37
13 changed files with 784842 additions and 0 deletions
2168
Brutal.Sdl.Mixer/Generated/Libraries/SdlMixer.Ergonomic.gen.cs
Normal file
2168
Brutal.Sdl.Mixer/Generated/Libraries/SdlMixer.Ergonomic.gen.cs
Normal file
File diff suppressed because it is too large
Load diff
46
Brutal.Sdl.Mixer/Generated/SdlMixer.Constants.gen.cs
Normal file
46
Brutal.Sdl.Mixer/Generated/SdlMixer.Constants.gen.cs
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
// <auto-generated/>
|
||||
// Generated by Brutal.Sdl.Generate; do not edit by hand.
|
||||
#nullable enable
|
||||
|
||||
namespace Brutal.SdlApi.Mixer
|
||||
{
|
||||
public static unsafe partial class SdlMixer
|
||||
{
|
||||
public static class Constants
|
||||
{
|
||||
public const int DurationInfinite = -2;
|
||||
public const int DurationUnknown = -1;
|
||||
public const string PropAudioDecoderString = "SDL_mixer.audio.decoder";
|
||||
public const string PropAudioLoadCloseioBoolean = "SDL_mixer.audio.load.closeio";
|
||||
public const string PropAudioLoadIgnoreLoopsBoolean = "SDL_mixer.audio.load.ignore_loops";
|
||||
public const string PropAudioLoadIostreamPointer = "SDL_mixer.audio.load.iostream";
|
||||
public const string PropAudioLoadPredecodeBoolean = "SDL_mixer.audio.load.predecode";
|
||||
public const string PropAudioLoadPreferredMixerPointer = "SDL_mixer.audio.load.preferred_mixer";
|
||||
public const string PropAudioLoadSkipMetadataTagsBoolean = "SDL_mixer.audio.load.skip_metadata_tags";
|
||||
public const string PropMetadataAlbumString = "SDL_mixer.metadata.album";
|
||||
public const string PropMetadataArtistString = "SDL_mixer.metadata.artist";
|
||||
public const string PropMetadataCopyrightString = "SDL_mixer.metadata.copyright";
|
||||
public const string PropMetadataDurationFramesNumber = "SDL_mixer.metadata.duration_frames";
|
||||
public const string PropMetadataDurationInfiniteBoolean = "SDL_mixer.metadata.duration_infinite";
|
||||
public const string PropMetadataTitleString = "SDL_mixer.metadata.title";
|
||||
public const string PropMetadataTotalTracksNumber = "SDL_mixer.metadata.total_tracks";
|
||||
public const string PropMetadataTrackNumber = "SDL_mixer.metadata.track";
|
||||
public const string PropMetadataYearNumber = "SDL_mixer.metadata.year";
|
||||
public const string PropMixerDeviceNumber = "SDL_mixer.mixer.device";
|
||||
public const string PropPlayAppendSilenceFramesNumber = "SDL_mixer.play.append_silence_frames";
|
||||
public const string PropPlayAppendSilenceMillisecondsNumber = "SDL_mixer.play.append_silence_milliseconds";
|
||||
public const string PropPlayFadeInFramesNumber = "SDL_mixer.play.fade_in_frames";
|
||||
public const string PropPlayFadeInMillisecondsNumber = "SDL_mixer.play.fade_in_milliseconds";
|
||||
public const string PropPlayFadeInStartGainFloat = "SDL_mixer.play.fade_in_start_gain";
|
||||
public const string PropPlayHaltWhenExhaustedBoolean = "SDL_mixer.play.halt_when_exhausted";
|
||||
public const string PropPlayLoopsNumber = "SDL_mixer.play.loops";
|
||||
public const string PropPlayLoopStartFrameNumber = "SDL_mixer.play.loop_start_frame";
|
||||
public const string PropPlayLoopStartMillisecondNumber = "SDL_mixer.play.loop_start_millisecond";
|
||||
public const string PropPlayMaxFrameNumber = "SDL_mixer.play.max_frame";
|
||||
public const string PropPlayMaxMillisecondsNumber = "SDL_mixer.play.max_milliseconds";
|
||||
public const string PropPlayStartFrameNumber = "SDL_mixer.play.start_frame";
|
||||
public const string PropPlayStartMillisecondNumber = "SDL_mixer.play.start_millisecond";
|
||||
public const string PropPlayStartOrderNumber = "SDL_mixer.play.start_order";
|
||||
}
|
||||
}
|
||||
}
|
||||
36
Brutal.Sdl.Mixer/Generated/SdlMixer.Delegates.gen.cs
Normal file
36
Brutal.Sdl.Mixer/Generated/SdlMixer.Delegates.gen.cs
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
// <auto-generated/>
|
||||
// Generated by Brutal.Sdl.Generate; do not edit by hand.
|
||||
#nullable enable
|
||||
|
||||
namespace Brutal.SdlApi.Mixer
|
||||
{
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
public unsafe delegate void MixTrackStoppedCallback(void* userdata, MixTrack track);
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
public unsafe delegate void MixTrackMixCallback(
|
||||
void* userdata,
|
||||
MixTrack track,
|
||||
SdlAudioSpec* spec,
|
||||
float* pcm,
|
||||
int samples
|
||||
);
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
public unsafe delegate void MixGroupMixCallback(
|
||||
void* userdata,
|
||||
MixGroup group,
|
||||
SdlAudioSpec* spec,
|
||||
float* pcm,
|
||||
int samples
|
||||
);
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
public unsafe delegate void MixPostMixCallback(
|
||||
void* userdata,
|
||||
MixMixer mixer,
|
||||
SdlAudioSpec* spec,
|
||||
float* pcm,
|
||||
int samples
|
||||
);
|
||||
}
|
||||
1471
Brutal.Sdl.Mixer/Generated/SdlMixer.HandleMethods.gen.cs
Normal file
1471
Brutal.Sdl.Mixer/Generated/SdlMixer.HandleMethods.gen.cs
Normal file
File diff suppressed because it is too large
Load diff
98
Brutal.Sdl.Mixer/Generated/SdlMixer.Handles.gen.cs
Normal file
98
Brutal.Sdl.Mixer/Generated/SdlMixer.Handles.gen.cs
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
// <auto-generated/>
|
||||
// Generated by Brutal.Sdl.Generate; do not edit by hand.
|
||||
#nullable enable
|
||||
|
||||
using System;
|
||||
using Brutal.Interop;
|
||||
|
||||
namespace Brutal.SdlApi.Mixer;
|
||||
|
||||
/// <summary>
|
||||
/// A strongly-typed interop handle wrapping the opaque SDL <c>MIX_Audio</c> pointer.
|
||||
/// </summary>
|
||||
[InteropHandle]
|
||||
public readonly unsafe partial struct MixAudio : IDisposable
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public void Dispose()
|
||||
{
|
||||
// A default/zeroed handle owns nothing; forwarding it to the native destructor is at
|
||||
// best a wasted call and at worst undefined behaviour. Guard so Dispose is a safe no-op
|
||||
// on a null handle (and so a double-dispose after the value was cleared is harmless).
|
||||
if (IsNull())
|
||||
return;
|
||||
SdlMixer.PInvoke.DestroyAudio(this);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A strongly-typed interop handle wrapping the opaque SDL <c>MIX_AudioDecoder</c> pointer.
|
||||
/// </summary>
|
||||
[InteropHandle]
|
||||
public readonly unsafe partial struct MixAudioDecoder : IDisposable
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public void Dispose()
|
||||
{
|
||||
// A default/zeroed handle owns nothing; forwarding it to the native destructor is at
|
||||
// best a wasted call and at worst undefined behaviour. Guard so Dispose is a safe no-op
|
||||
// on a null handle (and so a double-dispose after the value was cleared is harmless).
|
||||
if (IsNull())
|
||||
return;
|
||||
SdlMixer.PInvoke.DestroyAudioDecoder(this);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A strongly-typed interop handle wrapping the opaque SDL <c>MIX_Group</c> pointer.
|
||||
/// </summary>
|
||||
[InteropHandle]
|
||||
public readonly unsafe partial struct MixGroup : IDisposable
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public void Dispose()
|
||||
{
|
||||
// A default/zeroed handle owns nothing; forwarding it to the native destructor is at
|
||||
// best a wasted call and at worst undefined behaviour. Guard so Dispose is a safe no-op
|
||||
// on a null handle (and so a double-dispose after the value was cleared is harmless).
|
||||
if (IsNull())
|
||||
return;
|
||||
SdlMixer.PInvoke.DestroyGroup(this);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A strongly-typed interop handle wrapping the opaque SDL <c>MIX_Mixer</c> pointer.
|
||||
/// </summary>
|
||||
[InteropHandle]
|
||||
public readonly unsafe partial struct MixMixer : IDisposable
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public void Dispose()
|
||||
{
|
||||
// A default/zeroed handle owns nothing; forwarding it to the native destructor is at
|
||||
// best a wasted call and at worst undefined behaviour. Guard so Dispose is a safe no-op
|
||||
// on a null handle (and so a double-dispose after the value was cleared is harmless).
|
||||
if (IsNull())
|
||||
return;
|
||||
SdlMixer.PInvoke.DestroyMixer(this);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A strongly-typed interop handle wrapping the opaque SDL <c>MIX_Track</c> pointer.
|
||||
/// </summary>
|
||||
[InteropHandle]
|
||||
public readonly unsafe partial struct MixTrack : IDisposable
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public void Dispose()
|
||||
{
|
||||
// A default/zeroed handle owns nothing; forwarding it to the native destructor is at
|
||||
// best a wasted call and at worst undefined behaviour. Guard so Dispose is a safe no-op
|
||||
// on a null handle (and so a double-dispose after the value was cleared is harmless).
|
||||
if (IsNull())
|
||||
return;
|
||||
SdlMixer.PInvoke.DestroyTrack(this);
|
||||
}
|
||||
}
|
||||
1074
Brutal.Sdl.Mixer/Generated/SdlMixer.PInvoke.gen.cs
Normal file
1074
Brutal.Sdl.Mixer/Generated/SdlMixer.PInvoke.gen.cs
Normal file
File diff suppressed because it is too large
Load diff
21
Brutal.Sdl.Mixer/Generated/SdlMixer.Structs.gen.cs
Normal file
21
Brutal.Sdl.Mixer/Generated/SdlMixer.Structs.gen.cs
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
// <auto-generated/>
|
||||
// Generated by Brutal.Sdl.Generate; do not edit by hand.
|
||||
#nullable enable
|
||||
|
||||
namespace Brutal.SdlApi.Mixer
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public partial struct MixStereoGains
|
||||
{
|
||||
public float left;
|
||||
public float right;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public partial struct MixPoint3D
|
||||
{
|
||||
public float x;
|
||||
public float y;
|
||||
public float z;
|
||||
}
|
||||
}
|
||||
3
Brutal.Sdl.Mixer/GlobalUsings.cs
Normal file
3
Brutal.Sdl.Mixer/GlobalUsings.cs
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
global using System.Runtime.CompilerServices;
|
||||
global using System.Runtime.InteropServices;
|
||||
global using Brutal.SdlApi;
|
||||
|
|
@ -0,0 +1,237 @@
|
|||
THIRD-PARTY LICENSE NOTICES
|
||||
RocketWerkz.Brutal.Sdl.Mixer
|
||||
|
||||
This package redistributes third-party software. The licenses governing that software
|
||||
are reproduced below in full.
|
||||
|
||||
WHAT THIS PACKAGE CONTAINS
|
||||
|
||||
One native library, on every runtime identifier the package supports
|
||||
(win-x64, linux-x64, osx-arm64):
|
||||
|
||||
SDL_mixer 3.2.4 SDL3_mixer.dll / libSDL3_mixer.so / libSDL3_mixer.dylib
|
||||
|
||||
Three decoders maintained by third parties are compiled into that library and are
|
||||
governed by their own licenses, one section each below:
|
||||
|
||||
stb_vorbis Ogg Vorbis decoding
|
||||
dr_flac FLAC decoding
|
||||
dr_mp3 MP3 decoding
|
||||
|
||||
A NOTE ON SCOPE
|
||||
|
||||
This package depends on RocketWerkz.Brutal.Sdl and links against SDL3 at runtime.
|
||||
SDL3 is not contained in this package and is covered by that package's own notices.
|
||||
|
||||
SDL_mixer can optionally be built against libmpg123, libFLAC, libvorbis, libopus,
|
||||
libxmp, libgme, WavPack and FluidSynth. This build enables none of them and
|
||||
substitutes the header-only decoders named above. None of those optional libraries
|
||||
is contained in the shipped library, and none is attributed here.
|
||||
|
||||
==============================================================================
|
||||
SDL_mixer
|
||||
==============================================================================
|
||||
|
||||
Name SDL_mixer
|
||||
Version 3.2.4
|
||||
Upstream https://github.com/libsdl-org/SDL_mixer
|
||||
SPDX Zlib
|
||||
Shipped as SDL3_mixer.dll, libSDL3_mixer.so, libSDL3_mixer.dylib
|
||||
|
||||
Copyright (C) 1997-2026 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
|
||||
==============================================================================
|
||||
stb_vorbis
|
||||
==============================================================================
|
||||
|
||||
Name stb_vorbis
|
||||
Version as vendored by SDL_mixer 3.2.4
|
||||
Upstream https://github.com/nothings/stb
|
||||
SPDX MIT OR Unlicense
|
||||
Shipped as compiled into SDL3_mixer.dll, libSDL3_mixer.so, libSDL3_mixer.dylib
|
||||
|
||||
stb_vorbis is offered under two mutually exclusive licenses, both reproduced below
|
||||
as upstream states them.
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
ALTERNATIVE A - MIT License
|
||||
Copyright (c) 2017 Sean Barrett
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
------------------------------------------------------------------------------
|
||||
ALTERNATIVE B - Public Domain (www.unlicense.org)
|
||||
This is free and unencumbered software released into the public domain.
|
||||
Anyone is free to copy, modify, publish, use, compile, sell, or distribute this
|
||||
software, either in source code form or as a compiled binary, for any purpose,
|
||||
commercial or non-commercial, and by any means.
|
||||
In jurisdictions that recognize copyright laws, the author or authors of this
|
||||
software dedicate any and all copyright interest in the software to the public
|
||||
domain. We make this dedication for the benefit of the public at large and to
|
||||
the detriment of our heirs and successors. We intend this dedication to be an
|
||||
overt act of relinquishment in perpetuity of all present and future rights to
|
||||
this software under copyright law.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
||||
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
==============================================================================
|
||||
dr_flac
|
||||
==============================================================================
|
||||
|
||||
Name dr_flac
|
||||
Version 0.13.4 (as vendored by SDL_mixer 3.2.4)
|
||||
Upstream https://github.com/mackron/dr_libs
|
||||
SPDX Unlicense OR MIT-0
|
||||
Shipped as compiled into SDL3_mixer.dll, libSDL3_mixer.so, libSDL3_mixer.dylib
|
||||
|
||||
This software is available as a choice of the following licenses. Choose
|
||||
whichever you prefer.
|
||||
|
||||
===============================================================================
|
||||
ALTERNATIVE 1 - Public Domain (www.unlicense.org)
|
||||
===============================================================================
|
||||
This is free and unencumbered software released into the public domain.
|
||||
|
||||
Anyone is free to copy, modify, publish, use, compile, sell, or distribute this
|
||||
software, either in source code form or as a compiled binary, for any purpose,
|
||||
commercial or non-commercial, and by any means.
|
||||
|
||||
In jurisdictions that recognize copyright laws, the author or authors of this
|
||||
software dedicate any and all copyright interest in the software to the public
|
||||
domain. We make this dedication for the benefit of the public at large and to
|
||||
the detriment of our heirs and successors. We intend this dedication to be an
|
||||
overt act of relinquishment in perpetuity of all present and future rights to
|
||||
this software under copyright law.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
||||
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
For more information, please refer to <http://unlicense.org/>
|
||||
|
||||
===============================================================================
|
||||
ALTERNATIVE 2 - MIT No Attribution
|
||||
===============================================================================
|
||||
Copyright 2023 David Reid
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
==============================================================================
|
||||
dr_mp3
|
||||
==============================================================================
|
||||
|
||||
Name dr_mp3
|
||||
Version 0.7.4 (as vendored by SDL_mixer 3.2.4)
|
||||
Upstream https://github.com/mackron/dr_libs
|
||||
SPDX Unlicense OR MIT-0
|
||||
Shipped as compiled into SDL3_mixer.dll, libSDL3_mixer.so, libSDL3_mixer.dylib
|
||||
|
||||
dr_mp3's decoding core derives from minimp3 -- "where the real work was done",
|
||||
in dr_mp3's own words. The dr_libs terms come first, then minimp3's dedication,
|
||||
both as dr_mp3 carries them. minimp3 names no copyright holder.
|
||||
|
||||
This software is available as a choice of the following licenses. Choose
|
||||
whichever you prefer.
|
||||
|
||||
===============================================================================
|
||||
ALTERNATIVE 1 - Public Domain (www.unlicense.org)
|
||||
===============================================================================
|
||||
This is free and unencumbered software released into the public domain.
|
||||
|
||||
Anyone is free to copy, modify, publish, use, compile, sell, or distribute this
|
||||
software, either in source code form or as a compiled binary, for any purpose,
|
||||
commercial or non-commercial, and by any means.
|
||||
|
||||
In jurisdictions that recognize copyright laws, the author or authors of this
|
||||
software dedicate any and all copyright interest in the software to the public
|
||||
domain. We make this dedication for the benefit of the public at large and to
|
||||
the detriment of our heirs and successors. We intend this dedication to be an
|
||||
overt act of relinquishment in perpetuity of all present and future rights to
|
||||
this software under copyright law.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
||||
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
For more information, please refer to <http://unlicense.org/>
|
||||
|
||||
===============================================================================
|
||||
ALTERNATIVE 2 - MIT No Attribution
|
||||
===============================================================================
|
||||
Copyright 2023 David Reid
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
minimp3 -- the dedication carried for the code dr_mp3 derives from
|
||||
----------------------------------------------------------------------------
|
||||
|
||||
https://github.com/lieff/minimp3
|
||||
To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide.
|
||||
This software is distributed without any warranty.
|
||||
See <http://creativecommons.org/publicdomain/zero/1.0/>.
|
||||
76
Brutal.Sdl.Mixer/Manual/ExceptionAggregator.cs
Normal file
76
Brutal.Sdl.Mixer/Manual/ExceptionAggregator.cs
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
namespace Brutal.SdlApi.Mixer;
|
||||
|
||||
internal sealed class ExceptionAggregator
|
||||
{
|
||||
public const int MaxRetained = 16;
|
||||
|
||||
private readonly List<Exception> _exceptions = [];
|
||||
private int _dropped;
|
||||
private readonly Lock _lock = new();
|
||||
|
||||
public void Push(string message, Exception? innerException = null)
|
||||
{
|
||||
var wrapped = innerException is null
|
||||
? new SdlCallbackException(message)
|
||||
: new SdlCallbackException(message, innerException);
|
||||
|
||||
// Store before logging so a faulting logger cannot drop the exception.
|
||||
lock (_lock)
|
||||
{
|
||||
if (_exceptions.Count < MaxRetained)
|
||||
_exceptions.Add(wrapped);
|
||||
else
|
||||
_dropped++;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
SdlMixer.TraceLog.Error(wrapped);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// A logging fault must not cross the native boundary.
|
||||
}
|
||||
}
|
||||
|
||||
public void CheckExceptions()
|
||||
{
|
||||
Exception exception;
|
||||
lock (_lock)
|
||||
{
|
||||
if (_exceptions.Count == 0)
|
||||
return;
|
||||
|
||||
var dropped = _dropped;
|
||||
if (_exceptions.Count == 1 && dropped == 0)
|
||||
{
|
||||
exception = _exceptions[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
var message =
|
||||
$"{_exceptions.Count} SDL_mixer callback exception(s) occurred."
|
||||
+ (
|
||||
dropped > 0
|
||||
? $" A further {dropped} were dropped (only the first {MaxRetained} are retained)."
|
||||
: ""
|
||||
);
|
||||
exception = new AggregateException(message, _exceptions.ToArray());
|
||||
}
|
||||
|
||||
_exceptions.Clear();
|
||||
_dropped = 0;
|
||||
}
|
||||
|
||||
throw exception;
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
_exceptions.Clear();
|
||||
_dropped = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
232
Brutal.Sdl.Mixer/Manual/Libraries/SdlMixer.Callbacks.cs
Normal file
232
Brutal.Sdl.Mixer/Manual/Libraries/SdlMixer.Callbacks.cs
Normal file
|
|
@ -0,0 +1,232 @@
|
|||
namespace Brutal.SdlApi.Mixer;
|
||||
|
||||
public delegate void MixTrackStoppedHandler(MixTrack track);
|
||||
|
||||
public delegate void MixTrackMixHandler(MixTrack track, in SdlAudioSpec spec, Span<float> pcm);
|
||||
|
||||
public delegate void MixGroupMixHandler(MixGroup group, in SdlAudioSpec spec, Span<float> pcm);
|
||||
|
||||
public delegate void MixPostMixHandler(MixMixer mixer, in SdlAudioSpec spec, Span<float> pcm);
|
||||
|
||||
public static unsafe partial class SdlMixer
|
||||
{
|
||||
// Which callback slot a registration occupies. SDL_mixer allows one callback of each kind per
|
||||
// object; a track can have all three of TrackStopped / TrackRaw / TrackCooked at once, so the kind
|
||||
// is part of the registry key (setting Raw must not disturb Cooked, and vice versa).
|
||||
private enum CallbackKind
|
||||
{
|
||||
TrackStopped,
|
||||
TrackRaw,
|
||||
TrackCooked,
|
||||
GroupPostMix,
|
||||
PostMix,
|
||||
}
|
||||
|
||||
// Registered callback delegates, keyed by (native object pointer, kind). Each GCHandle roots the
|
||||
// managed delegate for as long as SDL_mixer holds the native trampoline pointer against that
|
||||
// object, and its IntPtr is the userdata SDL threads back to the trampoline so it can dispatch to
|
||||
// the right delegate. Guarded by a lock because SDL_mixer permits (un)registering from any thread,
|
||||
// and the audio thread reads the GCHandle target concurrently. Freed on replace, on clear (setting
|
||||
// a null handler), and wholesale on Quit.
|
||||
private static readonly Dictionary<(nint Object, CallbackKind Kind), GCHandle> Callbacks = new();
|
||||
private static readonly Lock CallbackLock = new();
|
||||
|
||||
// Callers hold CallbackLock and free an old GCHandle only after the native setter returns.
|
||||
|
||||
private static (GCHandle NewHandle, nint Userdata) PrepareCallback(Delegate? callback)
|
||||
{
|
||||
if (callback is null)
|
||||
return (default, 0);
|
||||
|
||||
var handle = GCHandle.Alloc(callback);
|
||||
return (handle, GCHandle.ToIntPtr(handle));
|
||||
}
|
||||
|
||||
private static void CommitCallback((nint, CallbackKind) key, GCHandle newHandle)
|
||||
{
|
||||
if (Callbacks.Remove(key, out var old))
|
||||
old.Free();
|
||||
|
||||
if (newHandle.IsAllocated)
|
||||
Callbacks[key] = newHandle;
|
||||
}
|
||||
|
||||
// The native setter failed and left the old registration in place.
|
||||
private static void RollbackCallback(GCHandle newHandle)
|
||||
{
|
||||
if (newHandle.IsAllocated)
|
||||
newHandle.Free();
|
||||
}
|
||||
|
||||
public static void SetTrackStoppedCallback(MixTrack track, MixTrackStoppedHandler? callback)
|
||||
{
|
||||
ExceptionAggregator.CheckExceptions();
|
||||
var key = (track.Pointer.Value, CallbackKind.TrackStopped);
|
||||
lock (CallbackLock)
|
||||
{
|
||||
var (newHandle, userdata) = PrepareCallback(callback);
|
||||
delegate* unmanaged[Cdecl]<void*, MixTrack, void> fn = callback is null ? null : &TrackStoppedTrampoline;
|
||||
if (PInvoke.SetTrackStoppedCallback(track, fn, (void*)userdata) == 0)
|
||||
{
|
||||
RollbackCallback(newHandle);
|
||||
throw SdlException.FromError("MIX_SetTrackStoppedCallback failed");
|
||||
}
|
||||
CommitCallback(key, newHandle);
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetTrackRawCallback(MixTrack track, MixTrackMixHandler? callback)
|
||||
{
|
||||
ExceptionAggregator.CheckExceptions();
|
||||
var key = (track.Pointer.Value, CallbackKind.TrackRaw);
|
||||
lock (CallbackLock)
|
||||
{
|
||||
var (newHandle, userdata) = PrepareCallback(callback);
|
||||
delegate* unmanaged[Cdecl]<void*, MixTrack, SdlAudioSpec*, float*, int, void> fn = callback is null
|
||||
? null
|
||||
: &TrackMixTrampoline;
|
||||
if (PInvoke.SetTrackRawCallback(track, fn, (void*)userdata) == 0)
|
||||
{
|
||||
RollbackCallback(newHandle);
|
||||
throw SdlException.FromError("MIX_SetTrackRawCallback failed");
|
||||
}
|
||||
CommitCallback(key, newHandle);
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetTrackCookedCallback(MixTrack track, MixTrackMixHandler? callback)
|
||||
{
|
||||
ExceptionAggregator.CheckExceptions();
|
||||
var key = (track.Pointer.Value, CallbackKind.TrackCooked);
|
||||
lock (CallbackLock)
|
||||
{
|
||||
var (newHandle, userdata) = PrepareCallback(callback);
|
||||
delegate* unmanaged[Cdecl]<void*, MixTrack, SdlAudioSpec*, float*, int, void> fn = callback is null
|
||||
? null
|
||||
: &TrackMixTrampoline;
|
||||
if (PInvoke.SetTrackCookedCallback(track, fn, (void*)userdata) == 0)
|
||||
{
|
||||
RollbackCallback(newHandle);
|
||||
throw SdlException.FromError("MIX_SetTrackCookedCallback failed");
|
||||
}
|
||||
CommitCallback(key, newHandle);
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetGroupPostMixCallback(MixGroup group, MixGroupMixHandler? callback)
|
||||
{
|
||||
ExceptionAggregator.CheckExceptions();
|
||||
var key = (group.Pointer.Value, CallbackKind.GroupPostMix);
|
||||
lock (CallbackLock)
|
||||
{
|
||||
var (newHandle, userdata) = PrepareCallback(callback);
|
||||
delegate* unmanaged[Cdecl]<void*, MixGroup, SdlAudioSpec*, float*, int, void> fn = callback is null
|
||||
? null
|
||||
: &GroupMixTrampoline;
|
||||
if (PInvoke.SetGroupPostMixCallback(group, fn, (void*)userdata) == 0)
|
||||
{
|
||||
RollbackCallback(newHandle);
|
||||
throw SdlException.FromError("MIX_SetGroupPostMixCallback failed");
|
||||
}
|
||||
CommitCallback(key, newHandle);
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetPostMixCallback(MixMixer mixer, MixPostMixHandler? callback)
|
||||
{
|
||||
ExceptionAggregator.CheckExceptions();
|
||||
var key = (mixer.Pointer.Value, CallbackKind.PostMix);
|
||||
lock (CallbackLock)
|
||||
{
|
||||
var (newHandle, userdata) = PrepareCallback(callback);
|
||||
delegate* unmanaged[Cdecl]<void*, MixMixer, SdlAudioSpec*, float*, int, void> fn = callback is null
|
||||
? null
|
||||
: &PostMixTrampoline;
|
||||
if (PInvoke.SetPostMixCallback(mixer, fn, (void*)userdata) == 0)
|
||||
{
|
||||
RollbackCallback(newHandle);
|
||||
throw SdlException.FromError("MIX_SetPostMixCallback failed");
|
||||
}
|
||||
CommitCallback(key, newHandle);
|
||||
}
|
||||
}
|
||||
|
||||
// Called by Quit after MIX_Quit, when no trampoline can fire.
|
||||
internal static void ClearCallbacks()
|
||||
{
|
||||
lock (CallbackLock)
|
||||
{
|
||||
foreach (var (_, handle) in Callbacks)
|
||||
handle.Free();
|
||||
Callbacks.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
[UnmanagedCallersOnly(CallConvs = [typeof(CallConvCdecl)])]
|
||||
private static void TrackStoppedTrampoline(void* userdata, MixTrack track)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (GCHandle.FromIntPtr((nint)userdata).Target is MixTrackStoppedHandler handler)
|
||||
handler(track);
|
||||
else
|
||||
ExceptionAggregator.Push(DeadHandleMessage("track-stopped"));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ExceptionAggregator.Push("An exception occurred in an SDL_mixer track-stopped callback.", ex);
|
||||
}
|
||||
}
|
||||
|
||||
[UnmanagedCallersOnly(CallConvs = [typeof(CallConvCdecl)])]
|
||||
private static void TrackMixTrampoline(void* userdata, MixTrack track, SdlAudioSpec* spec, float* pcm, int samples)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (GCHandle.FromIntPtr((nint)userdata).Target is MixTrackMixHandler handler)
|
||||
handler(track, in *spec, new Span<float>(pcm, samples));
|
||||
else
|
||||
ExceptionAggregator.Push(DeadHandleMessage("track mix"));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ExceptionAggregator.Push("An exception occurred in an SDL_mixer track mix callback.", ex);
|
||||
}
|
||||
}
|
||||
|
||||
[UnmanagedCallersOnly(CallConvs = [typeof(CallConvCdecl)])]
|
||||
private static void GroupMixTrampoline(void* userdata, MixGroup group, SdlAudioSpec* spec, float* pcm, int samples)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (GCHandle.FromIntPtr((nint)userdata).Target is MixGroupMixHandler handler)
|
||||
handler(group, in *spec, new Span<float>(pcm, samples));
|
||||
else
|
||||
ExceptionAggregator.Push(DeadHandleMessage("group post-mix"));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ExceptionAggregator.Push("An exception occurred in an SDL_mixer group post-mix callback.", ex);
|
||||
}
|
||||
}
|
||||
|
||||
[UnmanagedCallersOnly(CallConvs = [typeof(CallConvCdecl)])]
|
||||
private static void PostMixTrampoline(void* userdata, MixMixer mixer, SdlAudioSpec* spec, float* pcm, int samples)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (GCHandle.FromIntPtr((nint)userdata).Target is MixPostMixHandler handler)
|
||||
handler(mixer, in *spec, new Span<float>(pcm, samples));
|
||||
else
|
||||
ExceptionAggregator.Push(DeadHandleMessage("post-mix"));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ExceptionAggregator.Push("An exception occurred in an SDL_mixer post-mix callback.", ex);
|
||||
}
|
||||
}
|
||||
|
||||
private static string DeadHandleMessage(string family) =>
|
||||
$"An SDL_mixer {family} callback fired with a dead or foreign GCHandle (its target was not the "
|
||||
+ "expected handler); the callback was skipped.";
|
||||
}
|
||||
12
Brutal.Sdl.Mixer/Manual/Libraries/SdlMixer.Init.cs
Normal file
12
Brutal.Sdl.Mixer/Manual/Libraries/SdlMixer.Init.cs
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
namespace Brutal.SdlApi.Mixer;
|
||||
|
||||
public static unsafe partial class SdlMixer
|
||||
{
|
||||
public static void Quit()
|
||||
{
|
||||
// Free the callback GCHandles only after MIX_Quit returns; the audio thread uses them until then.
|
||||
PInvoke.Quit();
|
||||
ClearCallbacks();
|
||||
ExceptionAggregator.Clear();
|
||||
}
|
||||
}
|
||||
114
Brutal.Sdl.Mixer/SdlMixer.cs
Normal file
114
Brutal.Sdl.Mixer/SdlMixer.cs
Normal file
|
|
@ -0,0 +1,114 @@
|
|||
using System.Reflection;
|
||||
using Brutal.Logging;
|
||||
|
||||
namespace Brutal.SdlApi.Mixer;
|
||||
|
||||
/// <summary>
|
||||
/// Provides access to the SDL_mixer library.
|
||||
/// </summary>
|
||||
public static unsafe partial class SdlMixer
|
||||
{
|
||||
/// <summary>
|
||||
/// The name the generated P/Invoke surface imports against. The <see cref="PInvoke"/> static
|
||||
/// constructor registers a <see cref="NativeLibrary.SetDllImportResolver"/> that normalizes
|
||||
/// this name to the platform-specific SDL3_mixer shared library.
|
||||
/// </summary>
|
||||
internal const string Dll = "SDL3_mixer";
|
||||
|
||||
/// <summary>
|
||||
/// The logging category for the per-call trace logs the generated P/Invoke surface emits. An
|
||||
/// internal implementation detail mirroring core's <c>Sdl.TraceLog</c>; the generated
|
||||
/// <c>SdlMixer.PInvoke</c> wrappers call <c>SdlMixer.TraceLog.Trace()</c> on every invocation.
|
||||
/// </summary>
|
||||
internal static readonly LogCategory TraceLog = LogCategory.Make("SdlMixer");
|
||||
|
||||
/// <summary>
|
||||
/// Captures exceptions thrown inside SDL_mixer callbacks, which run on the audio thread, so they
|
||||
/// can be rethrown from managed code. Drained by every ergonomic mixer/track/group method and by
|
||||
/// <see cref="ThrowPendingCallbackExceptions"/>.
|
||||
/// </summary>
|
||||
internal static readonly ExceptionAggregator ExceptionAggregator = new();
|
||||
|
||||
/// <summary>
|
||||
/// Rethrows any exception captured inside an SDL_mixer callback since the last drain, then clears
|
||||
/// the pending set. Callbacks fire on SDL_mixer's audio thread(s), where a managed exception cannot
|
||||
/// legally unwind; each is caught, logged, and parked on the shared aggregator instead. Every
|
||||
/// ergonomic method that touches a mixer, track or group drains automatically, but during long
|
||||
/// device-driven playback that makes no such calls, invoke this periodically (e.g. once per frame)
|
||||
/// to surface a failing callback promptly.
|
||||
/// </summary>
|
||||
/// <exception cref="SdlCallbackException">Exactly one callback exception was pending.</exception>
|
||||
/// <exception cref="AggregateException">More than one callback exception was pending, or some were dropped.</exception>
|
||||
public static void ThrowPendingCallbackExceptions() => ExceptionAggregator.CheckExceptions();
|
||||
|
||||
/// <summary>
|
||||
/// Hosts the raw generated P/Invoke surface and the native library resolver for <c>SDL3_mixer</c>.
|
||||
/// </summary>
|
||||
public static unsafe partial class PInvoke
|
||||
{
|
||||
// The native SDL3_mixer handle, resolved lazily by the DllImportResolver below and cached
|
||||
// so the library is loaded at most once regardless of how many entry points are resolved.
|
||||
private static nint _nativeHandle;
|
||||
|
||||
private static readonly Lock ResolveLock = new();
|
||||
|
||||
static PInvoke()
|
||||
{
|
||||
// Load libSDL3 before SDL3_mixer, which links against it; only a real P/Invoke triggers Sdl's resolver.
|
||||
_ = Sdl.PInvoke.GetVersion();
|
||||
|
||||
NativeLibrary.SetDllImportResolver(typeof(SdlMixer).Assembly, Resolve);
|
||||
}
|
||||
|
||||
// Normalizes the "SDL3_mixer" import name to the platform-specific shared library filename
|
||||
// (SDL3_mixer.dll on Windows, libSDL3_mixer.dylib on macOS, libSDL3_mixer.so.0 on Linux).
|
||||
// SDL_mixer's Linux build installs a versioned soname (libSDL3_mixer.so.0), same convention
|
||||
// as core's SDL3, so the candidate list is spelled out explicitly, most-specific first, with
|
||||
// the default probing convention name as a fallback.
|
||||
private static nint Resolve(string libraryName, Assembly assembly, DllImportSearchPath? searchPath)
|
||||
{
|
||||
// Only ever asked to resolve SDL3_mixer; anything else is left to the default resolver.
|
||||
if (libraryName != Dll)
|
||||
return IntPtr.Zero;
|
||||
|
||||
lock (ResolveLock)
|
||||
{
|
||||
if (_nativeHandle != IntPtr.Zero)
|
||||
return _nativeHandle;
|
||||
|
||||
var search = searchPath ?? DllImportSearchPath.AssemblyDirectory;
|
||||
|
||||
// Load (not TryLoad) so each candidate's OS error text reaches the final exception.
|
||||
var failures = new List<string>();
|
||||
foreach (var candidate in Candidates())
|
||||
{
|
||||
try
|
||||
{
|
||||
_nativeHandle = NativeLibrary.Load(candidate, assembly, search);
|
||||
return _nativeHandle;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
failures.Add($"'{candidate}': {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
throw new DllNotFoundException(
|
||||
"Could not load the SDL3_mixer native library. Attempts (most specific first): "
|
||||
+ string.Join("; ", failures)
|
||||
+ "."
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private static string[] Candidates()
|
||||
{
|
||||
if (OperatingSystem.IsWindows())
|
||||
return ["SDL3_mixer.dll", "SDL3_mixer"];
|
||||
if (OperatingSystem.IsMacOS())
|
||||
return ["libSDL3_mixer.dylib", "SDL3_mixer"];
|
||||
// Linux and other Unix-likes.
|
||||
return ["libSDL3_mixer.so.0", "libSDL3_mixer.so", "SDL3_mixer"];
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue