From 0277b66f744f3e8440f8650f0e2cd0b6e6de9ef0 Mon Sep 17 00:00:00 2001 From: izzy2lost Date: Mon, 2 Mar 2026 12:06:59 -0500 Subject: [PATCH] fix audio in jsrf and some other games --- hw/xbox/mcpx/apu/vp/vp.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/hw/xbox/mcpx/apu/vp/vp.c b/hw/xbox/mcpx/apu/vp/vp.c index 591f729175..35d1219ac7 100644 --- a/hw/xbox/mcpx/apu/vp/vp.c +++ b/hw/xbox/mcpx/apu/vp/vp.c @@ -1030,6 +1030,22 @@ static int voice_get_samples(MCPXAPUState *d, uint32_t v, float samples[][2], linear_addr += 4; } } + /* WAR: Deactivate voice if ADPCM header values are non-zero + * and identical. Something overwrites voice memory region + * before NV1BA0_PIO_VOICE_OFF is set. Mitigates loud + * crackling produced by decoding/playing such data. + */ + uint8_t *adpcm_hdr = (uint8_t *)adpcm_block; + if (adpcm_hdr[0] != 0) { + uint32_t diff = 0; + for (uint8_t i = 1; i < 8; i++) { + diff |= adpcm_hdr[i] ^ adpcm_hdr[0]; + } + if (diff == 0) { + voice_off(d, v); + return -1; + } + } adpcm_decode_block(adpcm_decoded, (uint8_t *)adpcm_block, block_size, channels); adpcm_block_index = block_index;