From ccccf8ff51358db4118e58c56c38a44df934168b Mon Sep 17 00:00:00 2001 From: David Benepe Date: Thu, 22 Jul 2021 14:33:07 -0500 Subject: [PATCH 1/4] Split unknown_0667D0 into main & alSynStartVoiceParams --- asm/entrypoint.s | 4 +- .../{unknown_0667D0 => main}/func_80065D98.s | 2 +- .../{unknown_0667D0 => main}/func_80065E30.s | 0 .../menu/menu_audio_options_loop.s | 2 +- .../unknown_066500/alSynSetPan.s | 2 +- .../unknown_0667D0/alSynStartVoiceParams.s | 69 ----------------- lib/src/mips1/al/alSynStartVoiceParams.c | 51 ++++++++++++ lib/src/mips1/al/alSynStartVoiceParams.h | 14 ++++ src/main.c | 77 +++++++++++++++++++ src/menu.c | 2 +- src/unknown_0667D0.c | 72 ----------------- src/unknown_0667D0.h | 8 -- 12 files changed, 148 insertions(+), 155 deletions(-) rename asm/non_matchings/{unknown_0667D0 => main}/func_80065D98.s (97%) rename asm/non_matchings/{unknown_0667D0 => main}/func_80065E30.s (100%) delete mode 100644 asm/non_matchings/unknown_0667D0/alSynStartVoiceParams.s create mode 100644 lib/src/mips1/al/alSynStartVoiceParams.c create mode 100644 lib/src/mips1/al/alSynStartVoiceParams.h create mode 100644 src/main.c delete mode 100644 src/unknown_0667D0.c delete mode 100644 src/unknown_0667D0.h diff --git a/asm/entrypoint.s b/asm/entrypoint.s index a394c0a0..6ecad654 100644 --- a/asm/entrypoint.s +++ b/asm/entrypoint.s @@ -20,9 +20,9 @@ glabel entrypoint /* 001018 80000418 AD000004 */ sw $zero, 4($t0) /* 00101C 8000041C 1520FFFC */ bnez $t1, .L80000410 /* 001020 80000420 21080008 */ addi $t0, $t0, 8 -/* 001024 80000424 3C0A8006 */ lui $t2, %hi(func_80065D40) # $t2, 0x8006 +/* 001024 80000424 3C0A8006 */ lui $t2, %hi(main) # $t2, 0x8006 /* 001028 80000428 3C1D8012 */ lui $sp, %hi(D_80120AC0) # $sp, 0x8012 -/* 00102C 8000042C 254A5D40 */ addiu $t2, %lo(func_80065D40) # addiu $t2, $t2, 0x5d40 +/* 00102C 8000042C 254A5D40 */ addiu $t2, %lo(main) # addiu $t2, $t2, 0x5d40 /* 001030 80000430 01400008 */ jr $t2 /* 001034 80000434 27BD0AC0 */ addiu $sp, %lo(D_80120AC0) # addiu $sp, $sp, 0xac0 /* 001038 80000438 00000000 */ nop diff --git a/asm/non_matchings/unknown_0667D0/func_80065D98.s b/asm/non_matchings/main/func_80065D98.s similarity index 97% rename from asm/non_matchings/unknown_0667D0/func_80065D98.s rename to asm/non_matchings/main/func_80065D98.s index f0630ecd..edf42ebb 100644 --- a/asm/non_matchings/unknown_0667D0/func_80065D98.s +++ b/asm/non_matchings/main/func_80065D98.s @@ -1,4 +1,4 @@ -glabel D_80065D98 +glabel func_80065D98 /* 066998 80065D98 27BDFFE0 */ addiu $sp, $sp, -0x20 /* 06699C 80065D9C AFBF001C */ sw $ra, 0x1c($sp) /* 0669A0 80065DA0 0C02DBD4 */ jal func_800B6F50 diff --git a/asm/non_matchings/unknown_0667D0/func_80065E30.s b/asm/non_matchings/main/func_80065E30.s similarity index 100% rename from asm/non_matchings/unknown_0667D0/func_80065E30.s rename to asm/non_matchings/main/func_80065E30.s diff --git a/asm/non_matchings/menu/menu_audio_options_loop.s b/asm/non_matchings/menu/menu_audio_options_loop.s index 9f9f9e51..501e10d2 100644 --- a/asm/non_matchings/menu/menu_audio_options_loop.s +++ b/asm/non_matchings/menu/menu_audio_options_loop.s @@ -187,7 +187,7 @@ glabel menu_audio_options_loop /* 085B18 80084F18 AC400000 */ sw $zero, ($v0) /* 085B1C 80084F1C 00002025 */ move $a0, $zero .L80084F20: -/* 085B20 80084F20 0C0196F4 */ jal func_80065BD0 +/* 085B20 80084F20 0C0196F4 */ jal set_stereo_pan_mode /* 085B24 80084F24 00000000 */ nop /* 085B28 80084F28 240E0001 */ li $t6, 1 /* 085B2C 80084F2C 10000074 */ b .L80085100 diff --git a/asm/non_matchings/unknown_066500/alSynSetPan.s b/asm/non_matchings/unknown_066500/alSynSetPan.s index 91652705..46d98986 100644 --- a/asm/non_matchings/unknown_066500/alSynSetPan.s +++ b/asm/non_matchings/unknown_066500/alSynSetPan.s @@ -21,7 +21,7 @@ glabel alSynSetPan /* 06676C 80065B6C 032A5821 */ addu $t3, $t9, $t2 /* 066770 80065B70 AC4B0004 */ sw $t3, 4($v0) /* 066774 80065B74 93A4002B */ lbu $a0, 0x2b($sp) -/* 066778 80065B78 0C0196FB */ jal func_80065BEC +/* 066778 80065B78 0C0196FB */ jal modify_panning /* 06677C 80065B7C AFA2001C */ sw $v0, 0x1c($sp) /* 066780 80065B80 8FA6001C */ lw $a2, 0x1c($sp) /* 066784 80065B84 24050003 */ li $a1, 3 diff --git a/asm/non_matchings/unknown_0667D0/alSynStartVoiceParams.s b/asm/non_matchings/unknown_0667D0/alSynStartVoiceParams.s deleted file mode 100644 index 100a6b6a..00000000 --- a/asm/non_matchings/unknown_0667D0/alSynStartVoiceParams.s +++ /dev/null @@ -1,69 +0,0 @@ -glabel alSynStartVoiceParams -/* 066838 80065C38 27BDFFE0 */ addiu $sp, $sp, -0x20 -/* 06683C 80065C3C AFBF0014 */ sw $ra, 0x14($sp) -/* 066840 80065C40 AFA40020 */ sw $a0, 0x20($sp) -/* 066844 80065C44 AFA50024 */ sw $a1, 0x24($sp) -/* 066848 80065C48 AFA60028 */ sw $a2, 0x28($sp) -/* 06684C 80065C4C AFA7002C */ sw $a3, 0x2c($sp) -/* 066850 80065C50 8CAF0008 */ lw $t7, 8($a1) -/* 066854 80065C54 00000000 */ nop -/* 066858 80065C58 11E00036 */ beqz $t7, .L80065D34 -/* 06685C 80065C5C 8FBF0014 */ lw $ra, 0x14($sp) -/* 066860 80065C60 0C01959A */ jal __allocParam -/* 066864 80065C64 00000000 */ nop -/* 066868 80065C68 10400031 */ beqz $v0, .L80065D30 -/* 06686C 80065C6C 00403025 */ move $a2, $v0 -/* 066870 80065C70 8FA20024 */ lw $v0, 0x24($sp) -/* 066874 80065C74 8FB80020 */ lw $t8, 0x20($sp) -/* 066878 80065C78 8C480008 */ lw $t0, 8($v0) -/* 06687C 80065C7C 8F19001C */ lw $t9, 0x1c($t8) -/* 066880 80065C80 8D0900D8 */ lw $t1, 0xd8($t0) -/* 066884 80065C84 240B000D */ li $t3, 13 -/* 066888 80065C88 03295021 */ addu $t2, $t9, $t1 -/* 06688C 80065C8C ACCA0004 */ sw $t2, 4($a2) -/* 066890 80065C90 ACC00000 */ sw $zero, ($a2) -/* 066894 80065C94 A4CB0008 */ sh $t3, 8($a2) -/* 066898 80065C98 844C001A */ lh $t4, 0x1a($v0) -/* 06689C 80065C9C 00000000 */ nop -/* 0668A0 80065CA0 A4CC000A */ sh $t4, 0xa($a2) -/* 0668A4 80065CA4 93A40037 */ lbu $a0, 0x37($sp) -/* 0668A8 80065CA8 0C0196FB */ jal func_80065BEC -/* 0668AC 80065CAC AFA6001C */ sw $a2, 0x1c($sp) -/* 0668B0 80065CB0 8FA6001C */ lw $a2, 0x1c($sp) -/* 0668B4 80065CB4 00000000 */ nop -/* 0668B8 80065CB8 A0C20012 */ sb $v0, 0x12($a2) -/* 0668BC 80065CBC 87AD0032 */ lh $t5, 0x32($sp) -/* 0668C0 80065CC0 00000000 */ nop -/* 0668C4 80065CC4 A4CD0010 */ sh $t5, 0x10($a2) -/* 0668C8 80065CC8 93AE003B */ lbu $t6, 0x3b($sp) -/* 0668CC 80065CCC 00000000 */ nop -/* 0668D0 80065CD0 A0CE0013 */ sb $t6, 0x13($a2) -/* 0668D4 80065CD4 C7A4002C */ lwc1 $f4, 0x2c($sp) -/* 0668D8 80065CD8 00000000 */ nop -/* 0668DC 80065CDC E4C4000C */ swc1 $f4, 0xc($a2) -/* 0668E0 80065CE0 8FA5003C */ lw $a1, 0x3c($sp) -/* 0668E4 80065CE4 8FA40020 */ lw $a0, 0x20($sp) -/* 0668E8 80065CE8 0C0195F1 */ jal __timeToSamples -/* 0668EC 80065CEC 00000000 */ nop -/* 0668F0 80065CF0 8FA6001C */ lw $a2, 0x1c($sp) -/* 0668F4 80065CF4 24050003 */ li $a1, 3 -/* 0668F8 80065CF8 ACC20014 */ sw $v0, 0x14($a2) -/* 0668FC 80065CFC 8FAF0028 */ lw $t7, 0x28($sp) -/* 066900 80065D00 00000000 */ nop -/* 066904 80065D04 ACCF0018 */ sw $t7, 0x18($a2) -/* 066908 80065D08 8FB80024 */ lw $t8, 0x24($sp) -/* 06690C 80065D0C 00000000 */ nop -/* 066910 80065D10 8F080008 */ lw $t0, 8($t8) -/* 066914 80065D14 00000000 */ nop -/* 066918 80065D18 8D04000C */ lw $a0, 0xc($t0) -/* 06691C 80065D1C 00000000 */ nop -/* 066920 80065D20 8C990008 */ lw $t9, 8($a0) -/* 066924 80065D24 00000000 */ nop -/* 066928 80065D28 0320F809 */ jalr $t9 -/* 06692C 80065D2C 00000000 */ nop -.L80065D30: -/* 066930 80065D30 8FBF0014 */ lw $ra, 0x14($sp) -.L80065D34: -/* 066934 80065D34 27BD0020 */ addiu $sp, $sp, 0x20 -/* 066938 80065D38 03E00008 */ jr $ra -/* 06693C 80065D3C 00000000 */ nop diff --git a/lib/src/mips1/al/alSynStartVoiceParams.c b/lib/src/mips1/al/alSynStartVoiceParams.c new file mode 100644 index 00000000..1eea9e40 --- /dev/null +++ b/lib/src/mips1/al/alSynStartVoiceParams.c @@ -0,0 +1,51 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x80065BD0 */ + +#include "alSynStartVoiceParams.h" + +s16 gStereoPanMode = STEREO; + +void set_stereo_pan_mode(s32 panMode) { + gStereoPanMode = panMode; +} + +/* Unused. */ +s16 get_stereo_pan_mode(void) { + return gStereoPanMode; +} + +s32 modify_panning(s32 pan) { + switch(gStereoPanMode) { + case STEREO: + return pan; + case HEADPHONES: + pan = ((pan - 64) >> 1) + 64; + return pan; + case MONO: + default: + return 64; + } +} + +void alSynStartVoiceParams(ALSynth *s, ALVoice *v, ALWaveTable *w, f32 pitch, s16 vol, ALPan pan, u8 fxmix, ALMicroTime t) { + ALStartParamAlt *update; + ALFilter *f; + + if (v->pvoice) { + update = (ALStartParamAlt *)__allocParam(); + if (update != NULL) { + update->delta = s->paramSamples + v->pvoice->offset; + update->next = 0; + update->type = AL_FILTER_START_VOICE_ALT; + update->unity = v->unityPitch; + update->pan = modify_panning(pan); + update->volume = vol; + update->fxMix = fxmix; + update->pitch = pitch; + update->samples = __timeToSamples(s, t); + update->wave = w; + f = v->pvoice->channelKnob; + (*f->setParam)(f, AL_FILTER_ADD_UPDATE, update); + } + } +} diff --git a/lib/src/mips1/al/alSynStartVoiceParams.h b/lib/src/mips1/al/alSynStartVoiceParams.h new file mode 100644 index 00000000..6544052c --- /dev/null +++ b/lib/src/mips1/al/alSynStartVoiceParams.h @@ -0,0 +1,14 @@ +#ifndef AL_SYN_START_VOICE_PARAMS +#define AL_SYN_START_VOICE_PARAMS + +#include "types.h" +#include "audio_internal.h" + +// Can be changed in the "Audio Options" menu. +enum StereoPanMode { + STEREO, + MONO, + HEADPHONES +}; + +#endif \ No newline at end of file diff --git a/src/main.c b/src/main.c new file mode 100644 index 00000000..d7164f05 --- /dev/null +++ b/src/main.c @@ -0,0 +1,77 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x80065D40 */ + +#include "types.h" +#include "macros.h" +#include "libultra_internal.h" + +/************ .rodata ************/ + +#ifndef NON_MATCHING +// Remove this when func_80065E30 is matching. +const char D_800E6ED0[] = "WARNING: Stack overflow/underflow!!!\n"; +#endif + +/*********************************/ + +/************ .bss ************/ + +s32 *D_8011D750; // stack pointer for thread 1 +s32 D_8011D754; +s32 D_8011D758[2048]; +s32 *D_8011F758; +s32 D_8011F75C; +OSThread *D_8011F760; // OSThread for thread 1 +s32 D_8011F764; +s32 D_8011F768[106]; +OSThread *D_8011F910; // OSThread for thread 3 +s32 D_8011F914; +s32 D_8011F918[1130]; + +/******************************/ + +void func_80065D98(s32 arg0); +void thread3_main(s32 arg0); + +void main(void) { + osInitialize(); + osCreateThread(&D_8011F760, 1, &func_80065D98, 0, &D_8011D750, 0); + osStartThread(&D_8011F760); +} + +#ifdef NON_MATCHING +void func_80065D98(s32 arg0) { + func_800B6F50(); + osCreateThread(&D_8011F910, 3, &thread3_main, 0, &D_8011F758, 10); + D_8011D758[2049] = 0; + D_8011D758[2048] = 0; + D_8011D758[1] = 0; + D_8011D758[0] = 0; + osStartThread(&D_8011F910); + osSetThreadPri(NULL, 0); + while(1){} +} +#else +GLOBAL_ASM("asm/non_matchings/main/func_80065D98.s") +#endif + +#ifdef NON_MATCHING +void func_80065E30(void) { + s32 temp, temp2, temp3, temp4; + temp = D_8011D758[2049] + 1; + temp2 = D_8011D758[2048] + (temp == 0); + temp3 = D_8011D758[1] + 1; + temp4 = D_8011D758[0] + (temp3 == 0); + D_8011D758[2049] = temp; + D_8011D758[2048] = temp2; + D_8011D758[1] = temp3; + D_8011D758[0] = temp4; + if ((temp2 != temp4) || (temp != temp3)) { + func_800C9D54("WARNING: Stack overflow/underflow!!!\n"); + } +} +#else +GLOBAL_ASM("asm/non_matchings/main/func_80065E30.s") +#endif + + diff --git a/src/menu.c b/src/menu.c index 351ee3ba..4a885a8c 100644 --- a/src/menu.c +++ b/src/menu.c @@ -2213,7 +2213,7 @@ s32 menu_audio_options_loop(s32 arg0) { if (D_800DFAC8 > 2) { D_800DFAC8 = 0; } - func_80065BD0(D_800DFAC8); + set_stereo_pan_mode(D_800DFAC8); sp30 = 1; } else if ((phi_a2 >> 2) != 0) { if(gOptionsMenuItemIndex == 2) { diff --git a/src/unknown_0667D0.c b/src/unknown_0667D0.c deleted file mode 100644 index e4aa8899..00000000 --- a/src/unknown_0667D0.c +++ /dev/null @@ -1,72 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x80065BD0 */ - -#include "unknown_0667D0.h" - -#include "types.h" -#include "macros.h" -#include "libultra_internal.h" - -/************ .data ************/ - -s16 D_800DD050 = 0; - -/*******************************/ - -extern s32* D_80065D98; // func_80065D98 is the entry function for thread 1 - -/************ .rodata ************/ - -// In func_80065E30 -const char D_800E6ED0[] = "WARNING: Stack overflow/underflow!!!\n"; - -/*********************************/ - -/************ .bss ************/ - -s32 *D_8011D750; // stack pointer for thread 1 -s32 D_8011D754; -s32 D_8011D758[2048]; -s32 *D_8011F758; -s32 D_8011F75C; -OSThread *D_8011F760; // OSThread for thread 1 -s32 D_8011F764; -s32 D_8011F768[106]; -s32 *D_8011F910[1132]; - -/******************************/ - -void func_80065BD0(s32 arg0) { - D_800DD050 = arg0; -} - -/* Unused? */ -s16 func_80065BDC(void) { - return D_800DD050; -} - -s32 func_80065BEC(s32 arg0) { - switch(D_800DD050) { - case 0: - return arg0; - case 2: - arg0 = ((arg0 - 0x40) >> 1) + 0x40; - return arg0; - case 1: - default: - return 0x40; - } -} - -GLOBAL_ASM("asm/non_matchings/unknown_0667D0/alSynStartVoiceParams.s") - -void func_80065D40(void) { - osInitialize(); - osCreateThread(&D_8011F760, 1, &D_80065D98, 0, &D_8011D750, 0); - osStartThread(&D_8011F760); -} - -GLOBAL_ASM("asm/non_matchings/unknown_0667D0/func_80065D98.s") -GLOBAL_ASM("asm/non_matchings/unknown_0667D0/func_80065E30.s") - - diff --git a/src/unknown_0667D0.h b/src/unknown_0667D0.h deleted file mode 100644 index 0eb70020..00000000 --- a/src/unknown_0667D0.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef _UNKNOWN_066500_H_ -#define _UNKNOWN_066500_H_ - -#include "types.h" - -extern s16 D_800DD050; - -#endif \ No newline at end of file From 442f0c3c33721f027310b67b0320c39c34011222 Mon Sep 17 00:00:00 2001 From: David Benepe Date: Thu, 22 Jul 2021 20:16:31 -0500 Subject: [PATCH 2/4] Decompiled files alAuxBusPull.c & alSynSetPan.c --- .../unknown_066500/alAuxBusParam.s | 52 ------------- .../unknown_066500/alAuxBusPull.s | 57 --------------- .../unknown_066500/alSynSetPan.s | 49 ------------- .../unknown_066500/func_80065A80.s | 43 ----------- include/audio_internal.h | 2 +- lib/src/mips1/al/alAuxBusPull.c | 73 +++++++++++++++++++ lib/src/mips1/al/alSynSetPan.c | 27 +++++++ lib/src/mips1/al/alSynStartVoiceParams.h | 3 + src/unknown_066500.c | 12 --- src/unknown_066500.h | 4 - 10 files changed, 104 insertions(+), 218 deletions(-) delete mode 100644 asm/non_matchings/unknown_066500/alAuxBusParam.s delete mode 100644 asm/non_matchings/unknown_066500/alAuxBusPull.s delete mode 100644 asm/non_matchings/unknown_066500/alSynSetPan.s delete mode 100644 asm/non_matchings/unknown_066500/func_80065A80.s create mode 100644 lib/src/mips1/al/alAuxBusPull.c create mode 100644 lib/src/mips1/al/alSynSetPan.c delete mode 100644 src/unknown_066500.c delete mode 100644 src/unknown_066500.h diff --git a/asm/non_matchings/unknown_066500/alAuxBusParam.s b/asm/non_matchings/unknown_066500/alAuxBusParam.s deleted file mode 100644 index 5f125f0f..00000000 --- a/asm/non_matchings/unknown_066500/alAuxBusParam.s +++ /dev/null @@ -1,52 +0,0 @@ -glabel alAuxBusParam -/* 0665D4 800659D4 8C83001C */ lw $v1, 0x1c($a0) -/* 0665D8 800659D8 24010002 */ li $at, 2 -/* 0665DC 800659DC 10A10006 */ beq $a1, $at, .L800659F8 -/* 0665E0 800659E0 00801025 */ move $v0, $a0 -/* 0665E4 800659E4 24010011 */ li $at, 17 -/* 0665E8 800659E8 10A1000D */ beq $a1, $at, .L80065A20 -/* 0665EC 800659EC 00000000 */ nop -/* 0665F0 800659F0 03E00008 */ jr $ra -/* 0665F4 800659F4 00001025 */ move $v0, $zero - -.L800659F8: -/* 0665F8 800659F8 8C8E0014 */ lw $t6, 0x14($a0) -/* 0665FC 800659FC 00001025 */ move $v0, $zero -/* 066600 80065A00 000E7880 */ sll $t7, $t6, 2 -/* 066604 80065A04 006FC021 */ addu $t8, $v1, $t7 -/* 066608 80065A08 AF060000 */ sw $a2, ($t8) -/* 06660C 80065A0C 8C990014 */ lw $t9, 0x14($a0) -/* 066610 80065A10 00000000 */ nop -/* 066614 80065A14 27280001 */ addiu $t0, $t9, 1 -/* 066618 80065A18 03E00008 */ jr $ra -/* 06661C 80065A1C AC880014 */ sw $t0, 0x14($a0) - -.L80065A20: -/* 066620 80065A20 8C890014 */ lw $t1, 0x14($a0) -/* 066624 80065A24 00002825 */ move $a1, $zero -/* 066628 80065A28 19200013 */ blez $t1, .L80065A78 -/* 06662C 80065A2C 00603825 */ move $a3, $v1 -.L80065A30: -/* 066630 80065A30 8CEA0000 */ lw $t2, ($a3) -/* 066634 80065A34 00000000 */ nop -/* 066638 80065A38 14CA000A */ bne $a2, $t2, .L80065A64 -/* 06663C 80065A3C 00000000 */ nop -/* 066640 80065A40 8C8B0014 */ lw $t3, 0x14($a0) -/* 066644 80065A44 00000000 */ nop -/* 066648 80065A48 256CFFFF */ addiu $t4, $t3, -1 -/* 06664C 80065A4C 000C7080 */ sll $t6, $t4, 2 -/* 066650 80065A50 AC8C0014 */ sw $t4, 0x14($a0) -/* 066654 80065A54 006E7821 */ addu $t7, $v1, $t6 -/* 066658 80065A58 8DF80000 */ lw $t8, ($t7) -/* 06665C 80065A5C 00000000 */ nop -/* 066660 80065A60 ACF80000 */ sw $t8, ($a3) -.L80065A64: -/* 066664 80065A64 8C590014 */ lw $t9, 0x14($v0) -/* 066668 80065A68 24A50001 */ addiu $a1, $a1, 1 -/* 06666C 80065A6C 00B9082A */ slt $at, $a1, $t9 -/* 066670 80065A70 1420FFEF */ bnez $at, .L80065A30 -/* 066674 80065A74 24E70004 */ addiu $a3, $a3, 4 -.L80065A78: -/* 066678 80065A78 03E00008 */ jr $ra -/* 06667C 80065A7C 00001025 */ move $v0, $zero - diff --git a/asm/non_matchings/unknown_066500/alAuxBusPull.s b/asm/non_matchings/unknown_066500/alAuxBusPull.s deleted file mode 100644 index 5479817b..00000000 --- a/asm/non_matchings/unknown_066500/alAuxBusPull.s +++ /dev/null @@ -1,57 +0,0 @@ -glabel alAuxBusPull -/* 066500 80065900 27BDFFC0 */ addiu $sp, $sp, -0x40 -/* 066504 80065904 AFB10024 */ sw $s1, 0x24($sp) -/* 066508 80065908 8FB10050 */ lw $s1, 0x50($sp) -/* 06650C 8006590C AFBF003C */ sw $ra, 0x3c($sp) -/* 066510 80065910 AFB60038 */ sw $s6, 0x38($sp) -/* 066514 80065914 AFB50034 */ sw $s5, 0x34($sp) -/* 066518 80065918 AFB40030 */ sw $s4, 0x30($sp) -/* 06651C 8006591C AFB3002C */ sw $s3, 0x2c($sp) -/* 066520 80065920 AFB20028 */ sw $s2, 0x28($sp) -/* 066524 80065924 AFB00020 */ sw $s0, 0x20($sp) -/* 066528 80065928 8C83001C */ lw $v1, 0x1c($a0) -/* 06652C 8006592C 3C0E0200 */ lui $t6, (0x020006C0 >> 16) # lui $t6, 0x200 -/* 066530 80065930 00061040 */ sll $v0, $a2, 1 -/* 066534 80065934 3C0F0200 */ lui $t7, (0x02000800 >> 16) # lui $t7, 0x200 -/* 066538 80065938 35CE06C0 */ ori $t6, (0x020006C0 & 0xFFFF) # ori $t6, $t6, 0x6c0 -/* 06653C 8006593C 35EF0800 */ ori $t7, (0x02000800 & 0xFFFF) # ori $t7, $t7, 0x800 -/* 066540 80065940 AE2E0000 */ sw $t6, ($s1) -/* 066544 80065944 AE220004 */ sw $v0, 4($s1) -/* 066548 80065948 AE2F0008 */ sw $t7, 8($s1) -/* 06654C 8006594C AE22000C */ sw $v0, 0xc($s1) -/* 066550 80065950 8C980014 */ lw $t8, 0x14($a0) -/* 066554 80065954 00C0A025 */ move $s4, $a2 -/* 066558 80065958 00A0A825 */ move $s5, $a1 -/* 06655C 8006595C 00E0B025 */ move $s6, $a3 -/* 066560 80065960 00809825 */ move $s3, $a0 -/* 066564 80065964 00008025 */ move $s0, $zero -/* 066568 80065968 1B00000F */ blez $t8, .L800659A8 -/* 06656C 8006596C 26320010 */ addiu $s2, $s1, 0x10 -/* 066570 80065970 00608825 */ move $s1, $v1 -.L80065974: -/* 066574 80065974 8E240000 */ lw $a0, ($s1) -/* 066578 80065978 AFB20010 */ sw $s2, 0x10($sp) -/* 06657C 8006597C 8C990004 */ lw $t9, 4($a0) -/* 066580 80065980 02A02825 */ move $a1, $s5 -/* 066584 80065984 02803025 */ move $a2, $s4 -/* 066588 80065988 0320F809 */ jalr $t9 -/* 06658C 8006598C 02C03825 */ move $a3, $s6 -/* 066590 80065990 8E680014 */ lw $t0, 0x14($s3) -/* 066594 80065994 26100001 */ addiu $s0, $s0, 1 -/* 066598 80065998 0208082A */ slt $at, $s0, $t0 -/* 06659C 8006599C 26310004 */ addiu $s1, $s1, 4 -/* 0665A0 800659A0 1420FFF4 */ bnez $at, .L80065974 -/* 0665A4 800659A4 00409025 */ move $s2, $v0 -.L800659A8: -/* 0665A8 800659A8 8FBF003C */ lw $ra, 0x3c($sp) -/* 0665AC 800659AC 02401025 */ move $v0, $s2 -/* 0665B0 800659B0 8FB20028 */ lw $s2, 0x28($sp) -/* 0665B4 800659B4 8FB00020 */ lw $s0, 0x20($sp) -/* 0665B8 800659B8 8FB10024 */ lw $s1, 0x24($sp) -/* 0665BC 800659BC 8FB3002C */ lw $s3, 0x2c($sp) -/* 0665C0 800659C0 8FB40030 */ lw $s4, 0x30($sp) -/* 0665C4 800659C4 8FB50034 */ lw $s5, 0x34($sp) -/* 0665C8 800659C8 8FB60038 */ lw $s6, 0x38($sp) -/* 0665CC 800659CC 03E00008 */ jr $ra -/* 0665D0 800659D0 27BD0040 */ addiu $sp, $sp, 0x40 - diff --git a/asm/non_matchings/unknown_066500/alSynSetPan.s b/asm/non_matchings/unknown_066500/alSynSetPan.s deleted file mode 100644 index 46d98986..00000000 --- a/asm/non_matchings/unknown_066500/alSynSetPan.s +++ /dev/null @@ -1,49 +0,0 @@ -glabel alSynSetPan -/* 066720 80065B20 27BDFFE0 */ addiu $sp, $sp, -0x20 -/* 066724 80065B24 AFBF0014 */ sw $ra, 0x14($sp) -/* 066728 80065B28 AFA40020 */ sw $a0, 0x20($sp) -/* 06672C 80065B2C AFA50024 */ sw $a1, 0x24($sp) -/* 066730 80065B30 AFA60028 */ sw $a2, 0x28($sp) -/* 066734 80065B34 8CAF0008 */ lw $t7, 8($a1) -/* 066738 80065B38 00000000 */ nop -/* 06673C 80065B3C 11E0001F */ beqz $t7, .L80065BBC -/* 066740 80065B40 8FBF0014 */ lw $ra, 0x14($sp) -/* 066744 80065B44 0C01959A */ jal __allocParam -/* 066748 80065B48 00000000 */ nop -/* 06674C 80065B4C 1040001A */ beqz $v0, .L80065BB8 -/* 066750 80065B50 240C000C */ li $t4, 12 -/* 066754 80065B54 8FA80024 */ lw $t0, 0x24($sp) -/* 066758 80065B58 8FB80020 */ lw $t8, 0x20($sp) -/* 06675C 80065B5C 8D090008 */ lw $t1, 8($t0) -/* 066760 80065B60 8F19001C */ lw $t9, 0x1c($t8) -/* 066764 80065B64 8D2A00D8 */ lw $t2, 0xd8($t1) -/* 066768 80065B68 A44C0008 */ sh $t4, 8($v0) -/* 06676C 80065B6C 032A5821 */ addu $t3, $t9, $t2 -/* 066770 80065B70 AC4B0004 */ sw $t3, 4($v0) -/* 066774 80065B74 93A4002B */ lbu $a0, 0x2b($sp) -/* 066778 80065B78 0C0196FB */ jal modify_panning -/* 06677C 80065B7C AFA2001C */ sw $v0, 0x1c($sp) -/* 066780 80065B80 8FA6001C */ lw $a2, 0x1c($sp) -/* 066784 80065B84 24050003 */ li $a1, 3 -/* 066788 80065B88 ACC2000C */ sw $v0, 0xc($a2) -/* 06678C 80065B8C ACC00000 */ sw $zero, ($a2) -/* 066790 80065B90 8FAD0024 */ lw $t5, 0x24($sp) -/* 066794 80065B94 00000000 */ nop -/* 066798 80065B98 8DAE0008 */ lw $t6, 8($t5) -/* 06679C 80065B9C 00000000 */ nop -/* 0667A0 80065BA0 8DC4000C */ lw $a0, 0xc($t6) -/* 0667A4 80065BA4 00000000 */ nop -/* 0667A8 80065BA8 8C990008 */ lw $t9, 8($a0) -/* 0667AC 80065BAC 00000000 */ nop -/* 0667B0 80065BB0 0320F809 */ jalr $t9 -/* 0667B4 80065BB4 00000000 */ nop -.L80065BB8: -/* 0667B8 80065BB8 8FBF0014 */ lw $ra, 0x14($sp) -.L80065BBC: -/* 0667BC 80065BBC 27BD0020 */ addiu $sp, $sp, 0x20 -/* 0667C0 80065BC0 03E00008 */ jr $ra -/* 0667C4 80065BC4 00000000 */ nop - -/* 0667C8 80065BC8 00000000 */ nop -/* 0667CC 80065BCC 00000000 */ nop - diff --git a/asm/non_matchings/unknown_066500/func_80065A80.s b/asm/non_matchings/unknown_066500/func_80065A80.s deleted file mode 100644 index 7bff323a..00000000 --- a/asm/non_matchings/unknown_066500/func_80065A80.s +++ /dev/null @@ -1,43 +0,0 @@ -glabel func_80065A80 -/* 066680 80065A80 27BDFFE0 */ addiu $sp, $sp, -0x20 -/* 066684 80065A84 AFA60028 */ sw $a2, 0x28($sp) -/* 066688 80065A88 AFBF0014 */ sw $ra, 0x14($sp) -/* 06668C 80065A8C AFA40020 */ sw $a0, 0x20($sp) -/* 066690 80065A90 90A200DC */ lbu $v0, 0xdc($a1) -/* 066694 80065A94 87AE002A */ lh $t6, 0x2a($sp) -/* 066698 80065A98 00A03825 */ move $a3, $a1 -/* 06669C 80065A9C 11C2001C */ beq $t6, $v0, .L80065B10 -/* 0666A0 80065AA0 0002C880 */ sll $t9, $v0, 2 -/* 0666A4 80065AA4 0322C821 */ addu $t9, $t9, $v0 -/* 0666A8 80065AA8 8C980034 */ lw $t8, 0x34($a0) -/* 0666AC 80065AAC 0019C880 */ sll $t9, $t9, 2 -/* 0666B0 80065AB0 0322C823 */ subu $t9, $t9, $v0 -/* 0666B4 80065AB4 0019C880 */ sll $t9, $t9, 2 -/* 0666B8 80065AB8 24E6008C */ addiu $a2, $a3, 0x8c -/* 0666BC 80065ABC AFA60018 */ sw $a2, 0x18($sp) -/* 0666C0 80065AC0 AFA70024 */ sw $a3, 0x24($sp) -/* 0666C4 80065AC4 24050011 */ li $a1, 17 -/* 0666C8 80065AC8 0C019675 */ jal alAuxBusParam -/* 0666CC 80065ACC 03192021 */ addu $a0, $t8, $t9 -/* 0666D0 80065AD0 87AA002A */ lh $t2, 0x2a($sp) -/* 0666D4 80065AD4 8FA80020 */ lw $t0, 0x20($sp) -/* 0666D8 80065AD8 000A5880 */ sll $t3, $t2, 2 -/* 0666DC 80065ADC 016A5821 */ addu $t3, $t3, $t2 -/* 0666E0 80065AE0 000B5880 */ sll $t3, $t3, 2 -/* 0666E4 80065AE4 8D090034 */ lw $t1, 0x34($t0) -/* 0666E8 80065AE8 016A5823 */ subu $t3, $t3, $t2 -/* 0666EC 80065AEC 8FA60018 */ lw $a2, 0x18($sp) -/* 0666F0 80065AF0 000B5880 */ sll $t3, $t3, 2 -/* 0666F4 80065AF4 24050002 */ li $a1, 2 -/* 0666F8 80065AF8 0C019675 */ jal alAuxBusParam -/* 0666FC 80065AFC 012B2021 */ addu $a0, $t1, $t3 -/* 066700 80065B00 87AC002A */ lh $t4, 0x2a($sp) -/* 066704 80065B04 8FAD0024 */ lw $t5, 0x24($sp) -/* 066708 80065B08 00000000 */ nop -/* 06670C 80065B0C A1AC00DC */ sb $t4, 0xdc($t5) -.L80065B10: -/* 066710 80065B10 8FBF0014 */ lw $ra, 0x14($sp) -/* 066714 80065B14 27BD0020 */ addiu $sp, $sp, 0x20 -/* 066718 80065B18 03E00008 */ jr $ra -/* 06671C 80065B1C 00000000 */ nop - diff --git a/include/audio_internal.h b/include/audio_internal.h index b5e8741b..b76d73e9 100644 --- a/include/audio_internal.h +++ b/include/audio_internal.h @@ -9,7 +9,7 @@ enum { AL_FILTER_FREE_VOICE, AL_FILTER_SET_SOURCE, - AL_FILTER_ADD_SOURCE, + AL_FILTER_ADD_SOURCE, // 2 AL_FILTER_ADD_UPDATE, AL_FILTER_RESET, AL_FILTER_SET_WAVETABLE, diff --git a/lib/src/mips1/al/alAuxBusPull.c b/lib/src/mips1/al/alAuxBusPull.c new file mode 100644 index 00000000..1fe17fd6 --- /dev/null +++ b/lib/src/mips1/al/alAuxBusPull.c @@ -0,0 +1,73 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x80065900 */ + +#include "alSynStartVoiceParams.h" + +#include "types.h" +#include "macros.h" +#include "audio_internal.h" + +Acmd *alAuxBusPull(void *filter, s16 *outp, s32 outCount, s32 sampleOffset, Acmd *p) { + Acmd *ptr = p; + ALAuxBus *m = (ALAuxBus *)filter; + ALFilter **sources = m->sources; + s32 i; + aClearBuffer(ptr++, AL_AUX_L_OUT, outCount<<1); + aClearBuffer(ptr++, AL_AUX_R_OUT, outCount<<1); + + for (i = 0; i < m->sourceCount; i++) { + ptr = (sources[i]->handler)(sources[i], outp, outCount, sampleOffset, ptr); + } + + return ptr; +} + +s32 alAuxBusParam(void *filter, s32 paramID, void *param) { + ALAuxBus *m = (ALAuxBus *) filter; + ALFilter **sources = m->sources; + s32 i; + + switch (paramID) { + case AL_FILTER_ADD_SOURCE: + sources[m->sourceCount++] = (ALFilter *) param; + break; + case 0x11: + for (i = 0; i < m->sourceCount; i++) { + if ((ALFilter *) param == sources[i]) { + m->sourceCount--; + sources[i] = sources[m->sourceCount]; + } + } + break; + } + + return 0; + +} + +/* Size: 0x4C bytes */ +typedef struct unk80065A80_arg0_34 { + u8 pad0[0x4C]; +} unk80065A80_arg0_34; + +/* Unknown size */ +typedef struct unk80065A80_arg0 { + u8 pad0[0x34]; + unk80065A80_arg0_34 *unk34; +} unk80065A80_arg0; + +/* Unknown size */ +typedef struct unk80065A80_arg1 { + u8 pad0[0x8C]; + s32 unk8C; + u8 pad90[0x4C]; + u8 unkDC; +} unk80065A80_arg1; + +void func_80065A80(unk80065A80_arg0 *arg0, unk80065A80_arg1 *arg1, s16 arg2) { + if (arg2 != arg1->unkDC) { + alAuxBusParam(&arg0->unk34[arg1->unkDC], 0x11, &arg1->unk8C); + alAuxBusParam(&arg0->unk34[arg2], 2, &arg1->unk8C); + arg1->unkDC = arg2; + } +} diff --git a/lib/src/mips1/al/alSynSetPan.c b/lib/src/mips1/al/alSynSetPan.c new file mode 100644 index 00000000..180ca092 --- /dev/null +++ b/lib/src/mips1/al/alSynSetPan.c @@ -0,0 +1,27 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x80065B20 */ + +#include "alSynStartVoiceParams.h" + +#include "types.h" +#include "macros.h" +#include "audio_internal.h" + +void alSynSetPan(ALSynth *synth, ALVoice *v, u8 pan) { + ALParam *update; + ALFilter *f; + + if (v->pvoice) { + update = __allocParam(); + + if(update != NULL) { + update->delta = synth->paramSamples + v->pvoice->offset; + update->type = AL_FILTER_SET_PAN; + update->data.i = modify_panning(pan); + update->next = 0; + + f = v->pvoice->channelKnob; + (*f->setParam)(f, AL_FILTER_ADD_UPDATE, update); + } + } +} diff --git a/lib/src/mips1/al/alSynStartVoiceParams.h b/lib/src/mips1/al/alSynStartVoiceParams.h index 6544052c..ea8a1370 100644 --- a/lib/src/mips1/al/alSynStartVoiceParams.h +++ b/lib/src/mips1/al/alSynStartVoiceParams.h @@ -11,4 +11,7 @@ enum StereoPanMode { HEADPHONES }; +void set_stereo_pan_mode(s32 panMode); +s32 modify_panning(s32 pan); + #endif \ No newline at end of file diff --git a/src/unknown_066500.c b/src/unknown_066500.c deleted file mode 100644 index b111b92a..00000000 --- a/src/unknown_066500.c +++ /dev/null @@ -1,12 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x80065900 */ - -#include "unknown_066500.h" - -#include "types.h" -#include "macros.h" - -GLOBAL_ASM("asm/non_matchings/unknown_066500/alAuxBusPull.s") -GLOBAL_ASM("asm/non_matchings/unknown_066500/alAuxBusParam.s") -GLOBAL_ASM("asm/non_matchings/unknown_066500/func_80065A80.s") -GLOBAL_ASM("asm/non_matchings/unknown_066500/alSynSetPan.s") diff --git a/src/unknown_066500.h b/src/unknown_066500.h deleted file mode 100644 index 1110dd65..00000000 --- a/src/unknown_066500.h +++ /dev/null @@ -1,4 +0,0 @@ -#ifndef _UNKNOWN_066500_H_ -#define _UNKNOWN_066500_H_ - -#endif \ No newline at end of file From 2375ac84a56d2bbee3d4725c84d50cceb97d52f3 Mon Sep 17 00:00:00 2001 From: David Benepe Date: Thu, 22 Jul 2021 20:51:42 -0500 Subject: [PATCH 3/4] Renamed unknown_066460 to alSynAllocFX, and moved to lib folder. --- .../alSynAllocFX}/alSynAllocFX.s | 0 lib/src/mips1/al/alSynAllocFX.c | 18 +++++++++++++++ src/unknown_066460.c | 22 ------------------- src/unknown_066460.h | 4 ---- 4 files changed, 18 insertions(+), 26 deletions(-) rename {asm/non_matchings/unknown_066460 => lib/asm/non_matchings/alSynAllocFX}/alSynAllocFX.s (100%) create mode 100644 lib/src/mips1/al/alSynAllocFX.c delete mode 100644 src/unknown_066460.c delete mode 100644 src/unknown_066460.h diff --git a/asm/non_matchings/unknown_066460/alSynAllocFX.s b/lib/asm/non_matchings/alSynAllocFX/alSynAllocFX.s similarity index 100% rename from asm/non_matchings/unknown_066460/alSynAllocFX.s rename to lib/asm/non_matchings/alSynAllocFX/alSynAllocFX.s diff --git a/lib/src/mips1/al/alSynAllocFX.c b/lib/src/mips1/al/alSynAllocFX.c new file mode 100644 index 00000000..ff42dc1a --- /dev/null +++ b/lib/src/mips1/al/alSynAllocFX.c @@ -0,0 +1,18 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x80065860 */ + +#include "types.h" +#include "macros.h" +#include "audio_internal.h" + +#ifdef NON_MATCHING +// This is very close to matching. +ALFxRef *alSynAllocFX(ALSynth *s, s16 bus, s32 *arg2) { + alFxNew(&s->auxBus[bus].fx[0], arg2, bus); + alFxParam(&s->auxBus[bus].fx[0], AL_FILTER_SET_SOURCE, &s->auxBus[bus]); + alMainBusParam(s->mainBus, AL_FILTER_ADD_SOURCE, &s->auxBus[bus].fx[0]); + return (ALFxRef)(&s->auxBus[bus].fx[0]); +} +#else +GLOBAL_ASM("lib/asm/non_matchings/alSynAllocFX/alSynAllocFX.s") +#endif \ No newline at end of file diff --git a/src/unknown_066460.c b/src/unknown_066460.c deleted file mode 100644 index d072d9cf..00000000 --- a/src/unknown_066460.c +++ /dev/null @@ -1,22 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x80065860 */ - -#include "unknown_066460.h" - -#include "types.h" -#include "macros.h" -#include "audio_internal.h" - -#if 1 - GLOBAL_ASM("asm/non_matchings/unknown_066460/alSynAllocFX.s") -#else -ALFxRef *alSynAllocFX(ALSynth *s, s16 bus, ALSynConfig *c, ALHeap *hp) -{ - alFxNew(&s->auxBus[bus].fx[0], c, hp); - alFxParam(&s->auxBus[bus].fx[0], AL_FILTER_SET_SOURCE, - &s->auxBus[bus]); - alMainBusParam(s->mainBus, AL_FILTER_ADD_SOURCE,&s->auxBus[bus].fx[0]); - - return (ALFxRef)(&s->auxBus[bus].fx[0]); -} -#endif \ No newline at end of file diff --git a/src/unknown_066460.h b/src/unknown_066460.h deleted file mode 100644 index 582be8b7..00000000 --- a/src/unknown_066460.h +++ /dev/null @@ -1,4 +0,0 @@ -#ifndef _UNKNOWN_066460_H_ -#define _UNKNOWN_066460_H_ - -#endif \ No newline at end of file From 6f234d2041791a5895bdee22c6c4c5d48fe6d9a0 Mon Sep 17 00:00:00 2001 From: David Benepe Date: Thu, 22 Jul 2021 23:20:51 -0500 Subject: [PATCH 4/4] Decompiled most of synthesizer.c --- .../unknown_065D30/__allocParam.s | 16 -- .../unknown_065D30/__collectPVoices.s | 28 --- .../unknown_065D30/__freePVoices.s | 16 -- .../unknown_065D30/__freeParam.s | 10 - .../unknown_065D30/__nextSampleTime.s | 35 --- .../unknown_065D30/__timeToSamples.s | 12 - .../unknown_065D30/__timeToSamplesNoRound.s | 35 --- .../unknown_065D30/alAudioFrame.s | 126 ---------- include/PR/libaudio.h | 3 +- include/audio_internal.h | 1 + .../asm/non_matchings/synthesizer}/alSynNew.s | 0 lib/src/mips1/al/synthesizer.c | 218 ++++++++++++++++++ src/audio.c | 4 +- src/unknown_065D30.c | 17 -- src/unknown_065D30.h | 4 - 15 files changed, 222 insertions(+), 303 deletions(-) delete mode 100644 asm/non_matchings/unknown_065D30/__allocParam.s delete mode 100644 asm/non_matchings/unknown_065D30/__collectPVoices.s delete mode 100644 asm/non_matchings/unknown_065D30/__freePVoices.s delete mode 100644 asm/non_matchings/unknown_065D30/__freeParam.s delete mode 100644 asm/non_matchings/unknown_065D30/__nextSampleTime.s delete mode 100644 asm/non_matchings/unknown_065D30/__timeToSamples.s delete mode 100644 asm/non_matchings/unknown_065D30/__timeToSamplesNoRound.s delete mode 100644 asm/non_matchings/unknown_065D30/alAudioFrame.s rename {asm/non_matchings/unknown_065D30 => lib/asm/non_matchings/synthesizer}/alSynNew.s (100%) create mode 100644 lib/src/mips1/al/synthesizer.c delete mode 100644 src/unknown_065D30.c delete mode 100644 src/unknown_065D30.h diff --git a/asm/non_matchings/unknown_065D30/__allocParam.s b/asm/non_matchings/unknown_065D30/__allocParam.s deleted file mode 100644 index 096cc1d7..00000000 --- a/asm/non_matchings/unknown_065D30/__allocParam.s +++ /dev/null @@ -1,16 +0,0 @@ -glabel __allocParam -/* 066268 80065668 3C02800E */ lui $v0, %hi(alGlobals) # $v0, 0x800e -/* 06626C 8006566C 8C423780 */ lw $v0, %lo(alGlobals)($v0) -/* 066270 80065670 00001825 */ move $v1, $zero -/* 066274 80065674 8C44002C */ lw $a0, 0x2c($v0) -/* 066278 80065678 00000000 */ nop -/* 06627C 8006567C 10800005 */ beqz $a0, .L80065694 -/* 066280 80065680 00000000 */ nop -/* 066284 80065684 8C8E0000 */ lw $t6, ($a0) -/* 066288 80065688 00801825 */ move $v1, $a0 -/* 06628C 8006568C AC4E002C */ sw $t6, 0x2c($v0) -/* 066290 80065690 AC800000 */ sw $zero, ($a0) -.L80065694: -/* 066294 80065694 03E00008 */ jr $ra -/* 066298 80065698 00601025 */ move $v0, $v1 - diff --git a/asm/non_matchings/unknown_065D30/__collectPVoices.s b/asm/non_matchings/unknown_065D30/__collectPVoices.s deleted file mode 100644 index e43cb395..00000000 --- a/asm/non_matchings/unknown_065D30/__collectPVoices.s +++ /dev/null @@ -1,28 +0,0 @@ -glabel __collectPVoices -/* 0662BC 800656BC 27BDFFD8 */ addiu $sp, $sp, -0x28 -/* 0662C0 800656C0 AFBF0024 */ sw $ra, 0x24($sp) -/* 0662C4 800656C4 AFB20020 */ sw $s2, 0x20($sp) -/* 0662C8 800656C8 AFB1001C */ sw $s1, 0x1c($sp) -/* 0662CC 800656CC AFB00018 */ sw $s0, 0x18($sp) -/* 0662D0 800656D0 8C900014 */ lw $s0, 0x14($a0) -/* 0662D4 800656D4 00808825 */ move $s1, $a0 -/* 0662D8 800656D8 1200000A */ beqz $s0, .L80065704 -/* 0662DC 800656DC 24920004 */ addiu $s2, $a0, 4 -.L800656E0: -/* 0662E0 800656E0 0C0321D8 */ jal alUnlink -/* 0662E4 800656E4 02002025 */ move $a0, $s0 -/* 0662E8 800656E8 02002025 */ move $a0, $s0 -/* 0662EC 800656EC 0C0321E4 */ jal alLink -/* 0662F0 800656F0 02402825 */ move $a1, $s2 -/* 0662F4 800656F4 8E300014 */ lw $s0, 0x14($s1) -/* 0662F8 800656F8 00000000 */ nop -/* 0662FC 800656FC 1600FFF8 */ bnez $s0, .L800656E0 -/* 066300 80065700 00000000 */ nop -.L80065704: -/* 066304 80065704 8FBF0024 */ lw $ra, 0x24($sp) -/* 066308 80065708 8FB00018 */ lw $s0, 0x18($sp) -/* 06630C 8006570C 8FB1001C */ lw $s1, 0x1c($sp) -/* 066310 80065710 8FB20020 */ lw $s2, 0x20($sp) -/* 066314 80065714 03E00008 */ jr $ra -/* 066318 80065718 27BD0028 */ addiu $sp, $sp, 0x28 - diff --git a/asm/non_matchings/unknown_065D30/__freePVoices.s b/asm/non_matchings/unknown_065D30/__freePVoices.s deleted file mode 100644 index 1e2d0855..00000000 --- a/asm/non_matchings/unknown_065D30/__freePVoices.s +++ /dev/null @@ -1,16 +0,0 @@ -glabel __freePVoices -/* 06631C 8006571C 27BDFFE8 */ addiu $sp, $sp, -0x18 -/* 066320 80065720 AFBF0014 */ sw $ra, 0x14($sp) -/* 066324 80065724 AFA40018 */ sw $a0, 0x18($sp) -/* 066328 80065728 AFA5001C */ sw $a1, 0x1c($sp) -/* 06632C 8006572C 0C0321D8 */ jal alUnlink -/* 066330 80065730 00A02025 */ move $a0, $a1 -/* 066334 80065734 8FA50018 */ lw $a1, 0x18($sp) -/* 066338 80065738 8FA4001C */ lw $a0, 0x1c($sp) -/* 06633C 8006573C 0C0321E4 */ jal alLink -/* 066340 80065740 24A50014 */ addiu $a1, $a1, 0x14 -/* 066344 80065744 8FBF0014 */ lw $ra, 0x14($sp) -/* 066348 80065748 27BD0018 */ addiu $sp, $sp, 0x18 -/* 06634C 8006574C 03E00008 */ jr $ra -/* 066350 80065750 00000000 */ nop - diff --git a/asm/non_matchings/unknown_065D30/__freeParam.s b/asm/non_matchings/unknown_065D30/__freeParam.s deleted file mode 100644 index d3c77f41..00000000 --- a/asm/non_matchings/unknown_065D30/__freeParam.s +++ /dev/null @@ -1,10 +0,0 @@ -glabel __freeParam -/* 06629C 8006569C 3C02800E */ lui $v0, %hi(alGlobals) # $v0, 0x800e -/* 0662A0 800656A0 8C423780 */ lw $v0, %lo(alGlobals)($v0) -/* 0662A4 800656A4 00000000 */ nop -/* 0662A8 800656A8 8C4E002C */ lw $t6, 0x2c($v0) -/* 0662AC 800656AC 00000000 */ nop -/* 0662B0 800656B0 AC8E0000 */ sw $t6, ($a0) -/* 0662B4 800656B4 03E00008 */ jr $ra -/* 0662B8 800656B8 AC44002C */ sw $a0, 0x2c($v0) - diff --git a/asm/non_matchings/unknown_065D30/__nextSampleTime.s b/asm/non_matchings/unknown_065D30/__nextSampleTime.s deleted file mode 100644 index 3567a321..00000000 --- a/asm/non_matchings/unknown_065D30/__nextSampleTime.s +++ /dev/null @@ -1,35 +0,0 @@ -glabel __nextSampleTime -/* 0663EC 800657EC ACA00000 */ sw $zero, ($a1) -/* 0663F0 800657F0 8C830000 */ lw $v1, ($a0) -/* 0663F4 800657F4 3C027FFF */ lui $v0, (0x7FFFFFFF >> 16) # lui $v0, 0x7fff -/* 0663F8 800657F8 10600012 */ beqz $v1, .L80065844 -/* 0663FC 800657FC 3442FFFF */ ori $v0, (0x7FFFFFFF & 0xFFFF) # ori $v0, $v0, 0xffff -/* 066400 80065800 8C860020 */ lw $a2, 0x20($a0) -/* 066404 80065804 00000000 */ nop -.L80065808: -/* 066408 80065808 8C6E0010 */ lw $t6, 0x10($v1) -/* 06640C 8006580C 00000000 */ nop -/* 066410 80065810 01C67823 */ subu $t7, $t6, $a2 -/* 066414 80065814 01E2082A */ slt $at, $t7, $v0 -/* 066418 80065818 10200006 */ beqz $at, .L80065834 -/* 06641C 8006581C 00000000 */ nop -/* 066420 80065820 ACA30000 */ sw $v1, ($a1) -/* 066424 80065824 8C780010 */ lw $t8, 0x10($v1) -/* 066428 80065828 8C860020 */ lw $a2, 0x20($a0) -/* 06642C 8006582C 00000000 */ nop -/* 066430 80065830 03061023 */ subu $v0, $t8, $a2 -.L80065834: -/* 066434 80065834 8C630000 */ lw $v1, ($v1) -/* 066438 80065838 00000000 */ nop -/* 06643C 8006583C 1460FFF2 */ bnez $v1, .L80065808 -/* 066440 80065840 00000000 */ nop -.L80065844: -/* 066444 80065844 8CB90000 */ lw $t9, ($a1) -/* 066448 80065848 00000000 */ nop -/* 06644C 8006584C 8F220010 */ lw $v0, 0x10($t9) -/* 066450 80065850 03E00008 */ jr $ra -/* 066454 80065854 00000000 */ nop - -/* 066458 80065858 00000000 */ nop -/* 06645C 8006585C 00000000 */ nop - diff --git a/asm/non_matchings/unknown_065D30/__timeToSamples.s b/asm/non_matchings/unknown_065D30/__timeToSamples.s deleted file mode 100644 index 2a142dc4..00000000 --- a/asm/non_matchings/unknown_065D30/__timeToSamples.s +++ /dev/null @@ -1,12 +0,0 @@ -glabel __timeToSamples -/* 0663C4 800657C4 27BDFFE8 */ addiu $sp, $sp, -0x18 -/* 0663C8 800657C8 AFBF0014 */ sw $ra, 0x14($sp) -/* 0663CC 800657CC 0C0195D5 */ jal __timeToSamplesNoRound -/* 0663D0 800657D0 00000000 */ nop -/* 0663D4 800657D4 8FBF0014 */ lw $ra, 0x14($sp) -/* 0663D8 800657D8 2401FFF0 */ li $at, -16 -/* 0663DC 800657DC 00417024 */ and $t6, $v0, $at -/* 0663E0 800657E0 01C01025 */ move $v0, $t6 -/* 0663E4 800657E4 03E00008 */ jr $ra -/* 0663E8 800657E8 27BD0018 */ addiu $sp, $sp, 0x18 - diff --git a/asm/non_matchings/unknown_065D30/__timeToSamplesNoRound.s b/asm/non_matchings/unknown_065D30/__timeToSamplesNoRound.s deleted file mode 100644 index 6a10fe67..00000000 --- a/asm/non_matchings/unknown_065D30/__timeToSamplesNoRound.s +++ /dev/null @@ -1,35 +0,0 @@ -.late_rodata -glabel D_800E6EC0 -.double 1000000.0 - -.text -glabel __timeToSamplesNoRound -/* 066354 80065754 8C8E0044 */ lw $t6, 0x44($a0) -/* 066358 80065758 44852000 */ mtc1 $a1, $f4 -/* 06635C 8006575C 448E4000 */ mtc1 $t6, $f8 -/* 066360 80065760 468021A0 */ cvt.s.w $f6, $f4 -/* 066364 80065764 3C01800E */ lui $at, %hi(D_800E6EC0 + 4) # $at, 0x800e -/* 066368 80065768 C4256EC0 */ lwc1 $f5, %lo(D_800E6EC0)($at) -/* 06636C 8006576C 468042A0 */ cvt.s.w $f10, $f8 -/* 066370 80065770 C4246EC4 */ lwc1 $f4, %lo(D_800E6EC0 + 4)($at) -/* 066374 80065774 3C013FE0 */ li $at, 0x3FE00000 # 1.750000 -/* 066378 80065778 460A3402 */ mul.s $f16, $f6, $f10 -/* 06637C 8006577C 44803000 */ mtc1 $zero, $f6 -/* 066380 80065780 44813800 */ mtc1 $at, $f7 -/* 066384 80065784 460084A1 */ cvt.d.s $f18, $f16 -/* 066388 80065788 00000000 */ nop -/* 06638C 8006578C 46249203 */ div.d $f8, $f18, $f4 -/* 066390 80065790 46264280 */ add.d $f10, $f8, $f6 -/* 066394 80065794 46205020 */ cvt.s.d $f0, $f10 -/* 066398 80065798 444FF800 */ cfc1 $t7, $31 -/* 06639C 8006579C 00000000 */ nop -/* 0663A0 800657A0 35E10003 */ ori $at, $t7, 3 -/* 0663A4 800657A4 38210002 */ xori $at, $at, 2 -/* 0663A8 800657A8 44C1F800 */ ctc1 $at, $31 -/* 0663AC 800657AC 00000000 */ nop -/* 0663B0 800657B0 46000424 */ cvt.w.s $f16, $f0 -/* 0663B4 800657B4 44028000 */ mfc1 $v0, $f16 -/* 0663B8 800657B8 44CFF800 */ ctc1 $t7, $31 -/* 0663BC 800657BC 03E00008 */ jr $ra -/* 0663C0 800657C0 00000000 */ nop - diff --git a/asm/non_matchings/unknown_065D30/alAudioFrame.s b/asm/non_matchings/unknown_065D30/alAudioFrame.s deleted file mode 100644 index d5a72ed5..00000000 --- a/asm/non_matchings/unknown_065D30/alAudioFrame.s +++ /dev/null @@ -1,126 +0,0 @@ -glabel alAudioFrame -/* 066094 80065494 27BDFF90 */ addiu $sp, $sp, -0x70 -/* 066098 80065498 AFB20024 */ sw $s2, 0x24($sp) -/* 06609C 8006549C 3C12800E */ lui $s2, %hi(alGlobals) # $s2, 0x800e -/* 0660A0 800654A0 8E523780 */ lw $s2, %lo(alGlobals)($s2) -/* 0660A4 800654A4 AFBF003C */ sw $ra, 0x3c($sp) -/* 0660A8 800654A8 AFB70038 */ sw $s7, 0x38($sp) -/* 0660AC 800654AC AFB60034 */ sw $s6, 0x34($sp) -/* 0660B0 800654B0 AFB50030 */ sw $s5, 0x30($sp) -/* 0660B4 800654B4 AFB4002C */ sw $s4, 0x2c($sp) -/* 0660B8 800654B8 AFB30028 */ sw $s3, 0x28($sp) -/* 0660BC 800654BC AFB10020 */ sw $s1, 0x20($sp) -/* 0660C0 800654C0 AFB0001C */ sw $s0, 0x1c($sp) -/* 0660C4 800654C4 AFA50074 */ sw $a1, 0x74($sp) -/* 0660C8 800654C8 A7A00062 */ sh $zero, 0x62($sp) -/* 0660CC 800654CC 8E4E0000 */ lw $t6, ($s2) -/* 0660D0 800654D0 00808825 */ move $s1, $a0 -/* 0660D4 800654D4 00E09825 */ move $s3, $a3 -/* 0660D8 800654D8 0080A025 */ move $s4, $a0 -/* 0660DC 800654DC 15C00004 */ bnez $t6, .L800654F0 -/* 0660E0 800654E0 00C0A825 */ move $s5, $a2 -/* 0660E4 800654E4 ACA00000 */ sw $zero, ($a1) -/* 0660E8 800654E8 10000054 */ b .L8006563C -/* 0660EC 800654EC 00801025 */ move $v0, $a0 -.L800654F0: -/* 0660F0 800654F0 27B0006C */ addiu $s0, $sp, 0x6c -/* 0660F4 800654F4 02002825 */ move $a1, $s0 -/* 0660F8 800654F8 02402025 */ move $a0, $s2 -/* 0660FC 800654FC 0C0195FB */ jal __nextSampleTime -/* 066100 80065500 AFB10070 */ sw $s1, 0x70($sp) -/* 066104 80065504 8E580020 */ lw $t8, 0x20($s2) -/* 066108 80065508 AE42001C */ sw $v0, 0x1c($s2) -/* 06610C 8006550C 0058C823 */ subu $t9, $v0, $t8 -/* 066110 80065510 0333082A */ slt $at, $t9, $s3 -/* 066114 80065514 1020001B */ beqz $at, .L80065584 -/* 066118 80065518 2411FFF0 */ li $s1, -16 -.L8006551C: -/* 06611C 8006551C 8E48001C */ lw $t0, 0x1c($s2) -/* 066120 80065520 00000000 */ nop -/* 066124 80065524 01114824 */ and $t1, $t0, $s1 -/* 066128 80065528 AE49001C */ sw $t1, 0x1c($s2) -/* 06612C 8006552C 8FA4006C */ lw $a0, 0x6c($sp) -/* 066130 80065530 00000000 */ nop -/* 066134 80065534 8C990008 */ lw $t9, 8($a0) -/* 066138 80065538 00000000 */ nop -/* 06613C 8006553C 0320F809 */ jalr $t9 -/* 066140 80065540 00000000 */ nop -/* 066144 80065544 02402025 */ move $a0, $s2 -/* 066148 80065548 0C0195D5 */ jal __timeToSamplesNoRound -/* 06614C 8006554C 00402825 */ move $a1, $v0 -/* 066150 80065550 8FAB006C */ lw $t3, 0x6c($sp) -/* 066154 80065554 02402025 */ move $a0, $s2 -/* 066158 80065558 8D6C0010 */ lw $t4, 0x10($t3) -/* 06615C 8006555C 02002825 */ move $a1, $s0 -/* 066160 80065560 01826821 */ addu $t5, $t4, $v0 -/* 066164 80065564 0C0195FB */ jal __nextSampleTime -/* 066168 80065568 AD6D0010 */ sw $t5, 0x10($t3) -/* 06616C 8006556C 8E4E0020 */ lw $t6, 0x20($s2) -/* 066170 80065570 AE42001C */ sw $v0, 0x1c($s2) -/* 066174 80065574 004E7823 */ subu $t7, $v0, $t6 -/* 066178 80065578 01F3082A */ slt $at, $t7, $s3 -/* 06617C 8006557C 1420FFE7 */ bnez $at, .L8006551C -/* 066180 80065580 00000000 */ nop -.L80065584: -/* 066184 80065584 8E58001C */ lw $t8, 0x1c($s2) -/* 066188 80065588 2411FFF0 */ li $s1, -16 -/* 06618C 8006558C 03114024 */ and $t0, $t8, $s1 -/* 066190 80065590 1A600022 */ blez $s3, .L8006561C -/* 066194 80065594 AE48001C */ sw $t0, 0x1c($s2) -/* 066198 80065598 27B70062 */ addiu $s7, $sp, 0x62 -/* 06619C 8006559C 3C160700 */ lui $s6, 0x700 -.L800655A0: -/* 0661A0 800655A0 8E420048 */ lw $v0, 0x48($s2) -/* 0661A4 800655A4 02608025 */ move $s0, $s3 -/* 0661A8 800655A8 0053082A */ slt $at, $v0, $s3 -/* 0661AC 800655AC 10200003 */ beqz $at, .L800655BC -/* 0661B0 800655B0 00000000 */ nop -/* 0661B4 800655B4 10000001 */ b .L800655BC -/* 0661B8 800655B8 00408025 */ move $s0, $v0 -.L800655BC: -/* 0661BC 800655BC AE960000 */ sw $s6, ($s4) -/* 0661C0 800655C0 AE800004 */ sw $zero, 4($s4) -/* 0661C4 800655C4 8E510038 */ lw $s1, 0x38($s2) -/* 0661C8 800655C8 24050006 */ li $a1, 6 -/* 0661CC 800655CC 8E390008 */ lw $t9, 8($s1) -/* 0661D0 800655D0 02A03025 */ move $a2, $s5 -/* 0661D4 800655D4 0320F809 */ jalr $t9 -/* 0661D8 800655D8 02202025 */ move $a0, $s1 -/* 0661DC 800655DC 8E470020 */ lw $a3, 0x20($s2) -/* 0661E0 800655E0 26890008 */ addiu $t1, $s4, 8 -/* 0661E4 800655E4 AFA90010 */ sw $t1, 0x10($sp) -/* 0661E8 800655E8 8E390004 */ lw $t9, 4($s1) -/* 0661EC 800655EC 02202025 */ move $a0, $s1 -/* 0661F0 800655F0 02E02825 */ move $a1, $s7 -/* 0661F4 800655F4 0320F809 */ jalr $t9 -/* 0661F8 800655F8 02003025 */ move $a2, $s0 -/* 0661FC 800655FC 8E4D0020 */ lw $t5, 0x20($s2) -/* 066200 80065600 02709823 */ subu $s3, $s3, $s0 -/* 066204 80065604 00106080 */ sll $t4, $s0, 2 -/* 066208 80065608 01B05821 */ addu $t3, $t5, $s0 -/* 06620C 8006560C 0040A025 */ move $s4, $v0 -/* 066210 80065610 02ACA821 */ addu $s5, $s5, $t4 -/* 066214 80065614 1E60FFE2 */ bgtz $s3, .L800655A0 -/* 066218 80065618 AE4B0020 */ sw $t3, 0x20($s2) -.L8006561C: -/* 06621C 8006561C 8FAE0070 */ lw $t6, 0x70($sp) -/* 066220 80065620 8FA80074 */ lw $t0, 0x74($sp) -/* 066224 80065624 028E7823 */ subu $t7, $s4, $t6 -/* 066228 80065628 000FC0C3 */ sra $t8, $t7, 3 -/* 06622C 8006562C 02402025 */ move $a0, $s2 -/* 066230 80065630 0C0195AF */ jal __collectPVoices -/* 066234 80065634 AD180000 */ sw $t8, ($t0) -/* 066238 80065638 02801025 */ move $v0, $s4 -.L8006563C: -/* 06623C 8006563C 8FBF003C */ lw $ra, 0x3c($sp) -/* 066240 80065640 8FB0001C */ lw $s0, 0x1c($sp) -/* 066244 80065644 8FB10020 */ lw $s1, 0x20($sp) -/* 066248 80065648 8FB20024 */ lw $s2, 0x24($sp) -/* 06624C 8006564C 8FB30028 */ lw $s3, 0x28($sp) -/* 066250 80065650 8FB4002C */ lw $s4, 0x2c($sp) -/* 066254 80065654 8FB50030 */ lw $s5, 0x30($sp) -/* 066258 80065658 8FB60034 */ lw $s6, 0x34($sp) -/* 06625C 8006565C 8FB70038 */ lw $s7, 0x38($sp) -/* 066260 80065660 03E00008 */ jr $ra -/* 066264 80065664 27BD0070 */ addiu $sp, $sp, 0x70 - diff --git a/include/PR/libaudio.h b/include/PR/libaudio.h index 93f0ef3a..9439df2e 100644 --- a/include/PR/libaudio.h +++ b/include/PR/libaudio.h @@ -264,8 +264,7 @@ typedef struct { void *dmaproc; ALHeap *heap; s32 outputRate; /* output sample rate */ - ALFxId fxType; - u8 unk1d; + ALFxId fxType[2]; s32 *params; } ALSynConfig; diff --git a/include/audio_internal.h b/include/audio_internal.h index b76d73e9..e1790d48 100644 --- a/include/audio_internal.h +++ b/include/audio_internal.h @@ -264,6 +264,7 @@ typedef struct PVoice_s { ALResampler resampler; ALEnvMixer envmixer; s32 offset; + s32 unkDC; } PVoice; #endif diff --git a/asm/non_matchings/unknown_065D30/alSynNew.s b/lib/asm/non_matchings/synthesizer/alSynNew.s similarity index 100% rename from asm/non_matchings/unknown_065D30/alSynNew.s rename to lib/asm/non_matchings/synthesizer/alSynNew.s diff --git a/lib/src/mips1/al/synthesizer.c b/lib/src/mips1/al/synthesizer.c new file mode 100644 index 00000000..5396d50f --- /dev/null +++ b/lib/src/mips1/al/synthesizer.c @@ -0,0 +1,218 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x80065130 */ + +#include "types.h" +#include "audio_internal.h" +#include "macros.h" + +#ifdef NON_MATCHING + +s32 __nextSampleTime(ALSynth *drvr, ALPlayer **client); +s32 _timeToSamplesNoRound(ALSynth *ALSynth, s32 micros); + +// Regalloc issue. s7 and s8 need to swap places; there is also an extra 8 bytes on the stack. +void alSynNew(ALSynth *drvr, ALSynConfig *c) +{ + s32 i; + ALVoice *vv; + PVoice *pv; + ALVoice *vvoices; + PVoice *pvoices; + ALHeap *hp = c->heap; + ALSave *save; + ALFilter *sources; + ALParam *params; + ALParam *paramPtr; + + drvr->head = NULL; + drvr->numPVoices = c->maxPVoices; + drvr->curSamples = 0; + drvr->paramSamples = 0; + drvr->outputRate = c->outputRate; + drvr->maxOutSamples = AL_MAX_RSP_SAMPLES; + drvr->dma = (ALDMANew) c->dmaproc; + + save = alHeapAlloc(hp, 1, sizeof(ALSave)); + alSaveNew(save); + drvr->outputFilter = (ALFilter *)save; + + drvr->auxBus = alHeapAlloc(hp, 2, sizeof(ALAuxBus)); + drvr->maxAuxBusses = 2; + sources = alHeapAlloc(hp, c->maxPVoices, sizeof(ALFilter *)); + alAuxBusNew(drvr->auxBus, sources, c->maxPVoices); + + sources = alHeapAlloc(hp, c->maxPVoices, sizeof(ALFilter *)); + alAuxBusNew(drvr->auxBus + 1, sources, c->maxPVoices); + + drvr->mainBus = alHeapAlloc(hp, 1, sizeof(ALMainBus)); + sources = alHeapAlloc(hp, c->maxPVoices, sizeof(ALFilter *)); + alMainBusNew(drvr->mainBus, sources, c->maxPVoices); + + for(i = 0; i < 2; i++) { + if (c->fxType[i] != 0) { + alSynAllocFX(drvr, (s16)i, c, c); + } else { + alMainBusParam(drvr->mainBus, 2, drvr->auxBus + i); + } + } + + drvr->pFreeList.next = 0; + drvr->pFreeList.prev = 0; + drvr->pLameList.next = 0; + drvr->pLameList.prev = 0; + drvr->pAllocList.next = 0; + drvr->pAllocList.prev = 0; + + pvoices = alHeapAlloc(hp, c->maxPVoices, sizeof(PVoice)); + for (i = 0; i < c->maxPVoices; i++) { + pv = &pvoices[i]; + alLink((ALLink *)pv, &drvr->pFreeList); + pv->vvoice = 0; + + alLoadNew(&pv->decoder, drvr->dma, hp); + alLoadParam(&pv->decoder, AL_FILTER_SET_SOURCE, 0); + + alResampleNew(&pv->resampler, hp); + alResampleParam(&pv->resampler, AL_FILTER_SET_SOURCE, &pv->decoder); + + alEnvmixerNew(&pv->envmixer, hp); + alEnvmixerParam(&pv->envmixer, AL_FILTER_SET_SOURCE, &pv->resampler); + + alAuxBusParam(drvr->auxBus, AL_FILTER_ADD_SOURCE, &pv->envmixer); + + pv->channelKnob = (ALFilter *)&pv->envmixer; + } + + alSaveParam(save, AL_FILTER_SET_SOURCE, drvr->mainBus); + + params = alHeapAlloc(hp, c->maxUpdates, sizeof(ALParam)); + drvr->paramList = 0; + for (i = 0; i < c->maxUpdates; i++) { + paramPtr= ¶ms[i]; + paramPtr->next = drvr->paramList; + drvr->paramList = paramPtr; + } + + drvr->heap = hp; +} +#else +GLOBAL_ASM("lib/asm/non_matchings/synthesizer/alSynNew.s") +#endif + +void __collectPVoices(ALSynth *drvr); +s32 __timeToSamplesNoRound(ALSynth *synth, s32 micros); + +Acmd *alAudioFrame(Acmd *cmdList, s32 *cmdLen, s16 *outBuf, s32 outLen) +{ + ALPlayer *client; + ALFilter *output; + ALSynth *drvr = &alGlobals->drvr; + s16 tmp = 0; /* Starting buffer in DMEM */ + Acmd *cmdlEnd = cmdList; + Acmd *cmdPtr; + s32 nOut; + s16 *lOutBuf = outBuf; + + if (drvr->head == 0) { + *cmdLen = 0; + return cmdList; /* nothing to do */ + } + + for (drvr->paramSamples = __nextSampleTime(drvr, &client); + drvr->paramSamples - drvr->curSamples < outLen; + drvr->paramSamples = __nextSampleTime(drvr, &client)) + { + drvr->paramSamples &= ~0xf; + client->samplesLeft += __timeToSamplesNoRound(drvr, (*client->handler)(client)); + } + + drvr->paramSamples &= ~0xf; + + while (outLen > 0){ + nOut = MIN(drvr->maxOutSamples, outLen); + + cmdPtr = cmdlEnd; + aSegment(cmdPtr++, 0, 0); + output = drvr->outputFilter; + (*output->setParam)(output, AL_FILTER_SET_DRAM, lOutBuf); + cmdlEnd = (*output->handler)(output, &tmp, nOut, drvr->curSamples, + cmdPtr); + + outLen -= nOut; + lOutBuf += nOut<<1; + drvr->curSamples += nOut; + + } + *cmdLen = (s32) (cmdlEnd - cmdList); + + __collectPVoices(drvr); + + return cmdlEnd; +} + +ALParam *__allocParam() +{ + ALParam *update = 0; + ALSynth *drvr = &alGlobals->drvr; + + if (drvr->paramList) { + update = drvr->paramList; + drvr->paramList = drvr->paramList->next; + update->next = 0; + } + return update; +} + +void __freeParam(ALParam *param) +{ + ALSynth *drvr = &alGlobals->drvr; + param->next = drvr->paramList; + drvr->paramList = param; +} + +void __collectPVoices(ALSynth *drvr) +{ + ALLink *dl; + PVoice *pv; + + while ((dl = drvr->pLameList.next) != 0) { + pv = (PVoice *)dl; + alUnlink(dl); + alLink(dl, &drvr->pFreeList); + } +} + +void __freePVoices(ALSynth *drvr, PVoice *pvoice) +{ + alUnlink((ALLink *)pvoice); + alLink((ALLink *)pvoice, &drvr->pLameList); +} + +s32 __timeToSamplesNoRound(ALSynth *synth, s32 micros) +{ + f32 tmp = ((f32)micros) * synth->outputRate / 1000000.0 + 0.5; + + return (s32)tmp; +} + +s32 __timeToSamples(ALSynth *synth, s32 micros) +{ + return __timeToSamplesNoRound(synth, micros) & ~0xF; +} + +s32 __nextSampleTime(ALSynth *drvr, ALPlayer **client) +{ + ALMicroTime delta = 0x7fffffff; + ALPlayer *cl; + + *client = 0; + + for (cl = drvr->head; cl != 0; cl = cl->next) { + if ((cl->samplesLeft - drvr->curSamples) < delta) { + *client = cl; + delta = cl->samplesLeft - drvr->curSamples; + } + } + + return (*client)->samplesLeft; +} diff --git a/src/audio.c b/src/audio.c index c0ce6845..31a2ab2c 100644 --- a/src/audio.c +++ b/src/audio.c @@ -184,8 +184,8 @@ void audio_init(u32 arg0){ synth_config.maxPVoices = 40; synth_config.maxUpdates = 96; synth_config.dmaproc = NULL; - synth_config.fxType = 6; - synth_config.unk1d = 2; + synth_config.fxType[0] = 6; + synth_config.fxType[1] = 2; synth_config.outputRate = 0; synth_config.heap = &gALHeap; audioNewThread(&synth_config, 12, arg0); diff --git a/src/unknown_065D30.c b/src/unknown_065D30.c deleted file mode 100644 index 1dae06ef..00000000 --- a/src/unknown_065D30.c +++ /dev/null @@ -1,17 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x80065130 */ - -#include "unknown_065D30.h" - -#include "types.h" -#include "macros.h" - -GLOBAL_ASM("asm/non_matchings/unknown_065D30/alSynNew.s") -GLOBAL_ASM("asm/non_matchings/unknown_065D30/alAudioFrame.s") -GLOBAL_ASM("asm/non_matchings/unknown_065D30/__allocParam.s") -GLOBAL_ASM("asm/non_matchings/unknown_065D30/__freeParam.s") -GLOBAL_ASM("asm/non_matchings/unknown_065D30/__collectPVoices.s") -GLOBAL_ASM("asm/non_matchings/unknown_065D30/__freePVoices.s") -GLOBAL_ASM("asm/non_matchings/unknown_065D30/__timeToSamplesNoRound.s") -GLOBAL_ASM("asm/non_matchings/unknown_065D30/__timeToSamples.s") -GLOBAL_ASM("asm/non_matchings/unknown_065D30/__nextSampleTime.s") diff --git a/src/unknown_065D30.h b/src/unknown_065D30.h deleted file mode 100644 index 727dccc7..00000000 --- a/src/unknown_065D30.h +++ /dev/null @@ -1,4 +0,0 @@ -#ifndef _UNKNOWN_065D30_H_ -#define _UNKNOWN_065D30_H_ - -#endif \ No newline at end of file