upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/runtime/xma_decoder
diff options
context:
space:
mode:
authorandretuta <andreviniciusmerlia@gmail.com>2026-11-24 05:27:55 -0300
committerandretuta <andreviniciusmerlia@gmail.com>2026-11-24 05:27:55 -0300
commit0fe9c0bdfb844678209c0d0ffdd37d2533d1f57e (patch)
tree143420e46b24ebd381998ea651aa4a0a8b20d001 /runtime/xma_decoder
parente02ec36bf315de960a9db244e971bf00cfd66406 (diff)
acphal: recover SHAPE allocation and preserve XMA stream state
Diffstat (limited to 'runtime/xma_decoder')
-rw-r--r--runtime/xma_decoder/README.md1
-rw-r--r--runtime/xma_decoder/src/lib.rs7
-rw-r--r--runtime/xma_decoder/tests/ffi_contract.rs22
3 files changed, 27 insertions, 3 deletions
diff --git a/runtime/xma_decoder/README.md b/runtime/xma_decoder/README.md
index 44eb4288a..9db801810 100644
--- a/runtime/xma_decoder/README.md
+++ b/runtime/xma_decoder/README.md
@@ -23,3 +23,4 @@ The C++ smoke test is run by the xma2-decoder workflow with MSVC. It links ws2_3
23`runtime/shims/acphal.cpp` uses `leonida_xma2_decoder_create_hardware` and decodes whole 2048-byte packets, so loop points are rounded to packets. The shim creates a fresh decoder after a loop rewind or a decoder error. 23`runtime/shims/acphal.cpp` uses `leonida_xma2_decoder_create_hardware` and decodes whole 2048-byte packets, so loop points are rounded to packets. The shim creates a fresh decoder after a loop rewind or a decoder error.
24 24
25Without `cargo`, when that build fails, or with the cl.exe fallback of `scripts/build_runtime.ps1`, XMA voices output silence. 25Without `cargo`, when that build fails, or with the cl.exe fallback of `scripts/build_runtime.ps1`, XMA voices output silence.
26Use `-DLEONIDA_REQUIRE_XMA2_DECODER=ON` to require the decoder in a CMake build, as the Windows runtime CI does.
diff --git a/runtime/xma_decoder/src/lib.rs b/runtime/xma_decoder/src/lib.rs
index cda2721fb..69fedf49e 100644
--- a/runtime/xma_decoder/src/lib.rs
+++ b/runtime/xma_decoder/src/lib.rs
@@ -109,7 +109,8 @@ unsafe fn create_with<E>(
109/// Decodes a buffer containing one or more complete 2048-byte XMA2 packets. 109/// Decodes a buffer containing one or more complete 2048-byte XMA2 packets.
110/// 110///
111/// # Safety 111/// # Safety
112/// `decoder` must be a live handle returned by `leonida_xma2_decoder_create`. 112/// `decoder` must be a live handle returned by `leonida_xma2_decoder_create`
113/// or `leonida_xma2_decoder_create_hardware`.
113/// `input` must reference `input_len` readable bytes and `out_block` must be writable. 114/// `input` must reference `input_len` readable bytes and `out_block` must be writable.
114/// Do not destroy a decoder concurrently with this call. The returned PCM block remains valid 115/// Do not destroy a decoder concurrently with this call. The returned PCM block remains valid
115/// until `leonida_xma2_pcm_destroy` is called. 116/// until `leonida_xma2_pcm_destroy` is called.
@@ -182,8 +183,8 @@ pub unsafe extern "C" fn leonida_xma2_decode_buffer(
182/// Destroys a decoder. Passing null is a no-op. 183/// Destroys a decoder. Passing null is a no-op.
183/// 184///
184/// # Safety 185/// # Safety
185/// A non-null pointer must be a live handle returned by `leonida_xma2_decoder_create`, 186/// A non-null pointer must be a live handle returned by `leonida_xma2_decoder_create`
186/// and no calls may be using it concurrently. 187/// or `leonida_xma2_decoder_create_hardware`. No calls may be using it concurrently.
187#[no_mangle] 188#[no_mangle]
188pub unsafe extern "C" fn leonida_xma2_decoder_destroy(decoder: *mut LeonidaXma2Decoder) { 189pub unsafe extern "C" fn leonida_xma2_decoder_destroy(decoder: *mut LeonidaXma2Decoder) {
189 if !decoder.is_null() { 190 if !decoder.is_null() {
diff --git a/runtime/xma_decoder/tests/ffi_contract.rs b/runtime/xma_decoder/tests/ffi_contract.rs
index 0eb8e5cf4..6e6185c39 100644
--- a/runtime/xma_decoder/tests/ffi_contract.rs
+++ b/runtime/xma_decoder/tests/ffi_contract.rs
@@ -52,6 +52,28 @@ fn make_decoder(rate: u32, channels: u32) -> *mut LeonidaXma2Decoder {
52} 52}
53 53
54#[test] 54#[test]
55fn hardware_mode_keeps_all_samples_of_the_first_stereo_frame() {
56 let mut packet = synthetic_silent_packet(2);
57 packet[..4].copy_from_slice(&[4, 0, 1, 0]); // One frame, no continuation from a previous packet.
58 let mut decoder = ptr::null_mut();
59 let mut block = ptr::null_mut();
60 unsafe {
61 assert_eq!(
62 leonida_xma2_decoder_create_hardware(48_000, 2, &mut decoder),
63 LEONIDA_XMA2_OK
64 );
65 assert_eq!(
66 leonida_xma2_decode_buffer(decoder, packet.as_ptr(), packet.len(), &mut block),
67 LEONIDA_XMA2_OK
68 );
69 let count = leonida_xma2_pcm_sample_count(block);
70 leonida_xma2_pcm_destroy(block);
71 leonida_xma2_decoder_destroy(decoder);
72 assert_eq!(count, 512 * 2);
73 }
74}
75
76#[test]
55fn creation_rejects_invalid_outputs_and_formats() { 77fn creation_rejects_invalid_outputs_and_formats() {
56 assert_eq!( 78 assert_eq!(
57 unsafe { leonida_xma2_decoder_create(48_000, 2, ptr::null_mut()) }, 79 unsafe { leonida_xma2_decoder_create(48_000, 2, ptr::null_mut()) },