Audio: reduce the title's XMA read advance before adding it
ADVANCE_XMA_READ added the title's block count to the 5-bit read block in u32 before taking it modulo the ring size, so a count near u32::MAX overflowed (a panic in debug builds). The count is reduced modulo the ring first; the result is the same for every count that did not overflow. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
97c78d1087
commit
257d8bbab2
1 file changed
+9
-1
@@ -471,7 +471,8 @@ impl Xma {
|
||||
// The decoder writes the same words.
|
||||
let mut slot = lock(&self.voices[index as usize]);
|
||||
let size = context.field(0, 22, 5).max(1);
|
||||
let read = (context.field(9, 0, 5) + blocks) % size;
|
||||
// The count is the title's: reduced first, so the sum stays small.
|
||||
let read = (context.field(9, 0, 5) + blocks % size) % size;
|
||||
context.set_field(9, 0, 5, read);
|
||||
if blocks > 0 {
|
||||
context.set_field(1, 31, 1, 1);
|
||||
@@ -1062,6 +1063,13 @@ mod tests {
|
||||
assert_eq!(context.field(0, 20, 2), 0, "input used up");
|
||||
assert_eq!(context.field(2, 26, 5), INPUT_INVALID);
|
||||
|
||||
// A count near `u32::MAX` wraps the read block like any other
|
||||
// (3 + 0xffff_ffff blocks on a ring of four is block 2); the sum
|
||||
// used to overflow.
|
||||
context.set_field(9, 0, 5, 3);
|
||||
submit(ADVANCE_XMA_READ, &[1, u32::MAX]);
|
||||
assert_eq!(context.field(9, 0, 5), 2);
|
||||
|
||||
submit(DISABLE_XMA, &[1]);
|
||||
assert_eq!(produced(&xma()), None);
|
||||
(m.release)(acp);
|
||||
|
||||
Reference in new issue
Block a user