summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTyler McGavran <tyler.taggerung@gmail.com>2022-11-01 17:37:10 -0400
committerGitHub <noreply@github.com>2022-11-01 15:37:10 -0600
commit4e5946257d8049f421c4247d6039de94d3db83d5 (patch)
treeca99c55d584b13e431b99d2829ae5d7c6a2a7ecf /src
parent4647cdcd7e2a0f5b68265aac82d3a50d42aabfaa (diff)
Some matches for audio/synthesis (#268)
* Updated the Makefile to make the VERSION_US file get used when compiling stuff. * Updated the abi.h file to match SM64, with some modifications to support the currently targeted version (US). Signed-off-by: Taggerung <tyler.taggerung@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/audio/synthesis.c470
-rw-r--r--src/audio/synthesis.h113
2 files changed, 214 insertions, 369 deletions
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;
-}
- 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;
-}
-*/
-#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;
- }
- }
+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;
}
-// 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;
-
- }
- }
- }
+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/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
-
-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;
+Acmd *func_800B7630(Acmd *acmd, s16 reverbIndex, s16 updateIndex) {
+ struct ReverbRingBufferItem *item;
- 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