diff --git a/src/unknown_064830.c b/src/unknown_064830.c index 347a2aa3..e007ea42 100644 --- a/src/unknown_064830.c +++ b/src/unknown_064830.c @@ -31,8 +31,52 @@ s32 alFxParam(void* filter, s32 paramID, void* param) { GLOBAL_ASM("asm/non_matchings/unknown_064830/alFxParamHdl.s") GLOBAL_ASM("asm/non_matchings/unknown_064830/_loadOutputBuffer.s") GLOBAL_ASM("asm/non_matchings/unknown_064830/_loadBuffer.s") -GLOBAL_ASM("asm/non_matchings/unknown_064830/_saveBuffer.s") -//GLOBAL_ASM("asm/non_matchings/unknown_064830/_filterBuffer.s") +//GLOBAL_ASM("asm/non_matchings/unknown_064830/_saveBuffer.s") + +/* + * This routine is for writing data to the delay line buff. If the + * address of curr_ptr < r->base, it will force it to be within r->base + * space. If the write goes past the end of r->base, it will wrap around + * Cause count bytes of data at buff to be written to delay line, curr_ptr. + */ +Acmd *_saveBuffer(ALFx *r, s16 *curr_ptr, s32 buff, s32 count, Acmd *p) +{ + Acmd *ptr = p; + s32 after_end, before_end; + s16 *updated_ptr, *delay_end; + +#ifdef AUD_PROFILE + lastCnt[++cnt_index] = osGetCount(); +#endif + + delay_end = &r->base[r->length]; + if (curr_ptr < r->base) /* probably just security */ + curr_ptr += r->length; /* shouldn't occur */ + updated_ptr = curr_ptr + count; + + if (updated_ptr > delay_end) { /* if the data wraps past end of r->base */ + after_end = updated_ptr - delay_end; + before_end = delay_end - curr_ptr; + + aSetBuffer(ptr++, 0, 0, buff, before_end<<1); + aSaveBuffer(ptr++, osVirtualToPhysical(curr_ptr)); + aSetBuffer(ptr++, 0, 0, buff+(before_end<<1), after_end<<1); + aSaveBuffer(ptr++, osVirtualToPhysical(r->base)); + aSetBuffer(ptr++, 0, 0, 0, count<<1); + } else { + aSetBuffer(ptr++, 0, 0, buff, count<<1); + aSaveBuffer(ptr++, osVirtualToPhysical(curr_ptr)); + } + +#ifdef AUD_PROFILE + PROFILE_AUD(save_num, save_cnt, save_max, save_min); +#endif + return ptr; + +} + + + Acmd *_filterBuffer(ALLowPass *lp, s32 buff, s32 count, Acmd *p) { Acmd *ptr = p;