From d570cf346da2ac8cc57dbdd4b7ca6efa452baa41 Mon Sep 17 00:00:00 2001 From: Christopher Snowhill Date: Sat, 5 Mar 2022 20:43:41 -0800 Subject: [PATCH] Highly Complete / USF: Preliminary overload HLE Include preliminary overload effect for MP3 and CBFD HLE operations, based on a pull request from upstream. This should make the HLE pretty much sound for general use once again. Signed-off-by: Christopher Snowhill --- Frameworks/lazyusf2/lazyusf2/rsp_hle/alist.c | 14 ++++++++++++++ Frameworks/lazyusf2/lazyusf2/rsp_hle/alist.h | 7 +++++++ .../lazyusf2/lazyusf2/rsp_hle/alist_naudio.c | 19 +++++++++++++++---- 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/Frameworks/lazyusf2/lazyusf2/rsp_hle/alist.c b/Frameworks/lazyusf2/lazyusf2/rsp_hle/alist.c index e509b3755..d00078905 100644 --- a/Frameworks/lazyusf2/lazyusf2/rsp_hle/alist.c +++ b/Frameworks/lazyusf2/lazyusf2/rsp_hle/alist.c @@ -1031,3 +1031,17 @@ void alist_iirf( dram_store_u16(hle, (uint16_t*)&ibuf[(index-1)&3], address+10, 1); } +/* Perform a clamped gain, then attenuate it back by an amount */ +void alist_overload(struct hle_t* hle, uint16_t dmem, int16_t count, int16_t gain, int16_t attenuation) +{ + int16_t accu; + int16_t * sample = (int16_t*)(hle->alist_buffer + dmem); + + while (count != 0) + { + accu = clamp_s16(*sample * gain); + *sample = (accu * attenuation) >> 16; + sample++; + count --; + } +} diff --git a/Frameworks/lazyusf2/lazyusf2/rsp_hle/alist.h b/Frameworks/lazyusf2/lazyusf2/rsp_hle/alist.h index 2c2d40cfe..32579eb60 100644 --- a/Frameworks/lazyusf2/lazyusf2/rsp_hle/alist.h +++ b/Frameworks/lazyusf2/lazyusf2/rsp_hle/alist.h @@ -154,6 +154,13 @@ void alist_iirf( int16_t* table, uint32_t address); +void alist_overload( + struct hle_t* hle, + uint16_t dmem, + int16_t count, + int16_t gain, + int16_t attenuation); + /* * Audio flags */ diff --git a/Frameworks/lazyusf2/lazyusf2/rsp_hle/alist_naudio.c b/Frameworks/lazyusf2/lazyusf2/rsp_hle/alist_naudio.c index 30891d23d..1c66eabec 100644 --- a/Frameworks/lazyusf2/lazyusf2/rsp_hle/alist_naudio.c +++ b/Frameworks/lazyusf2/lazyusf2/rsp_hle/alist_naudio.c @@ -263,6 +263,17 @@ static void MP3(struct hle_t* hle, uint32_t w1, uint32_t w2) mp3_task(hle, index, address); } +static void OVERLOAD(struct hle_t* hle, uint32_t w1, uint32_t w2) +{ + /* Overload distortion effect for Conker's Bad Fur Day */ + /* Also included in Jet Force Gemini microcode */ + uint16_t dmem = (w1 & 0xfff) + NAUDIO_MAIN; + int16_t gain = w2 & 0x7fff; + int16_t attenuation = w2 >> 16; + + alist_overload(hle, dmem, NAUDIO_COUNT, gain, attenuation); +} + /* global functions */ void alist_process_naudio(struct hle_t* hle) { @@ -341,7 +352,7 @@ void alist_process_naudio_dk(struct hle_t* hle) void alist_process_naudio_mp3(struct hle_t* hle) { static const acmd_callback_t ABI[0x10] = { - UNKNOWN, ADPCM, CLEARBUFF, ENVMIXER, + OVERLOAD, ADPCM, CLEARBUFF, ENVMIXER, LOADBUFF, RESAMPLE, SAVEBUFF, MP3, MP3ADDY, SETVOL, DMEMMOVE, LOADADPCM, MIXER, INTERLEAVE, NAUDIO_14, SETLOOP @@ -349,7 +360,7 @@ void alist_process_naudio_mp3(struct hle_t* hle) #ifdef DEBUG_INFO static const char * ABI_names[0x10] = { - "UNKNOWN", "ADPCM", "CLEARBUFF", "ENVMIXER", + "OVERLOAD", "ADPCM", "CLEARBUFF", "ENVMIXER", "LOADBUFF", "RESAMPLE", "SAVEBUFF", "MP3", "MP3ADDY", "SETVOL", "DMEMMOVE", "LOADADPCM", "MIXER", "INTERLEAVE", "NAUDIO_14", "SETLOOP" @@ -366,7 +377,7 @@ void alist_process_naudio_cbfd(struct hle_t* hle) { /* TODO: see what differs from alist_process_naudio_mp3 */ static const acmd_callback_t ABI[0x10] = { - UNKNOWN, ADPCM, CLEARBUFF, ENVMIXER, + OVERLOAD, ADPCM, CLEARBUFF, ENVMIXER, LOADBUFF, RESAMPLE, SAVEBUFF, MP3, MP3ADDY, SETVOL, DMEMMOVE, LOADADPCM, MIXER, INTERLEAVE, NAUDIO_14, SETLOOP @@ -374,7 +385,7 @@ void alist_process_naudio_cbfd(struct hle_t* hle) #ifdef DEBUG_INFO static const char * ABI_names[0x10] = { - "UNKNOWN", "ADPCM", "CLEARBUFF", "ENVMIXER", + "OVERLOAD", "ADPCM", "CLEARBUFF", "ENVMIXER", "LOADBUFF", "RESAMPLE", "SAVEBUFF", "MP3", "MP3ADDY", "SETVOL", "DMEMMOVE", "LOADADPCM", "MIXER", "INTERLEAVE", "NAUDIO_14", "SETLOOP"