Skip to content

Commit

Permalink
wav64: unbreak VADPCM stereo
Browse files Browse the repository at this point in the history
  • Loading branch information
rasky committed Nov 3, 2024
1 parent d8c7321 commit 5295016
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
14 changes: 10 additions & 4 deletions src/audio/rsp_mixer.S
Original file line number Diff line number Diff line change
Expand Up @@ -1188,9 +1188,13 @@ Mix8Loop:

.section .bssovl1

# Codebook must be aligned to allow for xor trick
# to switch channels
.balign VADPCM_CODEBOOK_SIZE*16
VADPCM_CODEBOOK: .space VADPCM_CODEBOOK_SIZE*16*2

.align 4
VADPCM_STATE: .space 16*2 # state, left/right
VADPCM_CODEBOOK: .space VADPCM_CODEBOOK_SIZE*16*2
VADPCM_BUFFER: .space MAX_VADPCM_FRAMES*16*2
VADPCM_BUFFER_END: .space 8 # Extra 8 bytes for misalignment

Expand Down Expand Up @@ -1267,9 +1271,11 @@ VADPCM_Decompress:
ltv pred1a.e0, 0,s0

srl nframes, a1, 24
addiu nframes, 1
bgez a2, 1f
addiu nframes, 1
sll nframes, 1

# Calculate offset of input buffer inside the output buffer
1: # Calculate offset of input buffer inside the output buffer
li dmem_output, %lo(VADPCM_BUFFER)
and rdram_input, 0x00FFFFFF
and a1, 0x00FFFFFF
Expand Down Expand Up @@ -1383,6 +1389,7 @@ VADPCM_DecompressMono:
sqv vstate1, 0x10,dmem_output
srv vstate1, 0x20,dmem_output

addiu nframes, -1
addiu dmem_input, 9
bgez a2, VADPCM_Output
addiu dmem_output, 32
Expand Down Expand Up @@ -1430,7 +1437,6 @@ VADPCM_InterleaveStereo:

# Write output into RDRAM (async)
VADPCM_Output:
addiu nframes, -1
bgtz nframes, VADPCM_DecompressLoop
nop

Expand Down
3 changes: 2 additions & 1 deletion src/audio/wav64.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,8 @@ static void waveform_vadpcm_read(void *ctx, samplebuffer_t *sbuf, int wpos, int
bool highpri = false;
while (wlen > 0) {
// Calculate number of frames to decompress in this iteration
int nframes = MIN(wlen / 16, MAX_VADPCM_FRAMES);
int max_vadpcm_frames = (wav->wave.channels == 1) ? MAX_VADPCM_FRAMES : MAX_VADPCM_FRAMES / 2;
int nframes = MIN(wlen / 16, max_vadpcm_frames);

// Acquire destination buffer from the sample buffer
int16_t *dest = (int16_t*)samplebuffer_append(sbuf, nframes*16);
Expand Down

0 comments on commit 5295016

Please sign in to comment.