diff --git a/Makefile b/Makefile index 47a07a616..56d41ebde 100644 --- a/Makefile +++ b/Makefile @@ -159,7 +159,7 @@ GRUCODE_CFLAGS = -DF3DEX_GBI -D_LANGUAGE_C CC_CHECK := gcc -fsyntax-only -fsigned-char $(CC_CFLAGS) $(TARGET_CFLAGS) $(INCLUDE_CFLAGS) -std=gnu90 -Wall -Wextra -Wno-format-security -Wno-main -DNON_MATCHING -DAVOID_UB $(VERSION_CFLAGS) $(GRUCODE_CFLAGS) ASFLAGS = -march=vr4300 -mabi=32 -I include -I $(BUILD_DIR) --defsym F3DEX_GBI=1 -CFLAGS = -Wab,-r4300_mul -non_shared -G 0 -Xcpluscomm -Xfullwarn -signed $(OPT_FLAGS) $(TARGET_CFLAGS) $(INCLUDE_CFLAGS) $(MIPSISET) $(GRUCODE_CFLAGS) +CFLAGS = -Wab,-r4300_mul -non_shared -G 0 -Xcpluscomm -Xfullwarn -signed $(OPT_FLAGS) $(TARGET_CFLAGS) $(INCLUDE_CFLAGS) $(VERSION_CFLAGS) $(MIPSISET) $(GRUCODE_CFLAGS) OBJCOPYFLAGS = --pad-to=0xC00000 --gap-fill=0xFF LDFLAGS = -T undefined_syms.txt -T $(BUILD_DIR)/$(LD_SCRIPT) -Map $(BUILD_DIR)/$(TARGET).map --no-check-sections diff --git a/asm/non_matchings/audio/synthesis/func_800B6F1C.s b/asm/non_matchings/audio/synthesis/func_800B6F1C.s deleted file mode 100644 index 77f02a23b..000000000 --- a/asm/non_matchings/audio/synthesis/func_800B6F1C.s +++ /dev/null @@ -1,39 +0,0 @@ -glabel func_800B6F1C -/* 0B7B1C 800B6F1C 00074103 */ sra $t0, $a3, 4 -/* 0B7B20 800B6F20 AFA50004 */ sw $a1, 4($sp) -/* 0B7B24 800B6F24 00A07025 */ move $t6, $a1 -/* 0B7B28 800B6F28 311800FF */ andi $t8, $t0, 0xff -/* 0B7B2C 800B6F2C 01C02825 */ move $a1, $t6 -/* 0B7B30 800B6F30 AFA60008 */ sw $a2, 8($sp) -/* 0B7B34 800B6F34 30CFFFFF */ andi $t7, $a2, 0xffff -/* 0B7B38 800B6F38 0018CC00 */ sll $t9, $t8, 0x10 -/* 0B7B3C 800B6F3C 3C011500 */ lui $at, 0x1500 -/* 0B7B40 800B6F40 01E03025 */ move $a2, $t7 -/* 0B7B44 800B6F44 03214025 */ or $t0, $t9, $at -/* 0B7B48 800B6F48 31CEFFFF */ andi $t6, $t6, 0xffff -/* 0B7B4C 800B6F4C 010E7825 */ or $t7, $t0, $t6 -/* 0B7B50 800B6F50 AC8F0000 */ sw $t7, ($a0) -/* 0B7B54 800B6F54 8FB80010 */ lw $t8, 0x10($sp) -/* 0B7B58 800B6F58 3C0D803B */ lui $t5, %hi(gSynthesisReverbs) # $t5, 0x803b -/* 0B7B5C 800B6F5C 25ADF790 */ addiu $t5, %lo(gSynthesisReverbs) # addiu $t5, $t5, -0x870 -/* 0B7B60 800B6F60 0018C940 */ sll $t9, $t8, 5 -/* 0B7B64 800B6F64 0338C821 */ addu $t9, $t9, $t8 -/* 0B7B68 800B6F68 0019C8C0 */ sll $t9, $t9, 3 -/* 0B7B6C 800B6F6C 032D4821 */ addu $t1, $t9, $t5 -/* 0B7B70 800B6F70 8D2E0018 */ lw $t6, 0x18($t1) -/* 0B7B74 800B6F74 00065040 */ sll $t2, $a2, 1 -/* 0B7B78 800B6F78 3C0C8000 */ lui $t4, 0x8000 -/* 0B7B7C 800B6F7C 24B90180 */ addiu $t9, $a1, 0x180 -/* 0B7B80 800B6F80 01CA7821 */ addu $t7, $t6, $t2 -/* 0B7B84 800B6F84 01ECC021 */ addu $t8, $t7, $t4 -/* 0B7B88 800B6F88 332DFFFF */ andi $t5, $t9, 0xffff -/* 0B7B8C 800B6F8C AC980004 */ sw $t8, 4($a0) -/* 0B7B90 800B6F90 248B0008 */ addiu $t3, $a0, 8 -/* 0B7B94 800B6F94 010D7025 */ or $t6, $t0, $t5 -/* 0B7B98 800B6F98 AD6E0000 */ sw $t6, ($t3) -/* 0B7B9C 800B6F9C 8D2F001C */ lw $t7, 0x1c($t1) -/* 0B7BA0 800B6FA0 25620008 */ addiu $v0, $t3, 8 -/* 0B7BA4 800B6FA4 01EAC021 */ addu $t8, $t7, $t2 -/* 0B7BA8 800B6FA8 030CC821 */ addu $t9, $t8, $t4 -/* 0B7BAC 800B6FAC 03E00008 */ jr $ra -/* 0B7BB0 800B6FB0 AD790004 */ sw $t9, 4($t3) diff --git a/asm/non_matchings/audio/synthesis/func_800B7304.s b/asm/non_matchings/audio/synthesis/func_800B7304.s deleted file mode 100644 index 2671278ec..000000000 --- a/asm/non_matchings/audio/synthesis/func_800B7304.s +++ /dev/null @@ -1,209 +0,0 @@ -glabel func_800B7304 -/* 0B7F04 800B7304 27BDFFA8 */ addiu $sp, $sp, -0x58 -/* 0B7F08 800B7308 AFB10020 */ sw $s1, 0x20($sp) -/* 0B7F0C 800B730C 00068C00 */ sll $s1, $a2, 0x10 -/* 0B7F10 800B7310 00117403 */ sra $t6, $s1, 0x10 -/* 0B7F14 800B7314 000EC940 */ sll $t9, $t6, 5 -/* 0B7F18 800B7318 032EC821 */ addu $t9, $t9, $t6 -/* 0B7F1C 800B731C 3C0D803B */ lui $t5, %hi(gSynthesisReverbs) # $t5, 0x803b -/* 0B7F20 800B7320 25ADF790 */ addiu $t5, %lo(gSynthesisReverbs) # addiu $t5, $t5, -0x870 -/* 0B7F24 800B7324 0019C8C0 */ sll $t9, $t9, 3 -/* 0B7F28 800B7328 01C08825 */ move $s1, $t6 -/* 0B7F2C 800B732C 032D1821 */ addu $v1, $t9, $t5 -/* 0B7F30 800B7330 906E0003 */ lbu $t6, 3($v1) -/* 0B7F34 800B7334 AFA70064 */ sw $a3, 0x64($sp) -/* 0B7F38 800B7338 00077C00 */ sll $t7, $a3, 0x10 -/* 0B7F3C 800B733C 000F3C03 */ sra $a3, $t7, 0x10 -/* 0B7F40 800B7340 000E7880 */ sll $t7, $t6, 2 -/* 0B7F44 800B7344 01EE7823 */ subu $t7, $t7, $t6 -/* 0B7F48 800B7348 000F78C0 */ sll $t7, $t7, 3 -/* 0B7F4C 800B734C 01EE7821 */ addu $t7, $t7, $t6 -/* 0B7F50 800B7350 AFBF0024 */ sw $ra, 0x24($sp) -/* 0B7F54 800B7354 AFB0001C */ sw $s0, 0x1c($sp) -/* 0B7F58 800B7358 AFA5005C */ sw $a1, 0x5c($sp) -/* 0B7F5C 800B735C AFA60060 */ sw $a2, 0x60($sp) -/* 0B7F60 800B7360 3C0D0200 */ lui $t5, (0x02000840 >> 16) # lui $t5, 0x200 -/* 0B7F64 800B7364 000F7880 */ sll $t7, $t7, 2 -/* 0B7F68 800B7368 35AD0840 */ ori $t5, (0x02000840 & 0xFFFF) # ori $t5, $t5, 0x840 -/* 0B7F6C 800B736C 240E0300 */ li $t6, 768 -/* 0B7F70 800B7370 006FC021 */ addu $t8, $v1, $t7 -/* 0B7F74 800B7374 0007C880 */ sll $t9, $a3, 2 -/* 0B7F78 800B7378 AC8E0004 */ sw $t6, 4($a0) -/* 0B7F7C 800B737C AC8D0000 */ sw $t5, ($a0) -/* 0B7F80 800B7380 906F0004 */ lbu $t7, 4($v1) -/* 0B7F84 800B7384 0327C821 */ addu $t9, $t9, $a3 -/* 0B7F88 800B7388 0019C880 */ sll $t9, $t9, 2 -/* 0B7F8C 800B738C 03194021 */ addu $t0, $t8, $t9 -/* 0B7F90 800B7390 24010001 */ li $at, 1 -/* 0B7F94 800B7394 25080030 */ addiu $t0, $t0, 0x30 -/* 0B7F98 800B7398 15E1002D */ bne $t7, $at, .L800B7450 -/* 0B7F9C 800B739C 24900008 */ addiu $s0, $a0, 8 -/* 0B7FA0 800B73A0 9506000E */ lhu $a2, 0xe($t0) -/* 0B7FA4 800B73A4 85070010 */ lh $a3, 0x10($t0) -/* 0B7FA8 800B73A8 AFA80054 */ sw $t0, 0x54($sp) -/* 0B7FAC 800B73AC AFA30028 */ sw $v1, 0x28($sp) -/* 0B7FB0 800B73B0 AFB10010 */ sw $s1, 0x10($sp) -/* 0B7FB4 800B73B4 02002025 */ move $a0, $s0 -/* 0B7FB8 800B73B8 0C02DBA1 */ jal synthesis_load_reverb_ring_buffer -/* 0B7FBC 800B73BC 24050840 */ li $a1, 2112 -/* 0B7FC0 800B73C0 8FA80054 */ lw $t0, 0x54($sp) -/* 0B7FC4 800B73C4 00408025 */ move $s0, $v0 -/* 0B7FC8 800B73C8 8FA30028 */ lw $v1, 0x28($sp) -/* 0B7FCC 800B73CC 85070012 */ lh $a3, 0x12($t0) -/* 0B7FD0 800B73D0 02002025 */ move $a0, $s0 -/* 0B7FD4 800B73D4 00003025 */ move $a2, $zero -/* 0B7FD8 800B73D8 50E0000A */ beql $a3, $zero, .L800B7404 -/* 0B7FDC 800B73DC 3C190C30 */ lui $t9, 0xc30 -/* 0B7FE0 800B73E0 85050010 */ lh $a1, 0x10($t0) -/* 0B7FE4 800B73E4 AFA30028 */ sw $v1, 0x28($sp) -/* 0B7FE8 800B73E8 AFB10010 */ sw $s1, 0x10($sp) -/* 0B7FEC 800B73EC 24A50840 */ addiu $a1, $a1, 0x840 -/* 0B7FF0 800B73F0 30B8FFFF */ andi $t8, $a1, 0xffff -/* 0B7FF4 800B73F4 0C02DBA1 */ jal synthesis_load_reverb_ring_buffer -/* 0B7FF8 800B73F8 03002825 */ move $a1, $t8 -/* 0B7FFC 800B73FC 8FA30028 */ lw $v1, 0x28($sp) -/* 0B8000 800B7400 3C190C30 */ lui $t9, (0x0C307FFF >> 16) # lui $t9, 0xc30 -.L800B7404: -/* 0B8004 800B7404 3C0D0840 */ lui $t5, (0x08400540 >> 16) # lui $t5, 0x840 -/* 0B8008 800B7408 35AD0540 */ ori $t5, (0x08400540 & 0xFFFF) # ori $t5, $t5, 0x540 -/* 0B800C 800B740C 37397FFF */ ori $t9, (0x0C307FFF & 0xFFFF) # ori $t9, $t9, 0x7fff -/* 0B8010 800B7410 AC590000 */ sw $t9, ($v0) -/* 0B8014 800B7414 AC4D0004 */ sw $t5, 4($v0) -/* 0B8018 800B7418 946E0008 */ lhu $t6, 8($v1) -/* 0B801C 800B741C 34018000 */ li $at, 32768 -/* 0B8020 800B7420 24500008 */ addiu $s0, $v0, 8 -/* 0B8024 800B7424 01C17821 */ addu $t7, $t6, $at -/* 0B8028 800B7428 31F8FFFF */ andi $t8, $t7, 0xffff -/* 0B802C 800B742C 3C010C30 */ lui $at, 0xc30 -/* 0B8030 800B7430 02002825 */ move $a1, $s0 -/* 0B8034 800B7434 3C0D0840 */ lui $t5, (0x08400840 >> 16) # lui $t5, 0x840 -/* 0B8038 800B7438 35AD0840 */ ori $t5, (0x08400840 & 0xFFFF) # ori $t5, $t5, 0x840 -/* 0B803C 800B743C 0301C825 */ or $t9, $t8, $at -/* 0B8040 800B7440 ACB90000 */ sw $t9, ($a1) -/* 0B8044 800B7444 ACAD0004 */ sw $t5, 4($a1) -/* 0B8048 800B7448 10000073 */ b .L800B7618 -/* 0B804C 800B744C 26100008 */ addiu $s0, $s0, 8 -.L800B7450: -/* 0B8050 800B7450 8D02000C */ lw $v0, 0xc($t0) -/* 0B8054 800B7454 85190010 */ lh $t9, 0x10($t0) -/* 0B8058 800B7458 2401FFF0 */ li $at, -16 -/* 0B805C 800B745C 304E0007 */ andi $t6, $v0, 7 -/* 0B8060 800B7460 000E7C40 */ sll $t7, $t6, 0x11 -/* 0B8064 800B7464 000FC403 */ sra $t8, $t7, 0x10 -/* 0B8068 800B7468 03195021 */ addu $t2, $t8, $t9 -/* 0B806C 800B746C 254A000F */ addiu $t2, $t2, 0xf -/* 0B8070 800B7470 03004825 */ move $t1, $t8 -/* 0B8074 800B7474 314DFFF0 */ andi $t5, $t2, 0xfff0 -/* 0B8078 800B7478 000D7400 */ sll $t6, $t5, 0x10 -/* 0B807C 800B747C 000E7C03 */ sra $t7, $t6, 0x10 -/* 0B8080 800B7480 01E05025 */ move $t2, $t7 -/* 0B8084 800B7484 A7AA0050 */ sh $t2, 0x50($sp) -/* 0B8088 800B7488 A7A90052 */ sh $t1, 0x52($sp) -/* 0B808C 800B748C AFA80054 */ sw $t0, 0x54($sp) -/* 0B8090 800B7490 AFA30028 */ sw $v1, 0x28($sp) -/* 0B8094 800B7494 AFB10010 */ sw $s1, 0x10($sp) -/* 0B8098 800B7498 02002025 */ move $a0, $s0 -/* 0B809C 800B749C 24050020 */ li $a1, 32 -/* 0B80A0 800B74A0 05210003 */ bgez $t1, .L800B74B0 -/* 0B80A4 800B74A4 0009C043 */ sra $t8, $t1, 1 -/* 0B80A8 800B74A8 25210001 */ addiu $at, $t1, 1 -/* 0B80AC 800B74AC 0001C043 */ sra $t8, $at, 1 -.L800B74B0: -/* 0B80B0 800B74B0 00583023 */ subu $a2, $v0, $t8 -/* 0B80B4 800B74B4 30D9FFFF */ andi $t9, $a2, 0xffff -/* 0B80B8 800B74B8 03203025 */ move $a2, $t9 -/* 0B80BC 800B74BC 0C02DBA1 */ jal synthesis_load_reverb_ring_buffer -/* 0B80C0 800B74C0 24070180 */ li $a3, 384 -/* 0B80C4 800B74C4 8FA80054 */ lw $t0, 0x54($sp) -/* 0B80C8 800B74C8 00408025 */ move $s0, $v0 -/* 0B80CC 800B74CC 8FA30028 */ lw $v1, 0x28($sp) -/* 0B80D0 800B74D0 850D0012 */ lh $t5, 0x12($t0) -/* 0B80D4 800B74D4 87A90052 */ lh $t1, 0x52($sp) -/* 0B80D8 800B74D8 87AA0050 */ lh $t2, 0x50($sp) -/* 0B80DC 800B74DC 11A0000D */ beqz $t5, .L800B7514 -/* 0B80E0 800B74E0 02002025 */ move $a0, $s0 -/* 0B80E4 800B74E4 25450020 */ addiu $a1, $t2, 0x20 -/* 0B80E8 800B74E8 30AEFFFF */ andi $t6, $a1, 0xffff -/* 0B80EC 800B74EC 240F0180 */ li $t7, 384 -/* 0B80F0 800B74F0 01EA3823 */ subu $a3, $t7, $t2 -/* 0B80F4 800B74F4 01C02825 */ move $a1, $t6 -/* 0B80F8 800B74F8 00003025 */ move $a2, $zero -/* 0B80FC 800B74FC AFB10010 */ sw $s1, 0x10($sp) -/* 0B8100 800B7500 AFA30028 */ sw $v1, 0x28($sp) -/* 0B8104 800B7504 0C02DBA1 */ jal synthesis_load_reverb_ring_buffer -/* 0B8108 800B7508 A7A90052 */ sh $t1, 0x52($sp) -/* 0B810C 800B750C 8FA30028 */ lw $v1, 0x28($sp) -/* 0B8110 800B7510 87A90052 */ lh $t1, 0x52($sp) -.L800B7514: -/* 0B8114 800B7514 25380020 */ addiu $t8, $t1, 0x20 -/* 0B8118 800B7518 3C0A0800 */ lui $t2, 0x800 -/* 0B811C 800B751C 3319FFFF */ andi $t9, $t8, 0xffff -/* 0B8120 800B7520 032A6825 */ or $t5, $t9, $t2 -/* 0B8124 800B7524 AC4D0000 */ sw $t5, ($v0) -/* 0B8128 800B7528 8FA5005C */ lw $a1, 0x5c($sp) -/* 0B812C 800B752C 3C010840 */ lui $at, 0x840 -/* 0B8130 800B7530 3C0B0500 */ lui $t3, 0x500 -/* 0B8134 800B7534 00057040 */ sll $t6, $a1, 1 -/* 0B8138 800B7538 31C5FFFF */ andi $a1, $t6, 0xffff -/* 0B813C 800B753C 00A1C025 */ or $t8, $a1, $at -/* 0B8140 800B7540 AC580004 */ sw $t8, 4($v0) -/* 0B8144 800B7544 90780000 */ lbu $t8, ($v1) -/* 0B8148 800B7548 946D000A */ lhu $t5, 0xa($v1) -/* 0B814C 800B754C 24500008 */ addiu $s0, $v0, 8 -/* 0B8150 800B7550 0018CC00 */ sll $t9, $t8, 0x10 -/* 0B8154 800B7554 01AB7025 */ or $t6, $t5, $t3 -/* 0B8158 800B7558 01D96825 */ or $t5, $t6, $t9 -/* 0B815C 800B755C 02003025 */ move $a2, $s0 -/* 0B8160 800B7560 ACCD0000 */ sw $t5, ($a2) -/* 0B8164 800B7564 8C6F0020 */ lw $t7, 0x20($v1) -/* 0B8168 800B7568 3C0C8000 */ lui $t4, 0x8000 -/* 0B816C 800B756C 26100008 */ addiu $s0, $s0, 8 -/* 0B8170 800B7570 252E01A0 */ addiu $t6, $t1, 0x1a0 -/* 0B8174 800B7574 01ECC021 */ addu $t8, $t7, $t4 -/* 0B8178 800B7578 ACD80004 */ sw $t8, 4($a2) -/* 0B817C 800B757C 31D9FFFF */ andi $t9, $t6, 0xffff -/* 0B8180 800B7580 02003825 */ move $a3, $s0 -/* 0B8184 800B7584 3C0109C0 */ lui $at, 0x9c0 -/* 0B8188 800B7588 00A17825 */ or $t7, $a1, $at -/* 0B818C 800B758C 032A6825 */ or $t5, $t9, $t2 -/* 0B8190 800B7590 ACED0000 */ sw $t5, ($a3) -/* 0B8194 800B7594 ACEF0004 */ sw $t7, 4($a3) -/* 0B8198 800B7598 906F0000 */ lbu $t7, ($v1) -/* 0B819C 800B759C 946E000A */ lhu $t6, 0xa($v1) -/* 0B81A0 800B75A0 26100008 */ addiu $s0, $s0, 8 -/* 0B81A4 800B75A4 000FC400 */ sll $t8, $t7, 0x10 -/* 0B81A8 800B75A8 01CBC825 */ or $t9, $t6, $t3 -/* 0B81AC 800B75AC 03387025 */ or $t6, $t9, $t8 -/* 0B81B0 800B75B0 02004025 */ move $t0, $s0 -/* 0B81B4 800B75B4 AD0E0000 */ sw $t6, ($t0) -/* 0B81B8 800B75B8 8C6D0024 */ lw $t5, 0x24($v1) -/* 0B81BC 800B75BC 26100008 */ addiu $s0, $s0, 8 -/* 0B81C0 800B75C0 02001025 */ move $v0, $s0 -/* 0B81C4 800B75C4 01AC7821 */ addu $t7, $t5, $t4 -/* 0B81C8 800B75C8 AD0F0004 */ sw $t7, 4($t0) -/* 0B81CC 800B75CC 3C180840 */ lui $t8, (0x08400540 >> 16) # lui $t8, 0x840 -/* 0B81D0 800B75D0 3C190C30 */ lui $t9, (0x0C307FFF >> 16) # lui $t9, 0xc30 -/* 0B81D4 800B75D4 37397FFF */ ori $t9, (0x0C307FFF & 0xFFFF) # ori $t9, $t9, 0x7fff -/* 0B81D8 800B75D8 37180540 */ ori $t8, (0x08400540 & 0xFFFF) # ori $t8, $t8, 0x540 -/* 0B81DC 800B75DC AC580004 */ sw $t8, 4($v0) -/* 0B81E0 800B75E0 AC590000 */ sw $t9, ($v0) -/* 0B81E4 800B75E4 946E0008 */ lhu $t6, 8($v1) -/* 0B81E8 800B75E8 34018000 */ li $at, 32768 -/* 0B81EC 800B75EC 26100008 */ addiu $s0, $s0, 8 -/* 0B81F0 800B75F0 01C16821 */ addu $t5, $t6, $at -/* 0B81F4 800B75F4 02002025 */ move $a0, $s0 -/* 0B81F8 800B75F8 31AFFFFF */ andi $t7, $t5, 0xffff -/* 0B81FC 800B75FC 3C010C30 */ lui $at, 0xc30 -/* 0B8200 800B7600 3C180840 */ lui $t8, (0x08400840 >> 16) # lui $t8, 0x840 -/* 0B8204 800B7604 37180840 */ ori $t8, (0x08400840 & 0xFFFF) # ori $t8, $t8, 0x840 -/* 0B8208 800B7608 01E1C825 */ or $t9, $t7, $at -/* 0B820C 800B760C AC990000 */ sw $t9, ($a0) -/* 0B8210 800B7610 AC980004 */ sw $t8, 4($a0) -/* 0B8214 800B7614 26100008 */ addiu $s0, $s0, 8 -.L800B7618: -/* 0B8218 800B7618 8FBF0024 */ lw $ra, 0x24($sp) -/* 0B821C 800B761C 02001025 */ move $v0, $s0 -/* 0B8220 800B7620 8FB0001C */ lw $s0, 0x1c($sp) -/* 0B8224 800B7624 8FB10020 */ lw $s1, 0x20($sp) -/* 0B8228 800B7628 03E00008 */ jr $ra -/* 0B822C 800B762C 27BD0058 */ addiu $sp, $sp, 0x58 diff --git a/asm/non_matchings/audio/synthesis/func_800B7630.s b/asm/non_matchings/audio/synthesis/func_800B7630.s deleted file mode 100644 index 7cbd170b7..000000000 --- a/asm/non_matchings/audio/synthesis/func_800B7630.s +++ /dev/null @@ -1,79 +0,0 @@ -glabel func_800B7630 -/* 0B8230 800B7630 27BDFFD8 */ addiu $sp, $sp, -0x28 -/* 0B8234 800B7634 AFA5002C */ sw $a1, 0x2c($sp) -/* 0B8238 800B7638 87B8002E */ lh $t8, 0x2e($sp) -/* 0B823C 800B763C 3C08803B */ lui $t0, %hi(gSynthesisReverbs) # $t0, 0x803b -/* 0B8240 800B7640 2508F790 */ addiu $t0, %lo(gSynthesisReverbs) # addiu $t0, $t0, -0x870 -/* 0B8244 800B7644 0018C940 */ sll $t9, $t8, 5 -/* 0B8248 800B7648 0338C821 */ addu $t9, $t9, $t8 -/* 0B824C 800B764C 0019C8C0 */ sll $t9, $t9, 3 -/* 0B8250 800B7650 03281021 */ addu $v0, $t9, $t0 -/* 0B8254 800B7654 90490003 */ lbu $t1, 3($v0) -/* 0B8258 800B7658 00067400 */ sll $t6, $a2, 0x10 -/* 0B825C 800B765C 000E7C03 */ sra $t7, $t6, 0x10 -/* 0B8260 800B7660 00095080 */ sll $t2, $t1, 2 -/* 0B8264 800B7664 01495023 */ subu $t2, $t2, $t1 -/* 0B8268 800B7668 000A50C0 */ sll $t2, $t2, 3 -/* 0B826C 800B766C 000F3880 */ sll $a3, $t7, 2 -/* 0B8270 800B7670 01495021 */ addu $t2, $t2, $t1 -/* 0B8274 800B7674 904C0001 */ lbu $t4, 1($v0) -/* 0B8278 800B7678 000A5080 */ sll $t2, $t2, 2 -/* 0B827C 800B767C 00EF3821 */ addu $a3, $a3, $t7 -/* 0B8280 800B7680 00073880 */ sll $a3, $a3, 2 -/* 0B8284 800B7684 004A5821 */ addu $t3, $v0, $t2 -/* 0B8288 800B7688 01671821 */ addu $v1, $t3, $a3 -/* 0B828C 800B768C AFBF001C */ sw $ra, 0x1c($sp) -/* 0B8290 800B7690 AFA60030 */ sw $a2, 0x30($sp) -/* 0B8294 800B7694 1180002C */ beqz $t4, .L800B7748 -/* 0B8298 800B7698 24630030 */ addiu $v1, $v1, 0x30 -/* 0B829C 800B769C 904D0004 */ lbu $t5, 4($v0) -/* 0B82A0 800B76A0 24010001 */ li $at, 1 -/* 0B82A4 800B76A4 3C191530 */ lui $t9, (0x15300840 >> 16) # lui $t9, 0x1530 -/* 0B82A8 800B76A8 15A10017 */ bne $t5, $at, .L800B7708 -/* 0B82AC 800B76AC 37390840 */ ori $t9, (0x15300840 & 0xFFFF) # ori $t9, $t9, 0x840 -/* 0B82B0 800B76B0 87AE002E */ lh $t6, 0x2e($sp) -/* 0B82B4 800B76B4 9466000E */ lhu $a2, 0xe($v1) -/* 0B82B8 800B76B8 84670010 */ lh $a3, 0x10($v1) -/* 0B82BC 800B76BC AFA30024 */ sw $v1, 0x24($sp) -/* 0B82C0 800B76C0 24050840 */ li $a1, 2112 -/* 0B82C4 800B76C4 0C02DBC7 */ jal func_800B6F1C -/* 0B82C8 800B76C8 AFAE0010 */ sw $t6, 0x10($sp) -/* 0B82CC 800B76CC 8FA30024 */ lw $v1, 0x24($sp) -/* 0B82D0 800B76D0 00402025 */ move $a0, $v0 -/* 0B82D4 800B76D4 87B8002E */ lh $t8, 0x2e($sp) -/* 0B82D8 800B76D8 84670012 */ lh $a3, 0x12($v1) -/* 0B82DC 800B76DC 50E0001B */ beql $a3, $zero, .L800B774C -/* 0B82E0 800B76E0 8FBF001C */ lw $ra, 0x1c($sp) -/* 0B82E4 800B76E4 84650010 */ lh $a1, 0x10($v1) -/* 0B82E8 800B76E8 AFB80010 */ sw $t8, 0x10($sp) -/* 0B82EC 800B76EC 00003025 */ move $a2, $zero -/* 0B82F0 800B76F0 24A50840 */ addiu $a1, $a1, 0x840 -/* 0B82F4 800B76F4 30AFFFFF */ andi $t7, $a1, 0xffff -/* 0B82F8 800B76F8 0C02DBC7 */ jal func_800B6F1C -/* 0B82FC 800B76FC 01E02825 */ move $a1, $t7 -/* 0B8300 800B7700 10000011 */ b .L800B7748 -/* 0B8304 800B7704 00402025 */ move $a0, $v0 -.L800B7708: -/* 0B8308 800B7708 00801825 */ move $v1, $a0 -/* 0B830C 800B770C AC790000 */ sw $t9, ($v1) -/* 0B8310 800B7710 90480003 */ lbu $t0, 3($v0) -/* 0B8314 800B7714 3C018000 */ lui $at, 0x8000 -/* 0B8318 800B7718 24840008 */ addiu $a0, $a0, 8 -/* 0B831C 800B771C 00084880 */ sll $t1, $t0, 2 -/* 0B8320 800B7720 01284823 */ subu $t1, $t1, $t0 -/* 0B8324 800B7724 000948C0 */ sll $t1, $t1, 3 -/* 0B8328 800B7728 01284821 */ addu $t1, $t1, $t0 -/* 0B832C 800B772C 00094880 */ sll $t1, $t1, 2 -/* 0B8330 800B7730 00495021 */ addu $t2, $v0, $t1 -/* 0B8334 800B7734 01475821 */ addu $t3, $t2, $a3 -/* 0B8338 800B7738 8D6C0034 */ lw $t4, 0x34($t3) -/* 0B833C 800B773C 01816821 */ addu $t5, $t4, $at -/* 0B8340 800B7740 AC6D0004 */ sw $t5, 4($v1) -/* 0B8344 800B7744 A0400000 */ sb $zero, ($v0) -.L800B7748: -/* 0B8348 800B7748 8FBF001C */ lw $ra, 0x1c($sp) -.L800B774C: -/* 0B834C 800B774C 27BD0028 */ addiu $sp, $sp, 0x28 -/* 0B8350 800B7750 00801025 */ move $v0, $a0 -/* 0B8354 800B7754 03E00008 */ jr $ra -/* 0B8358 800B7758 00000000 */ nop diff --git a/asm/non_matchings/audio/synthesis/synthesis_load_reverb_ring_buffer.s b/asm/non_matchings/audio/synthesis/synthesis_load_reverb_ring_buffer.s deleted file mode 100644 index e113db103..000000000 --- a/asm/non_matchings/audio/synthesis/synthesis_load_reverb_ring_buffer.s +++ /dev/null @@ -1,39 +0,0 @@ -glabel synthesis_load_reverb_ring_buffer -/* 0B7A84 800B6E84 00074103 */ sra $t0, $a3, 4 -/* 0B7A88 800B6E88 AFA50004 */ sw $a1, 4($sp) -/* 0B7A8C 800B6E8C 00A07025 */ move $t6, $a1 -/* 0B7A90 800B6E90 311800FF */ andi $t8, $t0, 0xff -/* 0B7A94 800B6E94 01C02825 */ move $a1, $t6 -/* 0B7A98 800B6E98 AFA60008 */ sw $a2, 8($sp) -/* 0B7A9C 800B6E9C 30CFFFFF */ andi $t7, $a2, 0xffff -/* 0B7AA0 800B6EA0 0018CC00 */ sll $t9, $t8, 0x10 -/* 0B7AA4 800B6EA4 3C011400 */ lui $at, 0x1400 -/* 0B7AA8 800B6EA8 01E03025 */ move $a2, $t7 -/* 0B7AAC 800B6EAC 03214025 */ or $t0, $t9, $at -/* 0B7AB0 800B6EB0 31CEFFFF */ andi $t6, $t6, 0xffff -/* 0B7AB4 800B6EB4 010E7825 */ or $t7, $t0, $t6 -/* 0B7AB8 800B6EB8 AC8F0000 */ sw $t7, ($a0) -/* 0B7ABC 800B6EBC 8FB80010 */ lw $t8, 0x10($sp) -/* 0B7AC0 800B6EC0 3C0D803B */ lui $t5, %hi(gSynthesisReverbs) # $t5, 0x803b -/* 0B7AC4 800B6EC4 25ADF790 */ addiu $t5, %lo(gSynthesisReverbs) # addiu $t5, $t5, -0x870 -/* 0B7AC8 800B6EC8 0018C940 */ sll $t9, $t8, 5 -/* 0B7ACC 800B6ECC 0338C821 */ addu $t9, $t9, $t8 -/* 0B7AD0 800B6ED0 0019C8C0 */ sll $t9, $t9, 3 -/* 0B7AD4 800B6ED4 032D4821 */ addu $t1, $t9, $t5 -/* 0B7AD8 800B6ED8 8D2E0018 */ lw $t6, 0x18($t1) -/* 0B7ADC 800B6EDC 00065040 */ sll $t2, $a2, 1 -/* 0B7AE0 800B6EE0 3C0C8000 */ lui $t4, 0x8000 -/* 0B7AE4 800B6EE4 24B90180 */ addiu $t9, $a1, 0x180 -/* 0B7AE8 800B6EE8 01CA7821 */ addu $t7, $t6, $t2 -/* 0B7AEC 800B6EEC 01ECC021 */ addu $t8, $t7, $t4 -/* 0B7AF0 800B6EF0 332DFFFF */ andi $t5, $t9, 0xffff -/* 0B7AF4 800B6EF4 AC980004 */ sw $t8, 4($a0) -/* 0B7AF8 800B6EF8 248B0008 */ addiu $t3, $a0, 8 -/* 0B7AFC 800B6EFC 010D7025 */ or $t6, $t0, $t5 -/* 0B7B00 800B6F00 AD6E0000 */ sw $t6, ($t3) -/* 0B7B04 800B6F04 8D2F001C */ lw $t7, 0x1c($t1) -/* 0B7B08 800B6F08 25620008 */ addiu $v0, $t3, 8 -/* 0B7B0C 800B6F0C 01EAC021 */ addu $t8, $t7, $t2 -/* 0B7B10 800B6F10 030CC821 */ addu $t9, $t8, $t4 -/* 0B7B14 800B6F14 03E00008 */ jr $ra -/* 0B7B18 800B6F18 AD790004 */ sw $t9, 4($t3) diff --git a/include/PR/abi.h b/include/PR/abi.h index 8545be3bb..f1b67a2b7 100644 --- a/include/PR/abi.h +++ b/include/PR/abi.h @@ -24,29 +24,52 @@ /* * Header file for the Audio Binary Interface. * This is included in the Media Binary Interface file - * mbi.h. + * mbi.h. * * This file follows the framework used for graphics. - * + * */ /* Audio commands: */ #define A_SPNOOP 0 #define A_ADPCM 1 #define A_CLEARBUFF 2 +#define A_RESAMPLE 5 +#define A_SETBUFF 8 +#define A_DMEMMOVE 10 +#define A_LOADADPCM 11 +#define A_MIXER 12 +#define A_INTERLEAVE 13 +#define A_SETLOOP 15 + +#if !(defined(VERSION_SH) || defined(VERSION_US)) + #define A_ENVMIXER 3 #define A_LOADBUFF 4 #define A_RESAMPLE 5 #define A_SAVEBUFF 6 #define A_SEGMENT 7 -#define A_SETBUFF 8 #define A_SETVOL 9 -#define A_DMEMMOVE 10 -#define A_LOADADPCM 11 -#define A_MIXER 12 -#define A_INTERLEAVE 13 #define A_POLEF 14 -#define A_SETLOOP 15 + +#else + +#define A_ADDMIXER 4 +#define A_RESAMPLE_ZOH 6 +#define A_DMEMMOVE2 16 +#define A_DOWNSAMPLE_HALF 17 +#define A_ENVSETUP1 18 +#define A_ENVMIXER 19 +#define A_LOADBUFF 20 +#define A_SAVEBUFF 21 +#define A_ENVSETUP2 22 +#define A_S8DEC 23 +#define A_HILOGAIN 24 +#define A_UNK_25 25 +#define A_DUPLICATE 26 +#define A_FILTER 27 + +#endif #define ACMD_SIZE 32 /* @@ -205,7 +228,7 @@ typedef struct { unsigned int pad2:16; unsigned int addr; } Asetloop; - + /* * Generic Acmd Packet */ @@ -284,6 +307,8 @@ typedef short ENVMIX_STATE[40]; * address is later used as parameter, the 8 high bits will be an index * to the segment table and the lower 24 bits are added to the base address * stored in the segment table for this entry. The result is the physical address. + * With the newer rsp audio code, this segment table is not used. The address is + * used directly instead. * * Transfers to/from DRAM are executed using DMA and hence follow these restrictions: * All DRAM addresses should be aligned by 8 bytes, or they will be @@ -391,7 +416,7 @@ typedef short ENVMIX_STATE[40]; * First call: * aSetBuffer(cmd++, 0, 0, output, count) * - * The count refers to the size of the output. + * The count refers to the size of each input. Hence 2 * count bytes will be written out. * A left sample will be placed before the right sample. * * Note: count will be rounded up to the nearest multiple of 16 bytes. @@ -472,7 +497,7 @@ typedef short ENVMIX_STATE[40]; * For 1 octave up or downsampling to (roughly) half number of samples, use pitch 0xffff. * For 1 octave down or upsampling to double as many samples, use pitch 0x4000. * - * Note: count represents the number of output samples and is rounded up to + * Note: count represents the number of output sample bytes and is rounded up to * the nearest multiple of 16 bytes. * * The state consists of the four following source samples when the algorithm stopped as @@ -484,7 +509,7 @@ typedef short ENVMIX_STATE[40]; * the four next source samples and then moving the source position zero or more * samples forward. The first output sample (when A_INIT is given) is always 0. * - * When "count" samples have been written, the following four source samples + * When "count" bytes have been written, the following four source samples * are written to the state in DRAM as well as a fractional position. */ #define aResample(pkt, f, p, s) \ @@ -597,7 +622,7 @@ typedef short ENVMIX_STATE[40]; Acmd *_a = (Acmd *)pkt; \ \ _a->words.w0 = _SHIFTL(A_LOADADPCM, 24, 8) | _SHIFTL(c, 0, 24); \ - _a->words.w1 = (uintptr_t) d; \ + _a->words.w1 = (uintptr_t) (d); \ } // This is a version of aSetVolume which takes a single 32-bit parameter @@ -617,6 +642,355 @@ typedef short ENVMIX_STATE[40]; _a->words.w1 = (uintptr_t)(tr); \ } +#if defined(VERSION_SH) || defined(VERSION_US) +#undef aLoadBuffer +#undef aSaveBuffer +#undef aMix +#undef aEnvMixer +#undef aInterleave + +// New or modified operations in the new audio microcode below + +/** + * Decompresses S8 data. + * Possible flags: A_INIT and A_LOOP. + * + * First set up internal data in DMEM: + * aSetLoop(cmd++, physicalAddressOfLoopState) (if A_LOOP is set) + * + * Then before this command, call: + * aSetBuffer(cmd++, 0, in, out, count) + * + * Note: count will be rounded up to the nearest multiple of 32 bytes. + * + * S8 decompression works by expanding s8 bytes into s16 numbers, + * by performing a left shift of 8 steps. + * + * Before the algorithm starts, the previous 16 samples are loaded according to flag: + * A_INIT: all zeros + * A_LOOP: the address set by aSetLoop + * no flags: the DRAM address in the s parameter + * These 16 samples are immediately copied to the destination address. + * + * The result of "count" bytes will be written after these 16 initial samples. + * The last 16 samples written to the destination will also be written to + * the state address in DRAM. + */ +#define aS8Dec(pkt, f, s) \ +{ \ + Acmd *_a = (Acmd *)pkt; \ + \ + _a->words.w0 = _SHIFTL(A_S8DEC, 24, 8) | _SHIFTL(f, 16, 8); \ + _a->words.w1 = (uintptr_t)(s); \ +} + +/* + * Mix two tracks by simple clamped addition. + * + * s: DMEM source track 1 + * d: DMEM source track 2 and destination + * c: number of bytes to write + * + * Note: count is first rounded down to the nearest multiple of 16 bytes + * and then rounded up to the nearest multiple of 64 bytes. + */ +#define aAddMixer(pkt, s, d, c) \ +{ \ + Acmd *_a = (Acmd *)pkt; \ + \ + _a->words.w0 = (_SHIFTL(A_ADDMIXER, 24, 8) | \ + _SHIFTL((c) >> 4, 16, 8) | _SHIFTL(0x7fff, 0, 16)); \ + _a->words.w1 = (_SHIFTL(s, 16, 16) | _SHIFTL(d, 0, 16)); \ +} + +/* + * Loads a buffer from DRAM to DMEM. + * + * s: DRAM source + * d: DMEM destination + * c: number of bytes to copy (rounded down to 16 byte alignment) + */ +#define aLoadBuffer(pkt, s, d, c) \ +{ \ + Acmd *_a = (Acmd *)pkt; \ + \ + _a->words.w0 = _SHIFTL(A_LOADBUFF, 24, 8) | \ + _SHIFTL((c) >> 4, 16, 8) | _SHIFTL(d, 0, 16); \ + _a->words.w1 = (uintptr_t)(s); \ +} + +/* + * Stores a buffer from DMEM to DRAM. + * + * s: DMEM source + * d: DRAM destination + * c: number of bytes to copy (rounded down to 16 byte alignment) + */ +#define aSaveBuffer(pkt, s, d, c) \ +{ \ + Acmd *_a = (Acmd *)pkt; \ + \ + _a->words.w0 = _SHIFTL(A_SAVEBUFF, 24, 8) | \ + _SHIFTL((c) >> 4, 16, 8) | _SHIFTL(s, 0, 16); \ + _a->words.w1 = (uintptr_t)(d); \ +} + +/* + * Duplicates 128 bytes of data a number of times. + * + * 128 bytes are read from source DMEM address s. + * Then c identical copies of these bytes are written to DMEM address d. + */ +#define aDuplicate(pkt, s, d, c) \ +{ \ + Acmd *_a = (Acmd *)pkt; \ + \ + _a->words.w0 = (_SHIFTL(A_DUPLICATE, 24, 8) | \ + _SHIFTL(c, 16, 8) | _SHIFTL(s, 0, 16)); \ + _a->words.w1 = (_SHIFTL(d, 16, 16) | _SHIFTL(0x80, 0, 16)); \ +} + +/* + * Copies memory in DMEM, second version. + * + * Copies t * c bytes from address i to address o. + * + * Note: count is first rounded up to the nearest multiple of 32 bytes, + * before the multiplication by t. + * + * Note: This acts as memcpy where 32 bytes are moved at a time, therefore + * if input and output overlap, output address should be less than input address. + * + * Not used in SM64. + */ +#define aDMEMMove2(pkt, t, i, o, c) \ +{ \ + Acmd *_a = (Acmd *)pkt; \ + \ + _a->words.w0 = _SHIFTL(A_DMEMMOVE2, 24, 8) | \ + _SHIFTL(t, 16, 8) | _SHIFTL(i, 0, 16); \ + _a->words.w1 = _SHIFTL(o, 16, 16) | _SHIFTL(c, 0, 16); \ +} + +/* + * Fast resample. + * + * Before this command, call: + * aSetBuffer(cmd++, 0, in, out, count) + * + * This works like the other resample command but just takes the "nearest" sample, + * instead of a function of the four nearest samples. + * + * Initially the current position is calculated as (in << 16) + startFract. + * For every sample to create, the value is simply taken from the sample + * at address ((position >> 17) << 1). Then the current position is incremented + * by (pitch << 2). + * + * Note: count represents the number of output bytes to create, and is + * rounded up to the nearest multiple of 8 bytes. + */ +#define aResampleZoh(pkt, pitch, startFract) \ +{ \ + Acmd *_a = (Acmd *)pkt; \ + \ + _a->words.w0 = (_SHIFTL(A_RESAMPLE_ZOH, 24, 8) | \ + _SHIFTL(pitch, 0, 16)); \ + _a->words.w1 = _SHIFTL(startFract, 0, 16); \ +} + +/* + * Fast downsampling by taking every other sample, discarding others. + * + * Note: nSamples refers to the number of output samples to create, and + * is first rounded up to the nearest multiple of 8. + */ +#define aDownsampleHalf(pkt, nSamples, i, o) \ +{ \ + Acmd *_a = (Acmd *)pkt; \ + \ + _a->words.w0 = (_SHIFTL(A_DOWNSAMPLE_HALF, 24, 8) | \ + _SHIFTL(nSamples, 0, 16)); \ + _a->words.w1 = _SHIFTL(i, 16, 16) | _SHIFTL(o, 0, 16); \ +} + +/* + * Mixes audio. + * + * Input and output addresses are taken from the i and o parameters. + * The volume with which the input is changed is taken from the g parameter. + * After the volume of the input samples have been changed, the result + * is added to the output. + * + * Note: count is first rounded down to the nearest multiple of 16 bytes + * and then rounded up to the nearest multiple of 32 bytes. + */ +#define aMix(pkt, g, i, o, c) \ +{ \ + Acmd *_a = (Acmd *)pkt; \ + \ + _a->words.w0 = (_SHIFTL(A_MIXER, 24, 8) | \ + _SHIFTL((c) >> 4, 16, 8) | _SHIFTL(g, 0, 16)); \ + _a->words.w1 = _SHIFTL(i, 16, 16) | _SHIFTL(o, 0, 16); \ +} + +/* + * See aEnvMixer for more info. + */ +#define aEnvSetup1(pkt, initialVolReverb, rampReverb, rampLeft, rampRight) \ +{ \ + Acmd *_a = (Acmd *)pkt; \ + \ + _a->words.w0 = (_SHIFTL(A_ENVSETUP1, 24, 8) | \ + _SHIFTL(initialVolReverb, 16, 8) | \ + _SHIFTL(rampReverb, 0, 16)); \ + _a->words.w1 = _SHIFTL(rampLeft, 16, 16) | \ + _SHIFTL(rampRight, 0, 16); \ +} + +/* + * See aEnvMixer for more info. + */ +#define aEnvSetup2(pkt, initialVolLeft, initialVolRight) \ +{ \ + Acmd *_a = (Acmd *)pkt; \ + \ + _a->words.w0 = _SHIFTL(A_ENVSETUP2, 24, 8); \ + _a->words.w1 = _SHIFTL(initialVolLeft, 16, 16) | \ + _SHIFTL(initialVolRight, 0, 16); \ +} + +/* + * Mixes an envelope with mono sound into 4 channels. + * + * To allow for many parameters, a sequence of aEnvSetup1, aEnvSetup2, + * aEnvMixer shall always be called. + * + * The function works in blocks of 8 samples. + * However, nSamples is rounded up to the nearest multiple of 16 samples. + * + * For each sample in a block: + * 1. sampleLeft = in * volLeft * (negLeft ? -1 : 1) + * 2. sampleRight = in * volRight * (negRight ? -1 : 1) + * 3. dryLeft += sampleLeft + * 4. dryRight += sampleRight + * 5. if swapReverb: swap sampleLeft and sampleRight + * 6. wetLeft += sampleLeft * volReverb + * 7. wetRight += sampleRight * volReverb + * + * After each block, all vol variables are added by their corresponding + * ramp value. + * + * Each volume variable is treated as a UQ0.16 number. Make sure + * the ramp additions don't overflow, or wrapping will occur. + * The initialVolReverb parameter is only 8 bits, but will be left + * shifted 8 bits by the rsp. + */ +#define aEnvMixer(pkt, inBuf, nSamples, swapReverb, negLeft, negRight, \ + dryLeft, dryRight, wetLeft, wetRight) \ +{ \ + Acmd *_a = (Acmd *)pkt; \ + \ + _a->words.w0 = (_SHIFTL(A_ENVMIXER, 24, 8) | \ + _SHIFTL((inBuf) >> 4, 16, 8) | \ + _SHIFTL(nSamples, 8, 8)) | \ + _SHIFTL(swapReverb, 2, 1) | _SHIFTL(negLeft, 1, 1) |\ + _SHIFTL(negRight, 0, 1); \ + _a->words.w1 = _SHIFTL((dryLeft) >> 4, 24, 8) | \ + _SHIFTL((dryRight) >> 4, 16, 8) | \ + _SHIFTL((wetLeft) >> 4, 8, 8) | \ + _SHIFTL((wetRight) >> 4, 0, 8); \ +} + +/* + * Interleaves two mono channels into stereo. + * + * The count refers to the size of each input. Hence 2 * count bytes + * will be written out. + * + * A left sample will be placed before the right sample. + * All addresses (output, left, right) are DMEM addresses. + * + * Note: count will be rounded up to the nearest multiple of 8 bytes. + * The previous version of this function rounded up to the nearest + * multiple of 16 bytes. + */ +#define aInterleave(pkt, o, l, r, c) \ +{ \ + Acmd *_a = (Acmd *)pkt; \ + \ + _a->words.w0 = _SHIFTL(A_INTERLEAVE, 24, 8) | \ + _SHIFTL((c) >> 4, 16, 8) | _SHIFTL(o, 0, 16); \ + _a->words.w1 = _SHIFTL(l, 16, 16) | _SHIFTL(r, 0, 16); \ +} + +/* + * Linear filter function. + * + * Calculates out[i] = sum all elements in the vector in[i..i-7] * filter[0..7], + * where "*" represents dot multiplication. The input/output contains s16 + * samples and filter contains Q1.15 signed fixed point numbers. + * Every result sample is rounded and clamped. + * + * First initiate by calling with the flag f set to 2, countOrBuf contains + * the length in bytes that shall be processed in the next call. The addr + * parameter shall contain the DRAM address to the filter table (16 bytes). + * The count will be rounded up to the nearest multiple of 16 bytes. + * + * The aFilter function shall then be called in direct succession, with flag + * set to either 0 or 1. The countOrBuf parameter shall contain the DMEM + * address for the input/output. The addr parameter shall contain the DRAM + * address for the state, containing the last previous 8 input samples. + * The state is always written to upon exit, but is only read at entry if + * the flag is 0 (otherwise all-zero samples are used instead). + */ +#define aFilter(pkt, f, countOrBuf, addr) \ +{ \ + Acmd *_a = (Acmd *)pkt; \ + \ + _a->words.w0 = _SHIFTL(A_FILTER, 24, 8) | _SHIFTL((f), 16, 8) | \ + _SHIFTL((countOrBuf), 0, 16); \ + _a->words.w1 = (uintptr_t)(addr); \ +} + +/* + * Modifies the volume of samples using a simple UQ4.4 gain multiplier. + * + * Performs the following: + * + * 1. Count c is rounded up to 32 byte alignment + * 2. g is a u8 that contains a UQ4.4 number + * 3. Modify each sample s, so that s = clamp_s16(s * g >> 4) + */ +#define aHiLoGain(pkt, g, buflen, i) \ +{ \ + Acmd *_a = (Acmd *)pkt; \ + \ + _a->words.w0 = _SHIFTL(A_HILOGAIN, 24, 8) | \ + _SHIFTL((g), 16, 8) | _SHIFTL((buflen), 0, 16); \ + _a->words.w1 = _SHIFTL((i), 16, 16); \ +} + +/* + * Performs the following: + * + * 1. Count c is rounded up to 64 byte alignment + * 2. f is added to i + * 3. i and o are from now treated as s16 pointers + * 4. 32 s16 samples are loaded from i to tbl + * 5. for (u32 idx = 0; idx * sizeof(s16) < c; idx++) + * o[idx] = clamp_s16((s32)o[idx] * (s32)tbl[idx % 32]); + */ +#define aUnknown25(pkt, f, c, o, i) \ +{ \ + Acmd *_a = (Acmd *)pkt; \ + \ + _a->words.w0 = (_SHIFTL(A_UNK_25, 24, 8) | \ + _SHIFTL((f), 16, 8) | _SHIFTL((c), 0, 16)); \ + _a->words.w1 = _SHIFTL((o), 16, 16) | _SHIFTL((i), 0, 16); \ +} + +#endif + #endif /* _LANGUAGE_C */ #endif /* !_ABI_H_ */ diff --git a/permuter_settings.toml b/permuter_settings.toml index 33d31fe7e..e4dd63c79 100644 --- a/permuter_settings.toml +++ b/permuter_settings.toml @@ -15,3 +15,7 @@ "OS_.*" = "int" "SEGMENT_.*" = "int" "ACTOR_.*" = "int" +"A_[A-Z]+" = "int" +"a[A-Za-z]+" = "void" +"_SHIFT[LR]" = "void" +"ALIGN.*" = "int" diff --git a/src/audio/synthesis.c b/src/audio/synthesis.c index 8106fb622..1fd448b9f 100644 --- a/src/audio/synthesis.c +++ b/src/audio/synthesis.c @@ -7,20 +7,7 @@ //#include "seqplayer.h" #include "internal.h" //#include "external.h" - - -#define DMEM_ADDR_TEMP 0x0 -#define DMEM_ADDR_RESAMPLED 0x20 -#define DMEM_ADDR_RESAMPLED2 0x160 -#define DMEM_ADDR_UNCOMPRESSED_NOTE 0x180 -#define DMEM_ADDR_NOTE_PAN_TEMP 0x200 -#define DMEM_ADDR_STEREO_STRONG_TEMP_DRY 0x200 -#define DMEM_ADDR_STEREO_STRONG_TEMP_WET 0x340 -#define DMEM_ADDR_COMPRESSED_ADPCM_DATA 0x3f0 -#define DMEM_ADDR_LEFT_CH 0x4c0 -#define DMEM_ADDR_RIGHT_CH 0x600 -#define DMEM_ADDR_WET_LEFT_CH 0x740 -#define DMEM_ADDR_WET_RIGHT_CH 0x880 +#include "PR/abi.h" #define aSetLoadBufferPair(pkt, c, off) \ aSetBuffer(pkt, 0, c + DMEM_ADDR_WET_LEFT_CH, 0, DEFAULT_LEN_1CH - c); \ @@ -34,8 +21,6 @@ aSetBuffer(pkt, 0, 0, c + DMEM_ADDR_WET_RIGHT_CH, d); \ aSaveBuffer(pkt, VIRTUAL_TO_PHYSICAL2(gSynthesisReverb.ringBuffer.right + (off))); -#define ALIGN(val, amnt) (((val) + (1 << amnt) - 1) & ~((1 << amnt) - 1)) - struct VolumeChange { u16 sourceLeft; u16 sourceRight; @@ -62,9 +47,6 @@ s8 gUseReverb; s8 gNumSynthesisReverbs; struct NoteSubEu *gNoteSubsEu; -extern struct Note *gAudioBufferParameters; -extern s32 gMaxSimultaneousNotes; - f32 gLeftVolRampings; //f32 gRightVolRampings[3][1024]; //f32 *gCurrentLeftVolRamping; // Points to any of the three left buffers above @@ -128,79 +110,17 @@ void prepare_reverb_ring_buffer(s32 chunkLen, u32 updateIndex, s32 reverbIndex) } -#ifdef NON_MATCHING -/* sm64 -u64 *synthesis_load_reverb_ring_buffer(u64 *cmd, u16 addr, u16 srcOffset, s32 len, s32 reverbIndex) { - aSetBuffer(cmd++, 0, addr, 0, len&0xFF<<0x10); - aLoadBuffer(cmd++, VIRTUAL_TO_PHYSICAL2(&gSynthesisReverbs[reverbIndex].ringBuffer.left[srcOffset])); - - aSetBuffer(cmd++, 0, addr + DEFAULT_LEN_1CH, 0, len&0xFF<<0x10); - aLoadBuffer(cmd++, VIRTUAL_TO_PHYSICAL2(&gSynthesisReverbs[reverbIndex].ringBuffer.right[srcOffset])); - - return cmd; +Acmd *synthesis_load_reverb_ring_buffer(Acmd *acmd, u16 addr, u16 srcOffset, s32 len, s32 reverbIndex) { + aLoadBuffer(acmd++, VIRTUAL_TO_PHYSICAL2(&gSynthesisReverbs[reverbIndex].ringBuffer.left[srcOffset]), addr, len); + aLoadBuffer(acmd++, VIRTUAL_TO_PHYSICAL2(&gSynthesisReverbs[reverbIndex].ringBuffer.right[srcOffset]), addr + 0x180, len); + return acmd; } - void *temp_t1; - void *temp_t3; - temp_t0 = (((arg3 >> 4) & 0xFF) << 0x10) | 0x14000000; - arg0->unk0 = (s32) (temp_t0 | (arg1 & 0xFFFF)); - temp_t1 = (arg4 * 0x108) + &gSynthesisReverbs; - temp_t2 = (arg2 & 0xFFFF) * 2; - arg0->unk4 = (s32) (temp_t1->unk18 + temp_t2 + 0x80000000); - temp_t3 = arg0 + 8; - temp_t3->unk0 = (s32) (temp_t0 | ((arg1 + 0x180) & 0xFFFF)); - temp_t3->unk4 = (s32) (temp_t1->unk1C + temp_t2 + 0x80000000); - return temp_t3 + 8; +Acmd *synthesis_save_reverb_ring_buffer(Acmd *acmd, u16 addr, u16 destOffset, s32 len, s32 reverbIndex) { + aSaveBuffer(acmd++, addr, VIRTUAL_TO_PHYSICAL2(&gSynthesisReverbs[reverbIndex].ringBuffer.left[destOffset]), len); + aSaveBuffer(acmd++, addr + 0x180, VIRTUAL_TO_PHYSICAL2(&gSynthesisReverbs[reverbIndex].ringBuffer.right[destOffset]), len); + return acmd; } -*/ -#else -GLOBAL_ASM("asm/non_matchings/audio/synthesis/synthesis_load_reverb_ring_buffer.s") -#endif - -#ifdef NON_MATCHING -/* sm64 -void synthesis_load_note_subs_eu(s32 updateIndex) { - struct NoteSubEu *src; - struct NoteSubEu *dest; - s32 i; - - for (i = 0; i < gMaxSimultaneousNotes; i++) { - src = &gAudioBufferParameters[i].noteSubEu; - dest = &gNoteSubsEu[gMaxSimultaneousNotes * updateIndex + i]; - if (src->enabled) { - *dest = *src; - src->needsInit = FALSE; - } else { - dest->enabled = FALSE; - } - } -} -// mk64 m2c (with minor edits) struct access appears quite different. -void func_800B6FB4(s32 arg0, s32 arg1) { - s32 *dest; - s32 temp_v0; - s32 temp_v0_2; - s32 phi_v0; - - temp_v0 = arg0 + 1; - if (i = 0; temp_v0 < (s32) gAudioBufferParameters.unkC; i++) { - phi_v0 = temp_v0; - - for(i = 0; temp_v0_2 < (s32) gAudioBufferParameters.unkC; i++) { - dest = &gNoteSubsEu[gMaxSimultaneousNotes * phi_v0 + (arg1 * 0x10)]; - if ((*dest * 2) >= 0) { - temp_v0_2 = phi_v0 + 1; - *dest = (s8) ((u8) *dest & 0xFF7F); - phi_v0 = temp_v0_2; - - } - } - } -} -*/ -#else -GLOBAL_ASM("asm/non_matchings/audio/synthesis/func_800B6F1C.s") -#endif #ifdef MIPS_TO_C //generated by mips_to_c commit 3c3b0cede1a99430bfd3edf8d385802b94f91307 @@ -237,41 +157,35 @@ GLOBAL_ASM("asm/non_matchings/audio/synthesis/synthesis_load_note_subs_eu.s") #endif #ifdef MIPS_TO_C -//generated by mips_to_c commit 3c3b0cede1a99430bfd3edf8d385802b94f91307 -Tried to use struct NoteSubEu before it is defined. -extern s32 gMaxSimultaneousNotes; -extern ? gNoteSubsEu; +//generated by m2c commit 0927f17aac197848d4ebdf0c6bbad74b01f0851c +extern s32 D_803B1508; void func_800B7034(s32 arg0) { - s32 temp_v0; + s32 var_a1; + s32 var_v0; + struct NoteSub *temp_a2; void *temp_a0; void *temp_a0_2; - void *temp_a2; - s32 phi_a1; - s32 phi_v0; - phi_a1 = 0; - phi_v0 = 0; + var_v0 = 0; + var_a1 = 0; if (gMaxSimultaneousNotes > 0) { - // Error: Tried to use struct NoteSubEu before it is defined. - // At instruction: lui $t2, %hi(gNoteSubsEu) do { - temp_a0 = phi_a1 + *MIPS2C_ERROR(Read from unset register $t1); + temp_a0 = var_a1 + D_803B1508; temp_a0_2 = temp_a0 + 0xB0; - temp_a2 = (((gMaxSimultaneousNotes * arg0) + phi_v0) * 0x10) + *MIPS2C_ERROR(Read from unset register $t2); - if ((temp_a0->unkB0 >> 0x1F) != 0) { - temp_a2->unk0 = temp_a0_2->unk0; - temp_a2->unk4 = temp_a0_2->unk4; - temp_a2->unk8 = temp_a0_2->unk8; - temp_a2->unkC = temp_a0_2->unkC; - temp_a0_2->unk0 = temp_a0_2->unk0 & 0xFFBF; + temp_a2 = &gNoteSubsEu[(gMaxSimultaneousNotes * arg0) + var_v0]; + if (((u32) temp_a0->unkB0 >> 0x1F) != 0) { + temp_a2->unk0 = (s32) temp_a0_2->unk0; + temp_a2->unk4 = (s32) temp_a0_2->unk4; + temp_a2->unk8 = (s32) temp_a0_2->unk8; + temp_a2->sound.samples = temp_a0_2->unkC; + temp_a0_2->unk0 = (s8) ((u8) temp_a0_2->unk0 & 0xFFBF); } else { - temp_a2->unk0 = temp_a2->unk0 & 0xFF7F; + temp_a2->unk0 = (s8) ((u8) temp_a2->unk0 & 0xFF7F); } - temp_v0 = phi_v0 + 1; - phi_a1 += 0xC0; - phi_v0 = temp_v0; - } while (temp_v0 < gMaxSimultaneousNotes); + var_v0 += 1; + var_a1 += 0xC0; + } while (var_v0 < gMaxSimultaneousNotes); } } #else @@ -279,267 +193,157 @@ GLOBAL_ASM("asm/non_matchings/audio/synthesis/func_800B7034.s") #endif #ifdef MIPS_TO_C -//generated by mips_to_c commit 3c3b0cede1a99430bfd3edf8d385802b94f91307 -void func_800B7034(s32); // extern -void *func_800B775C(s32, s32, void *, s32); // extern -void func_800C1138(s32); // extern -void prepare_reverb_ring_buffer(s32, s32, s32); // extern -extern ? gAudioBufferParameters; +//generated by m2c commit 0927f17aac197848d4ebdf0c6bbad74b01f0851c +? func_800B7034(s32); /* extern */ +Acmd *func_800B775C(s32, s16, Acmd *, s32); /* extern */ +? func_800C1138(s16); /* extern */ +? prepare_reverb_ring_buffer(s16, s32, s32); /* extern */ -void *func_800B70EC(void *arg0, s32 *arg1, s32 arg2, s32 arg3) { - s16 temp_s2; - s16 temp_s4; - s16 temp_s4_2; +Acmd *func_800B70EC(Acmd *acmd, s32 *arg1, s32 arg2, s16 arg3) { + Acmd *temp_v0; + Acmd *var_fp; + s16 temp_s0; s16 temp_v1; s16 temp_v1_2; + s16 var_s3; + s16 var_s4; + s16 var_s4_2; + s16 var_s6; s32 temp_lo; - s32 temp_s0; - s32 temp_s1; - s32 temp_s4_3; - s8 temp_v0; - s8 temp_v0_3; - struct SynthesisReverb *temp_s0_2; - u8 temp_v0_4; - void *temp_fp; - void *temp_v0_2; - s16 phi_s4; - s32 phi_s4_2; - s32 phi_s6; - struct SynthesisReverb *phi_s0; - s32 phi_s3; - s16 phi_s2; - s32 phi_s1; - s32 phi_v0; - s32 phi_s7; - void *phi_fp; - s16 phi_s2_2; - struct SynthesisReverb *phi_s0_2; - void *phi_fp_2; - s16 phi_s2_3; + s32 var_s1; + s32 var_s7; + s8 temp_v0_2; + struct SynthesisReverb *var_s0; + struct SynthesisReverb *var_s0_2; + u8 temp_t4; + u8 temp_v0_3; - temp_s4 = gAudioBufferParameters.unkC; - phi_s4 = temp_s4; - phi_s6 = arg3; - if (temp_s4 > 0) { + var_s4 = gAudioBufferParameters.updatesPerFrame; + var_s6 = arg3; + if (var_s4 > 0) { do { - temp_s0 = phi_s4 - 1; + temp_s0 = var_s4 - 1; func_800C1138(temp_s0); - func_800B7034(gAudioBufferParameters.unkC - phi_s4); - phi_s4 = temp_s0; + func_800B7034(gAudioBufferParameters.updatesPerFrame - var_s4); + var_s4 = temp_s0; } while (temp_s0 > 0); } - arg0->unk0 = 0x7000000; - arg0->unk4 = 0; - temp_s4_2 = gAudioBufferParameters.unkC; - temp_fp = arg0 + 8; - phi_s4_2 = temp_s4_2; - phi_s7 = arg2; - phi_fp = temp_fp; - phi_fp_2 = temp_fp; - if (temp_s4_2 > 0) { + var_s7 = arg2; + acmd->words.w0 = 0x07000000; + acmd->words.w1 = 0; + var_s4_2 = gAudioBufferParameters.updatesPerFrame; + var_fp = acmd + 8; + if (var_s4_2 > 0) { do { - temp_s2 = gAudioBufferParameters.unkC; - phi_s2 = temp_s2; - phi_s1 = 0; - phi_s2_2 = temp_s2; - if (phi_s4_2 == 1) { - phi_s3 = phi_s6; + var_s1 = 0; + if (var_s4_2 == 1) { + var_s3 = var_s6; } else { - temp_lo = phi_s6 / phi_s4_2; - temp_v1 = gAudioBufferParameters.unk10; + temp_lo = var_s6 / var_s4_2; + temp_v1 = gAudioBufferParameters.samplesPerUpdateMax; if (temp_lo >= temp_v1) { - phi_s3 = temp_v1; + var_s3 = temp_v1; } else { - temp_v1_2 = gAudioBufferParameters.unk12; + temp_v1_2 = gAudioBufferParameters.samplesPerUpdateMin; if (temp_v1_2 >= temp_lo) { - phi_s3 = temp_v1_2; + var_s3 = temp_v1_2; } else { - phi_s3 = gAudioBufferParameters.unkE; + var_s3 = gAudioBufferParameters.samplesPerUpdate; } } } - temp_v0 = gNumSynthesisReverbs; - phi_v0 = temp_v0; - if (temp_v0 > 0) { - phi_s0 = gSynthesisReverbs; + if (gNumSynthesisReverbs > 0) { + var_s0 = gSynthesisReverbs; do { - phi_s2_3 = phi_s2; - if (phi_s0->useReverb != 0) { - prepare_reverb_ring_buffer(phi_s3, phi_s2 - phi_s4_2, phi_s1); - phi_v0 = gNumSynthesisReverbs; - phi_s2_3 = gAudioBufferParameters.unkC; + if (var_s0->useReverb != 0) { + prepare_reverb_ring_buffer(var_s3, gAudioBufferParameters.updatesPerFrame - var_s4_2, var_s1); } - temp_s1 = phi_s1 + 1; - phi_s0 += 0x108; - phi_s2 = phi_s2_3; - phi_s1 = temp_s1; - phi_s2_2 = phi_s2_3; - } while (temp_s1 < phi_v0); + var_s1 += 1; + var_s0 += 0x108; + } while (var_s1 < gNumSynthesisReverbs); } - temp_v0_2 = func_800B775C(phi_s7, phi_s3, phi_fp, phi_s2_2 - phi_s4_2); - temp_s4_3 = phi_s4_2 - 1; - phi_s4_2 = temp_s4_3; - phi_s6 -= phi_s3; - phi_s7 += phi_s3 * 4; - phi_fp = temp_v0_2; - phi_fp_2 = temp_v0_2; - } while (temp_s4_3 > 0); + temp_v0 = func_800B775C(var_s7, var_s3, var_fp, gAudioBufferParameters.updatesPerFrame - var_s4_2); + var_s4_2 -= 1; + var_fp = temp_v0; + var_s6 -= var_s3; + var_s7 += var_s3 * 4; + } while (var_s4_2 > 0); } - temp_v0_3 = gNumSynthesisReverbs; - phi_s0_2 = gSynthesisReverbs; - if (temp_v0_3 > 0) { + temp_v0_2 = gNumSynthesisReverbs; + var_s0_2 = gSynthesisReverbs; + if (temp_v0_2 > 0) { do { - temp_v0_4 = phi_s0_2->framesLeftToIgnore; - if (temp_v0_4 != 0) { - phi_s0_2->framesLeftToIgnore = temp_v0_4 - 1; + temp_v0_3 = var_s0_2->framesLeftToIgnore; + if (temp_v0_3 != 0) { + var_s0_2->framesLeftToIgnore = temp_v0_3 - 1; } - temp_s0_2 = phi_s0_2 + 0x108; - temp_s0_2->unk-105 = phi_s0_2->curFrame ^ 1; - phi_s0_2 = temp_s0_2; - } while (temp_s0_2 < &gSynthesisReverbs[temp_v0_3]); + temp_t4 = var_s0_2->curFrame; + var_s0_2 += 0x108; + var_s0_2->unk-105 = (s8) (temp_t4 ^ 1); + } while ((u32) var_s0_2 < (u32) &gSynthesisReverbs[temp_v0_2]); } - *arg1 = (phi_fp_2 - arg0) >> 3; - return phi_fp_2; + *arg1 = (s32) (var_fp - acmd) >> 3; + return var_fp; } #else GLOBAL_ASM("asm/non_matchings/audio/synthesis/func_800B70EC.s") #endif -#ifdef MIPS_TO_C -//generated by mips_to_c commit 3c3b0cede1a99430bfd3edf8d385802b94f91307 -void *synthesis_load_reverb_ring_buffer(void *, s32, u16, s16, s32); // extern +Acmd *func_800B7304(Acmd *acmd, s32 bufLen, s16 reverbIndex, s16 updateIndex) { + struct ReverbRingBufferItem *item; + s16 startPad; + s16 paddedLengthA; -s32 func_800B7304(void *arg0, s32 arg1, s16 arg2, s16 arg3) { - void *sp54; - s16 sp52; - s16 sp50; - struct SynthesisReverb *sp28; - s16 temp_a3; - s16 temp_t5; - s32 temp_a1; - s32 temp_t7; - s32 temp_t8; - s32 temp_v0_2; - struct SynthesisReverb *temp_v1; - void *temp_a0; - void *temp_a0_2; - void *temp_s0; - void *temp_s0_2; - void *temp_s0_3; - void *temp_s0_4; - void *temp_s0_5; - void *temp_s0_6; - void *temp_s0_7; - void *temp_t0; - void *temp_v0; - void *temp_v0_3; - void *phi_v0; - void *phi_v0_2; - void *phi_s0; + item = &gSynthesisReverbs[reverbIndex].items[gSynthesisReverbs[reverbIndex].curFrame][updateIndex]; + aClearBuffer(acmd++, 0x840, 0x300); + if (gSynthesisReverbs[reverbIndex].downsampleRate == 1) { - temp_v1 = &gSynthesisReverbs[arg2]; - arg0->unk4 = 0x300; - arg0->unk0 = 0x2000840; - temp_t0 = temp_v1 + (temp_v1->curFrame * 0x64) + (arg3 * 0x14) + 0x30; - temp_s0 = arg0 + 8; - if (temp_v1->downsampleRate == 1) { - sp54 = temp_t0; - sp28 = temp_v1; - temp_v0 = synthesis_load_reverb_ring_buffer(temp_s0, 0x840, temp_t0->unkE, temp_t0->unk10, arg2); - temp_a3 = temp_t0->unk12; - temp_a0 = temp_v0; - phi_v0 = temp_v0; - if (temp_a3 != 0) { - sp28 = temp_v1; - phi_v0 = synthesis_load_reverb_ring_buffer(temp_a0, (temp_t0->unk10 + 0x840) & 0xFFFF, 0, temp_a3, arg2); + acmd = synthesis_load_reverb_ring_buffer(acmd, 0x840, item->startPos, item->lengthA, reverbIndex); + if (item->lengthB != 0) { + acmd = synthesis_load_reverb_ring_buffer(acmd, item->lengthA + 0x840, 0U, item->lengthB, reverbIndex); } - phi_v0->unk0 = 0xC307FFF; - phi_v0->unk4 = 0x8400540; - temp_s0_2 = phi_v0 + 8; - temp_s0_2->unk0 = ((gSynthesisReverbs[arg2].reverbGain + 0x8000) & 0xFFFF) | 0xC300000; - temp_s0_2->unk4 = 0x8400840; - phi_s0 = temp_s0_2; + + aMix(acmd++, 0x7fff, 0x840, 0x540, 0x300); + aMix(acmd++, 0x8000 + gSynthesisReverbs[reverbIndex].reverbGain, 0x840, 0x840, 0x300); } else { - temp_v0_2 = temp_t0->unkC; - temp_t7 = (temp_v0_2 & 7) << 0x11; - temp_t8 = temp_t7 >> 0x10; - temp_t5 = (temp_t8 + temp_t0->unk10 + 0xF) & 0xFFF0; - sp50 = temp_t5; - sp52 = temp_t8; - sp54 = temp_t0; - sp28 = temp_v1; - temp_v0_3 = synthesis_load_reverb_ring_buffer(temp_s0, 0x20, (temp_v0_2 - (temp_t8 / 2)) & 0xFFFF, 0x180, arg2); - temp_a0_2 = temp_v0_3; - phi_v0_2 = temp_v0_3; - if (temp_t0->unk12 != 0) { - sp28 = temp_v1; - sp52 = temp_t8; - phi_v0_2 = synthesis_load_reverb_ring_buffer(temp_a0_2, (temp_t5 + 0x20) & 0xFFFF, 0, 0x180 - temp_t5, arg2); + startPad = (item->startPos % 8U) * 2; + paddedLengthA = ALIGN(startPad + item->lengthA, 4); + + acmd = synthesis_load_reverb_ring_buffer(acmd, 0x0020, item->startPos - (startPad / 2), 0x00000180, reverbIndex); + if (item->lengthB != 0) { + acmd = synthesis_load_reverb_ring_buffer(acmd, paddedLengthA + 0x20, 0, 0x180 - paddedLengthA, reverbIndex); } - phi_v0_2->unk0 = (((temp_t7 >> 0x10) + 0x20) & 0xFFFF) | 0x8000000; - temp_a1 = (arg1 * 2) & 0xFFFF; - phi_v0_2->unk4 = temp_a1 | 0x8400000; - temp_s0_3 = phi_v0_2 + 8; - temp_s0_3->unk0 = gSynthesisReverbs[arg2].resampleRate | 0x5000000 | (gSynthesisReverbs[arg2].resampleFlags << 0x10); - temp_s0_4 = temp_s0_3 + 8; - temp_s0_3->unk4 = gSynthesisReverbs[arg2].resampleStateLeft + 0x80000000; - temp_s0_4->unk0 = (((temp_t7 >> 0x10) + 0x1A0) & 0xFFFF) | 0x8000000; - temp_s0_4->unk4 = temp_a1 | 0x9C00000; - temp_s0_5 = temp_s0_4 + 8; - temp_s0_5->unk0 = gSynthesisReverbs[arg2].resampleRate | 0x5000000 | (gSynthesisReverbs[arg2].resampleFlags << 0x10); - temp_s0_6 = temp_s0_5 + 8; - temp_s0_5->unk4 = gSynthesisReverbs[arg2].resampleStateRight + 0x80000000; - temp_s0_6->unk4 = 0x8400540; - temp_s0_6->unk0 = 0xC307FFF; - temp_s0_7 = temp_s0_6 + 8; - temp_s0_7->unk0 = ((gSynthesisReverbs[arg2].reverbGain + 0x8000) & 0xFFFF) | 0xC300000; - temp_s0_7->unk4 = 0x8400840; - phi_s0 = temp_s0_7; + + aSetBuffer(acmd++, 0, 0x20 + startPad, 0x840, bufLen * 2); + aResample(acmd++, gSynthesisReverbs[reverbIndex].resampleFlags, gSynthesisReverbs[reverbIndex].resampleRate, VIRTUAL_TO_PHYSICAL2(gSynthesisReverbs[reverbIndex].resampleStateLeft)); + aSetBuffer(acmd++, 0, 0x1A0 + startPad, 0x9C0, bufLen * 2); + aResample(acmd++, gSynthesisReverbs[reverbIndex].resampleFlags, gSynthesisReverbs[reverbIndex].resampleRate, VIRTUAL_TO_PHYSICAL2(gSynthesisReverbs[reverbIndex].resampleStateRight)); + aMix(acmd++, 0x7fff, 0x840, 0x540, 0x300); + aMix(acmd++, 0x8000 + gSynthesisReverbs[reverbIndex].reverbGain, 0x840, 0x840, 0x300); } - return phi_s0 + 8; + return acmd; } -#else -GLOBAL_ASM("asm/non_matchings/audio/synthesis/func_800B7304.s") -#endif -#ifdef MIPS_TO_C -//generated by mips_to_c commit 3c3b0cede1a99430bfd3edf8d385802b94f91307 -void *func_800B6F1C(void *, u16, s16, s32, s32); // extern +Acmd *func_800B7630(Acmd *acmd, s16 reverbIndex, s16 updateIndex) { + struct ReverbRingBufferItem *item; -void *func_800B7630(void *arg0, s16 arg1, s16 arg2) { - void *sp24; - s16 temp_a3_2; - s32 temp_a3; - struct SynthesisReverb *temp_v0; - void *temp_v0_2; - void *temp_v1; - void *phi_a0; - - temp_v0 = &gSynthesisReverbs[arg1]; - temp_a3 = arg2 * 0x14; - temp_v1 = temp_v0 + (temp_v0->curFrame * 0x64) + temp_a3 + 0x30; - phi_a0 = arg0; - if (temp_v0->useReverb != 0) { - if (temp_v0->downsampleRate == 1) { - sp24 = temp_v1; - temp_v0_2 = func_800B6F1C(0x840, temp_v1->unkE, temp_v1->unk10, arg1); - temp_a3_2 = temp_v1->unk12; - phi_a0 = temp_v0_2; - if (temp_a3_2 != 0) { - phi_a0 = func_800B6F1C(temp_v0_2, (temp_v1->unk10 + 0x840) & 0xFFFF, 0, temp_a3_2, arg1); - } - } else { - arg0->unk0 = 0x15300840; - arg0->unk4 = (temp_v0 + (temp_v0->curFrame * 0x64) + temp_a3)->unk34 + 0x80000000; - temp_v0->resampleFlags = 0; - phi_a0 = arg0 + 8; + item = &gSynthesisReverbs[reverbIndex].items[gSynthesisReverbs[reverbIndex].curFrame][updateIndex]; + if (gSynthesisReverbs[reverbIndex].useReverb != 0) { + switch (gSynthesisReverbs[reverbIndex].downsampleRate) { + case 1: + acmd = synthesis_save_reverb_ring_buffer(acmd, 0x840, item->startPos, item->lengthA, reverbIndex); + if (item->lengthB != 0) { + acmd = synthesis_save_reverb_ring_buffer(acmd, 0x840 + item->lengthA, 0, item->lengthB, reverbIndex); + } + break; + default: + aSaveBuffer(acmd++, 0x840, VIRTUAL_TO_PHYSICAL2(gSynthesisReverbs[reverbIndex].items[gSynthesisReverbs[reverbIndex].curFrame][updateIndex].toDownsampleLeft), 0x300); + gSynthesisReverbs[reverbIndex].resampleFlags = 0; + break; } } - return phi_a0; + return acmd; } -#else -GLOBAL_ASM("asm/non_matchings/audio/synthesis/func_800B7630.s") -#endif #ifdef MIPS_TO_C //generated by mips_to_c commit 3c3b0cede1a99430bfd3edf8d385802b94f91307 diff --git a/src/audio/synthesis.h b/src/audio/synthesis.h index cb7dba792..db931ae9b 100644 --- a/src/audio/synthesis.h +++ b/src/audio/synthesis.h @@ -2,51 +2,94 @@ #define AUDIO_SYNTHESIS_H //#include "internal.h" +#include "PR/abi.h" -#define VERSION_EU +#define DEFAULT_LEN_1CH 0x180 +#define DEFAULT_LEN_2CH 0x300 -#define DEFAULT_LEN_1CH 0x140 -#define DEFAULT_LEN_2CH 0x280 +/* +Its not clear what values these macros should have. Neither version seem to +line up for MK64. Maybe each game has unique values for these? I don't know +enough about the Audio engine stuff to speculate beyond that. + +Non-Shindou SM64 +#define DMEM_ADDR_TEMP 0x0 +#define DMEM_ADDR_RESAMPLED 0x20 +#define DMEM_ADDR_RESAMPLED2 0x160 +#define DMEM_ADDR_UNCOMPRESSED_NOTE 0x180 +#define DMEM_ADDR_NOTE_PAN_TEMP 0x200 +#define DMEM_ADDR_STEREO_STRONG_TEMP_DRY 0x200 +#define DMEM_ADDR_STEREO_STRONG_TEMP_WET 0x340 +#define DMEM_ADDR_COMPRESSED_ADPCM_DATA 0x3f0 +#define DMEM_ADDR_LEFT_CH 0x4c0 +#define DMEM_ADDR_RIGHT_CH 0x600 +#define DMEM_ADDR_WET_LEFT_CH 0x740 +#define DMEM_ADDR_WET_RIGHT_CH 0x880 + +Shindou SM64 +#define DMEM_ADDR_TEMP 0x450 +#define DMEM_ADDR_RESAMPLED 0x470 +#define DMEM_ADDR_RESAMPLED2 0x5f0 +#define DMEM_ADDR_UNCOMPRESSED_NOTE 0x5f0 +#define DMEM_ADDR_NOTE_PAN_TEMP 0x650 +#define DMEM_ADDR_COMPRESSED_ADPCM_DATA 0x990 +#define DMEM_ADDR_LEFT_CH 0x990 +#define DMEM_ADDR_RIGHT_CH 0xb10 +#define DMEM_ADDR_WET_LEFT_CH 0xc90 +#define DMEM_ADDR_WET_RIGHT_CH 0xe10 +*/ #define MAX_UPDATES_PER_FRAME 5 struct ReverbRingBufferItem { - s16 numSamplesAfterDownsampling; - s16 chunkLen; // never read - s16 *toDownsampleLeft; - s16 *toDownsampleRight; // data pointed to by left and right are adjacent in memory - s32 startPos; // start pos in ring buffer - s16 lengthA; // first length in ring buffer (from startPos, at most until end) - s16 lengthB; // second length in ring buffer (from pos 0) + /* 0x00 */ s16 numSamplesAfterDownsampling; + /* 0x02 */ s16 chunkLen; // never read + /* 0x04 */ s16 *toDownsampleLeft; + /* 0x08 */ s16 *toDownsampleRight; // data pointed to by left and right are adjacent in memory + /* 0x0C */ s32 startPos; // start pos in ring buffer + /* 0x10 */ s16 lengthA; // first length in ring buffer (from startPos, at most until end) + /* 0x12 */ s16 lengthB; // second length in ring buffer (from pos 0) }; // size = 0x14 struct SynthesisReverb { - /*0x00, 0x00, 0x00*/ u8 resampleFlags; - /*0x01, 0x01, 0x01*/ u8 useReverb; - /*0x02, 0x02, 0x02*/ u8 framesLeftToIgnore; - /*0x03, 0x03, 0x03*/ u8 curFrame; - /* 0x04, 0x04*/ u8 downsampleRate; - /* 0x06, 0x06*/ u16 windowSize; // same as bufSizePerChannel - /*0x04, 0x08, 0x0A*/ u16 reverbGain; - /*0x06, 0x0A, 0x0C*/ u16 resampleRate; - /*0x08, 0x0C, 0x14*/ s32 nextRingBufferPos; - /*0x0C, 0x10, 0x18*/ s32 unkC; // never read - /*0x10, 0x14, 0x1C*/ s32 bufSizePerChannel; + /* 0x00 */ u8 resampleFlags; + /* 0x01 */ u8 useReverb; + /* 0x02 */ u8 framesLeftToIgnore; + /* 0x03 */ u8 curFrame; + /* 0x04 */ u8 downsampleRate; + /* 0x05 */ // u8 compilerPadding; + /* 0x06 */ u16 windowSize; // same as bufSizePerChannel + /* 0x08 */ u16 reverbGain; + /* 0x0A */ u16 resampleRate; + /* 0x0C */ s32 nextRingBufferPos; + /* 0x10 */ s32 unkC; // never read + /* 0x14 */ s32 bufSizePerChannel; struct { - s16 *left; - s16 *right; + /* 0x18 */ s16 *left; + /* 0x1C */ s16 *right; } ringBuffer; - /*0x1C, 0x20, 0x28*/ s16 *resampleStateLeft; - /*0x20, 0x24, 0x2C*/ s16 *resampleStateRight; - /*0x24, 0x28, 0x30*/ s16 *unk24; // never read - /*0x28, 0x2C, 0x34*/ s16 *unk28; // never read - /*0x2C, 0x30, 0x38*/ struct ReverbRingBufferItem items[2][MAX_UPDATES_PER_FRAME]; - // Only used in sh: - /* 0x100*/ s16 *unk100; - /* 0x104*/ s16 *unk104; - /* 0x108*/ s16 *unk108; - /* 0x10C*/ s16 *unk10C; -}; // 0xCC <= size <= 0x10 + /* 0x20 */ s16 *resampleStateLeft; + /* 0x24 */ s16 *resampleStateRight; + /* 0x28 */ s16 *unk24; // never read + /* 0x2C */ s16 *unk28; // never read + /* 0x30 */ struct ReverbRingBufferItem items[2][MAX_UPDATES_PER_FRAME]; + /* 0xF8 */ s16 *unkF8; + /* 0xFC */ s16 *unkFC; + /* 0x100 */ s16 *unk100; + /* 0x104 */ s16 *unk104; +}; // size = 0x108 + +#define ALIGN(val, amnt) (((val) + (1 << amnt) - 1) & ~((1 << amnt) - 1)) + +u64 *synthesis_execute(u64 *cmdBuf, s32 *writtenCmds, s16 *aiBuf, s32 bufLen); +Acmd *synthesis_load_reverb_ring_buffer(Acmd*, u16, u16, s32, s32); +Acmd *synthesis_save_reverb_ring_buffer(Acmd*, u16, u16, s32, s32); +Acmd *func_800B7304(Acmd*, s32, s16, s16); +Acmd *func_800B7630(Acmd*, s16, s16); + +extern struct AudioBufferParametersEU gAudioBufferParameters; +extern s32 gMaxSimultaneousNotes; + extern struct SynthesisReverb gSynthesisReverbs[4]; extern s8 gNumSynthesisReverbs; extern struct NoteSubEu *gNoteSubsEu; @@ -55,6 +98,4 @@ extern f32 gLeftVolRampings; //extern f32 *gCurrentLeftVolRamping; // Points to any of the three left buffers above //extern f32 *gCurrentRightVolRamping; // Points to any of the three right buffers above -u64 *synthesis_execute(u64 *cmdBuf, s32 *writtenCmds, s16 *aiBuf, s32 bufLen); - #endif // AUDIO_SYNTHESIS_H