mirror of
https://github.com/stride3d/stride.git
synced 2026-10-12 02:23:23 +00:00
Stride.Audio: enable Celt decode on macOS by stubbing variadic opus_custom_decoder_ctl GET_LOOKAHEAD
This commit is contained in:
Vendored
+7
@@ -17,6 +17,8 @@ fi
|
||||
cd "$EXTERNALS_DIR"
|
||||
|
||||
CELT_SOURCES="celt/bands.c celt/celt.c celt/celt_decoder.c celt/celt_encoder.c celt/celt_lpc.c celt/cwrs.c celt/entcode.c celt/entdec.c celt/entenc.c celt/kiss_fft.c celt/laplace.c celt/mathops.c celt/mdct.c celt/modes.c celt/pitch.c celt/quant_bands.c celt/rate.c celt/vq.c"
|
||||
# Stride-specific helpers compiled in alongside the upstream sources (see celt_extras.c).
|
||||
CELT_EXTRAS="$CELT_DIR/celt_extras.c"
|
||||
CFLAGS="-O2 -fPIC -DUSE_ALLOCA -DHAVE_LRINTF -DCUSTOM_MODES -DOPUS_BUILD -Iinclude -Icelt"
|
||||
|
||||
# Compile + archive Celt for one RID. Each (target, sdk) pair encodes the
|
||||
@@ -36,6 +38,11 @@ build_rid() {
|
||||
bn=$(basename "$src" .c)
|
||||
clang -target "$target" -isysroot "$sdk_path" $CFLAGS -c -o "build/$rid/${bn}.o" "$src"
|
||||
done
|
||||
for src in $CELT_EXTRAS; do
|
||||
local bn
|
||||
bn=$(basename "$src" .c)
|
||||
clang -target "$target" -isysroot "$sdk_path" $CFLAGS -c -o "build/$rid/${bn}.o" "$src"
|
||||
done
|
||||
ar rcs "build/$rid/libCelt.a" build/$rid/*.o
|
||||
|
||||
local out_dir="$STRIDE_ROOT/deps/NativePath/dotnet/$rid"
|
||||
|
||||
Vendored
+18
@@ -0,0 +1,18 @@
|
||||
// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net)
|
||||
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
|
||||
//
|
||||
// Stride-specific helpers compiled into libCelt.a alongside the upstream Opus/Celt sources.
|
||||
// Each function here is a non-variadic wrapper around a variadic opus_custom_decoder_ctl call,
|
||||
// so .NET DllImport can invoke them from C# (Mono on Apple does not support __arglist for
|
||||
// DllImport, and the Apple ARM64 variadic ABI passes overflow args on the stack — a plain
|
||||
// non-variadic DllImport would route them through registers and corrupt memory).
|
||||
|
||||
#include <stdint.h>
|
||||
#include "opus_custom.h"
|
||||
|
||||
// Returns the decoder's lookahead (encoder-delay) sample count via *out_delay.
|
||||
// OPUS_GET_LOOKAHEAD's macro arg is itself the int* (it pipes through opus_check_int_ptr).
|
||||
int stride_celt_get_lookahead(OpusCustomDecoder *decoder, int32_t *out_delay)
|
||||
{
|
||||
return opus_custom_decoder_ctl(decoder, OPUS_GET_LOOKAHEAD(out_delay));
|
||||
}
|
||||
+2
-2
@@ -1,3 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:fe1a8f66a373c2a0571325000ed8727ddc45ab1f94848c07257a88f7c422613c
|
||||
size 165768
|
||||
oid sha256:80ead625c1ea1b3b6aef6b2117153963347f0c6c00e4211215724f08aa71f238
|
||||
size 166496
|
||||
|
||||
+2
-2
@@ -1,3 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:a462411e356672170267356d80cd236879062a3436c25fbab81bd3d9bd2a72a6
|
||||
size 169664
|
||||
oid sha256:31084e4ca9220a8617ed72dfe09e1dfd8048661bf816f8a1c879d0bd96c26405
|
||||
size 170392
|
||||
|
||||
+2
-2
@@ -1,3 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:c538d24021f2ea5c098b0aac44f2dcb78a197e277903f17bc2bf0acba02a9b8d
|
||||
size 182776
|
||||
oid sha256:2809135fdd870d3c42c66847cbec9f52356a4fddf6bbd464223fdb69aff8118c
|
||||
size 173176
|
||||
|
||||
@@ -38,12 +38,6 @@ namespace Stride.Audio
|
||||
|
||||
public Celt(int sampleRate, int bufferSize, int channels, bool decoderOnly)
|
||||
{
|
||||
#if STRIDE_PLATFORM_MACOS
|
||||
// Decode crashes inside libCelt.a's decode_pulses on osx-arm64 after a handful of
|
||||
// packets — investigation pending. Bail cleanly so Sound loading raises a managed
|
||||
// exception instead of taking down the whole process.
|
||||
throw new NotSupportedException("Celt decoder not yet supported on macOS (osx-arm64 libCelt.a needs investigation).");
|
||||
#else
|
||||
SampleRate = sampleRate;
|
||||
BufferSize = bufferSize;
|
||||
Channels = channels;
|
||||
@@ -62,7 +56,6 @@ namespace Stride.Audio
|
||||
if (encoder == IntPtr.Zero)
|
||||
throw new Exception("Failed to create Celt encoder.");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
@@ -125,8 +118,13 @@ namespace Stride.Audio
|
||||
|
||||
public unsafe int GetDecoderSampleDelay()
|
||||
{
|
||||
// opus_custom_decoder_ctl is C-variadic and Mono on Apple rejects __arglist in
|
||||
// DllImport ("Vararg calling convention not supported"). stride_celt_get_lookahead
|
||||
// is a tiny non-variadic shim in libCelt.a (built from deps/Celt/celt_extras.c).
|
||||
// Re-evaluate this shim once Apple platforms move to CoreCLR — at that point a
|
||||
// pure-managed __arglist call should work and the shim can be retired.
|
||||
int delay = 0;
|
||||
int err = opus_custom_decoder_ctl_get_int(decoder, OPUS_GET_LOOKAHEAD_REQUEST, &delay);
|
||||
int err = stride_celt_get_lookahead(decoder, &delay);
|
||||
return err == 0 ? delay : 0;
|
||||
}
|
||||
|
||||
@@ -149,11 +147,14 @@ namespace Stride.Audio
|
||||
[SuppressUnmanagedCodeSecurity, DllImport(LibCelt, CallingConvention = CallingConvention.Cdecl)]
|
||||
private static extern unsafe int opus_custom_decode_float(IntPtr decoder, byte* data, int len, float* pcm, int frameSize);
|
||||
|
||||
// opus_custom_decoder_ctl is variadic. Calling it with no variadic args (RESET_STATE) is
|
||||
// safe under any ABI — nothing for va_arg to read. For requests that need an out-pointer
|
||||
// we go through stride_celt_get_lookahead (see celt_extras.c).
|
||||
[SuppressUnmanagedCodeSecurity, DllImport(LibCelt, EntryPoint = "opus_custom_decoder_ctl", CallingConvention = CallingConvention.Cdecl)]
|
||||
private static extern int opus_custom_decoder_ctl_reset(IntPtr decoder, int request);
|
||||
|
||||
[SuppressUnmanagedCodeSecurity, DllImport(LibCelt, EntryPoint = "opus_custom_decoder_ctl", CallingConvention = CallingConvention.Cdecl)]
|
||||
private static extern unsafe int opus_custom_decoder_ctl_get_int(IntPtr decoder, int request, int* value);
|
||||
[SuppressUnmanagedCodeSecurity, DllImport(LibCelt, CallingConvention = CallingConvention.Cdecl)]
|
||||
private static extern unsafe int stride_celt_get_lookahead(IntPtr decoder, int* outDelay);
|
||||
|
||||
[SuppressUnmanagedCodeSecurity, DllImport(LibCelt, CallingConvention = CallingConvention.Cdecl)]
|
||||
private static extern IntPtr opus_custom_encoder_create(IntPtr mode, int channels, IntPtr error);
|
||||
|
||||
Reference in New Issue
Block a user