Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
void ZSortBOSS_Audio2( u32 _w0, u32 _w1 )
{
int len = _w1 >> 24;
u16 *mem16 = (u16*)DMEM;
// Destination address (in 16bit sample unit)
u32 dst = (((u32*)DMEM)[0x10>>2] >> 1) ^ 1;
/* Fixed point 8.16 */
u32 fp0 = _w0 & 0xfffff;
u32 fp1 = _w1 & 0xfffff;
// Written by previous ZSortBOSS_MoveWord
u32 volume_addr = 0x904>>1;
u16 volume[2] = {
mem16[volume_addr + 1],
mem16[volume_addr],
};
for(int i = 0; i < len; i += 4) {
for(int j = 0; j < 4; j++) {
u64 val = i * fp0 + j * fp0 + fp1;
u32 fract = val & 0xffff;
u32 index = val >> 16;
s16 sample0 = mem16[((0x18 + index))^1];
s16 sample1 = mem16[((0x19 + index))^1];
s16 diff = sample0 - sample1;
s16 target_sample = mem16[dst];
for(int k = 0; k < 2; k++, dst += 2) {
s32 interpolated_diff = (diff * fract) >> 16;
s16 interpolated_sample = sample0 + interpolated_diff;
s32 mixed_sample = (volume[k] * interpolated_sample) >> 16;
s16 out_sample = target_sample + mixed_sample;
mem16[dst] = out_sample;
}
}
}
LOG(LOG_VERBOSE, "ZSortBOSS_Audio2 (0x%08x, 0x%08x)\n", _w0, _w1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment