summaryrefslogtreecommitdiff
path: root/src/audio
diff options
context:
space:
mode:
authorMegaMech <MegaMech@users.noreply.github.com>2022-04-17 00:11:40 -0600
committerGitHub <noreply@github.com>2022-04-16 23:11:40 -0700
commite4e5f91be58aa5a08eb3b05ca1ea7803c8d91afa (patch)
treeeb9017e043bff83a3f3e1b1398db5cba5b5f657c /src/audio
parent13a11f0ffa97db0efee0e3ba5ab187d9f537aa92 (diff)
audio load.c decomp (#176)
Diffstat (limited to 'src/audio')
-rw-r--r--src/audio/data.h7
-rw-r--r--src/audio/effects.c4
-rw-r--r--src/audio/heap.c153
-rw-r--r--src/audio/heap.h27
-rw-r--r--src/audio/internal.h75
-rw-r--r--src/audio/load.c721
-rw-r--r--src/audio/load.h12
-rw-r--r--src/audio/playback.c26
-rw-r--r--src/audio/port_eu.c28
-rw-r--r--src/audio/synthesis.c64
10 files changed, 607 insertions, 510 deletions
diff --git a/src/audio/data.h b/src/audio/data.h
index cca619756..9dddc3e81 100644
--- a/src/audio/data.h
+++ b/src/audio/data.h
@@ -3,6 +3,13 @@
#include "internal.h"
+#define AUDIO_LOCK_UNINITIALIZED 0
+#define AUDIO_LOCK_NOT_LOADING 0x76557364
+#define AUDIO_LOCK_LOADING 0x19710515
+
extern struct AdsrEnvelope gDefaultEnvelope[3];
+// number of DMAs performed during this frame
+extern s32 gCurrAudioFrameDmaCount;
+
#endif
diff --git a/src/audio/effects.c b/src/audio/effects.c
index c436bdb09..cfaa049e6 100644
--- a/src/audio/effects.c
+++ b/src/audio/effects.c
@@ -314,7 +314,7 @@ GLOBAL_ASM("asm/non_matchings/audio/effects/func_800BE5BC.s")
#ifdef MIPS_TO_C
//generated by mips_to_c commit bd0364fa19633bd6201f8007e2d0a7ed87825909
-extern ? D_803B7088;
+extern ? gAudioBufferParameters;
f32 func_800BE5E0(void *arg0) {
f32 temp_f0;
@@ -352,7 +352,7 @@ loop_6:
arg0->unk1 = 0;
} else {
if (temp_a2 >= 4) {
- arg0->unk4 = ((temp_a2 * D_803B7088.unkC) / D_803B7088.unk0) / 4;
+ arg0->unk4 = ((temp_a2 * gAudioBufferParameters.unkC) / gAudioBufferParameters.unk0) / 4;
}
phi_a2 = arg0->unk4;
if (arg0->unk4 == 0) {
diff --git a/src/audio/heap.c b/src/audio/heap.c
index 2f5e9d08f..6e05f6b69 100644
--- a/src/audio/heap.c
+++ b/src/audio/heap.c
@@ -1,5 +1,8 @@
#include <ultra64.h>
#include <macros.h>
+#include "heap.h"
+
+extern struct SoundAllocPool gNotesAndBuffersPool;
#ifdef MIPS_TO_C
//generated by mips_to_c commit 3c3b0cede1a99430bfd3edf8d385802b94f91307
@@ -61,7 +64,7 @@ GLOBAL_ASM("asm/non_matchings/audio/heap/func_800B8DE0.s")
? func_800BF004(? *, void *); // extern
extern s32 D_803B1508;
extern ? D_803B5FC8;
-extern s32 D_803B70B0;
+extern s32 gMaxSimultaneousNotes;
void func_800B8EA8(s32 arg0) {
s32 temp_s2;
@@ -73,7 +76,7 @@ void func_800B8EA8(s32 arg0) {
s32 phi_s2;
s32 phi_v0;
- temp_v0 = D_803B70B0;
+ temp_v0 = gMaxSimultaneousNotes;
phi_s2 = 0;
phi_v0 = temp_v0;
if (temp_v0 > 0) {
@@ -90,7 +93,7 @@ void func_800B8EA8(s32 arg0) {
func_800BCB48(temp_s0);
func_800BD6F4(temp_s0);
func_800BF004(&D_803B5FC8, temp_s0);
- phi_v0 = D_803B70B0;
+ phi_v0 = gMaxSimultaneousNotes;
}
temp_s2 = phi_s2 + 1;
phi_s1 += 0xC0;
@@ -127,7 +130,7 @@ GLOBAL_ASM("asm/non_matchings/audio/heap/func_800B8F8C.s")
#ifdef MIPS_TO_C
//generated by mips_to_c commit 3c3b0cede1a99430bfd3edf8d385802b94f91307
-u32 func_800B8FFC(void *arg0, s32 arg1) {
+u32 soundAlloc(void *arg0, s32 arg1) {
s32 temp_t6;
s8 *temp_a1;
u32 temp_a2;
@@ -153,7 +156,7 @@ u32 func_800B8FFC(void *arg0, s32 arg1) {
return 0;
}
#else
-GLOBAL_ASM("asm/non_matchings/audio/heap/func_800B8FFC.s")
+GLOBAL_ASM("asm/non_matchings/audio/heap/soundAlloc.s")
#endif
#ifdef MIPS_TO_C
@@ -222,16 +225,16 @@ GLOBAL_ASM("asm/non_matchings/audio/heap/func_800B90F0.s")
#ifdef MIPS_TO_C
//generated by mips_to_c commit 3c3b0cede1a99430bfd3edf8d385802b94f91307
-s32 func_800B8FFC(? *, s32); // extern
+s32 soundAlloc(? *, s32); // extern
? func_800B907C(? *, s32, s32); // extern
extern ? D_803AFBC8;
-extern ? D_803AFBE8;
+extern ? gNotesAndBuffersPool;
extern ? D_803AFC18;
void func_800B914C(void *arg0) {
D_803AFBC8.unk4 = D_803AFBC8.unk0;
- func_800B907C(&D_803AFBE8, func_800B8FFC(&D_803AFBC8, arg0->unk0), arg0->unk0);
- func_800B907C(&D_803AFC18, func_800B8FFC(&D_803AFBC8, arg0->unkC), arg0->unkC);
+ func_800B907C(&gNotesAndBuffersPool, soundAlloc(&D_803AFBC8, arg0->unk0), arg0->unk0);
+ func_800B907C(&D_803AFC18, soundAlloc(&D_803AFBC8, arg0->unkC), arg0->unkC);
}
#else
GLOBAL_ASM("asm/non_matchings/audio/heap/func_800B914C.s")
@@ -239,7 +242,7 @@ GLOBAL_ASM("asm/non_matchings/audio/heap/func_800B914C.s")
#ifdef MIPS_TO_C
//generated by mips_to_c commit 3c3b0cede1a99430bfd3edf8d385802b94f91307
-s32 func_800B8FFC(? *, s32); // extern
+s32 soundAlloc(? *, s32); // extern
? func_800B907C(? *, s32, s32); // extern
extern ? D_803AFC18;
extern ? D_803AFC28;
@@ -247,8 +250,8 @@ extern ? D_803AFC38;
void func_800B91C8(void *arg0) {
D_803AFC18.unk4 = D_803AFC18.unk0;
- func_800B907C(&D_803AFC28, func_800B8FFC(&D_803AFC18, arg0->unk0), arg0->unk0);
- func_800B907C(&D_803AFC38, func_800B8FFC(&D_803AFC18, arg0->unk4), arg0->unk4);
+ func_800B907C(&D_803AFC28, soundAlloc(&D_803AFC18, arg0->unk0), arg0->unk0);
+ func_800B907C(&D_803AFC38, soundAlloc(&D_803AFC18, arg0->unk4), arg0->unk4);
}
#else
GLOBAL_ASM("asm/non_matchings/audio/heap/func_800B91C8.s")
@@ -256,7 +259,7 @@ GLOBAL_ASM("asm/non_matchings/audio/heap/func_800B91C8.s")
#ifdef MIPS_TO_C
//generated by mips_to_c commit 3c3b0cede1a99430bfd3edf8d385802b94f91307
-s32 func_800B8FFC(? *, s32); // extern
+s32 soundAlloc(? *, s32); // extern
? func_800B907C(? *, s32, s32); // extern
? func_800B909C(? *); // extern
extern ? D_803AFC28;
@@ -269,9 +272,9 @@ extern ? D_803AFFEC;
void func_800B9244(void *arg0) {
D_803AFC28.unk4 = D_803AFC28.unk0;
- func_800B907C(&D_803AFC4C, func_800B8FFC(&D_803AFC28, arg0->unk0), arg0->unk0);
- func_800B907C(&D_803AFE1C, func_800B8FFC(&D_803AFC28, arg0->unk4), arg0->unk4);
- func_800B907C(&D_803AFFEC, func_800B8FFC(&D_803AFC28, arg0->unk8), arg0->unk8);
+ func_800B907C(&D_803AFC4C, soundAlloc(&D_803AFC28, arg0->unk0), arg0->unk0);
+ func_800B907C(&D_803AFE1C, soundAlloc(&D_803AFC28, arg0->unk4), arg0->unk4);
+ func_800B907C(&D_803AFFEC, soundAlloc(&D_803AFC28, arg0->unk8), arg0->unk8);
func_800B909C(&D_803AFC48);
func_800B909C(&D_803AFE18);
func_800B909C(&D_803AFFE8);
@@ -282,7 +285,7 @@ GLOBAL_ASM("asm/non_matchings/audio/heap/func_800B9244.s")
#ifdef MIPS_TO_C
//generated by mips_to_c commit 3c3b0cede1a99430bfd3edf8d385802b94f91307
-s32 func_800B8FFC(? *, s32); // extern
+s32 soundAlloc(? *, s32); // extern
? func_800B907C(? *, s32, s32); // extern
? func_800B90B0(? *); // extern
extern ? D_803AFC38;
@@ -295,9 +298,9 @@ extern ? D_803B0180;
void func_800B9300(void *arg0) {
D_803AFC38.unk4 = D_803AFC38.unk0;
- func_800B907C(&D_803AFDE0, func_800B8FFC(&D_803AFC38, arg0->unk0), arg0->unk0);
- func_800B907C(&D_803AFFB0, func_800B8FFC(&D_803AFC38, arg0->unk4), arg0->unk4);
- func_800B907C(&D_803B0180, func_800B8FFC(&D_803AFC38, arg0->unk8), arg0->unk8);
+ func_800B907C(&D_803AFDE0, soundAlloc(&D_803AFC38, arg0->unk0), arg0->unk0);
+ func_800B907C(&D_803AFFB0, soundAlloc(&D_803AFC38, arg0->unk4), arg0->unk4);
+ func_800B907C(&D_803B0180, soundAlloc(&D_803AFC38, arg0->unk8), arg0->unk8);
func_800B90B0(&D_803AFDDC);
func_800B90B0(&D_803AFFAC);
func_800B90B0(&D_803B017C);
@@ -310,7 +313,7 @@ GLOBAL_ASM("asm/non_matchings/audio/heap/func_800B9300.s")
//generated by mips_to_c commit 3c3b0cede1a99430bfd3edf8d385802b94f91307
? func_800B8EA8(s16, s32, s16, s32 *); // extern
? func_800B8F8C(s16, s32); // extern
-s32 func_800B8FFC(s32, s32); // extern
+s32 soundAlloc(s32, s32); // extern
extern ? D_803AFC48;
extern ? D_803AFE18;
extern ? D_803AFFE8;
@@ -320,7 +323,7 @@ extern ? D_803B0400;
extern void *D_803B1508;
extern ? D_803B1510;
extern ? D_803B1A30;
-extern s32 D_803B70B0;
+extern s32 gMaxSimultaneousNotes;
u32 func_800B93BC(s32 *arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4) {
? *sp34;
@@ -426,7 +429,7 @@ loop_1:
phi_t2_2 = phi_t2;
if (sp33 == 1) {
if (phi_t1 == 4) {
- temp_a1 = D_803B70B0;
+ temp_a1 = gMaxSimultaneousNotes;
phi_v1 = 0;
phi_v1_2 = 0;
if (temp_a1 > 0) {
@@ -452,7 +455,7 @@ loop_18:
}
}
if (phi_t2 == 4) {
- temp_a1_2 = D_803B70B0;
+ temp_a1_2 = gMaxSimultaneousNotes;
phi_v1_3 = 0;
phi_v1_4 = 0;
if (temp_a1_2 > 0) {
@@ -546,7 +549,7 @@ loop_54:
}
if (sp20 == 1) {
if (phi_t1_2 == 2) {
- temp_a1_3 = D_803B70B0;
+ temp_a1_3 = gMaxSimultaneousNotes;
phi_v1_5 = 0;
phi_v1_6 = 0;
if (temp_a1_3 > 0) {
@@ -576,7 +579,7 @@ block_68:
phi_a2 = phi_a2_2;
phi_a2 = phi_a2_2;
if (phi_t2_2 == 2) {
- temp_a1_4 = D_803B70B0;
+ temp_a1_4 = gMaxSimultaneousNotes;
phi_v1_7 = 0;
phi_v1_8 = 0;
if (temp_a1_4 > 0) {
@@ -717,7 +720,7 @@ block_99:
}
arg4 = arg4;
arg3 = phi_a3;
- temp_v0_9 = func_800B8FFC(arg0 + 4, arg1 * arg2);
+ temp_v0_9 = soundAlloc(arg0 + 4, arg1 * arg2);
(arg0 + (*arg0 * 0xC))->unk14 = temp_v0_9;
if (temp_v0_9 == 0) {
if ((arg3 != 0) && (arg3 != 1)) {
@@ -855,7 +858,7 @@ GLOBAL_ASM("asm/non_matchings/audio/heap/func_800B9FB8.s")
? func_800BEF2C(? *); /* extern */
extern ? D_803B1510;
extern ? D_803B1A30;
-extern ? D_803B7088;
+extern ? gAudioBufferParameters;
s32 func_800BA00C(void) {
? *temp_s0;
@@ -894,7 +897,7 @@ s32 func_800BA00C(void) {
D_803B0504 = temp_v0 - 1;
func_800B9FB8();
} else {
- temp_a2 = D_803B70B0;
+ temp_a2 = gMaxSimultaneousNotes;
phi_v1 = 0;
phi_a0 = 0;
phi_a2 = temp_a2;
@@ -904,10 +907,10 @@ s32 func_800BA00C(void) {
temp_v0_2 = D_803B1508 + phi_v1;
phi_a0 = temp_a0;
if (((temp_v0_2->unkB0 >> 0x1F) != 0) && (temp_v0_2->unk59 != 0)) {
- temp_v0_2->unk68 = D_803B7088.unk18;
+ temp_v0_2->unk68 = gAudioBufferParameters.unk18;
temp_v0_3 = D_803B1508 + phi_v1;
temp_v0_3->unk58 = temp_v0_3->unk58 | 0x10;
- phi_a2 = D_803B70B0;
+ phi_a2 = gMaxSimultaneousNotes;
}
phi_v1 += 0xC0;
} while (temp_a0 < phi_a2);
@@ -967,7 +970,7 @@ GLOBAL_ASM("asm/non_matchings/audio/heap/func_800BA00C.s")
#ifdef MIPS_TO_C
//generated by mips_to_c commit 3c3b0cede1a99430bfd3edf8d385802b94f91307
? func_800B8DE0(); // extern
-s32 func_800B8FFC(? *, s32); // extern
+s32 soundAlloc(? *, s32); // extern
? func_800B914C(? *, s16, s16, u16); // extern
? func_800B91C8(? *); // extern
? func_800B9244(? *); // extern
@@ -985,17 +988,17 @@ extern u16 D_803AFBC0;
extern u8 D_803AFBC3;
extern s32 D_803AFBC4;
extern s32 D_803AFBD0;
-extern ? D_803AFBE8;
+extern ? gNotesAndBuffersPool;
extern ? D_803B0348;
extern ? D_803B0358;
extern ? D_803B0360;
extern ? D_803B0370;
extern u8 D_803B0501;
extern s32 D_803B1508;
-extern s32 D_803B6E58;
-extern ? D_803B7088;
+extern s32 gSampleDmaNumListItems;
+extern ? gAudioBufferParameters;
extern s32 D_803B70AC;
-extern s32 D_803B70B0;
+extern s32 gMaxSimultaneousNotes;
extern s16 D_803B70B4;
extern ? D_803B70C8;
extern ? D_803B70D0;
@@ -1034,36 +1037,36 @@ void func_800BA250(void) {
s32 phi_s1;
temp_s6 = (D_803B0501 * 0x28) + &D_800EA4D8;
- D_803B6E58 = 0;
+ gSampleDmaNumListItems = 0;
temp_t9 = temp_s6->unk0;
- D_803B7088.unk2 = temp_t9;
- D_803B7088.unk4 = osAiSetFrequency(temp_t9 & 0xFFFF);
- temp_a3 = D_803B7088.unk2;
- D_803B7088.unk6 = ((temp_a3 / D_803B717C) + 0xF) & 0xFFF0;
- temp_v1 = D_803B7088.unk6;
+ gAudioBufferParameters.unk2 = temp_t9;
+ gAudioBufferParameters.unk4 = osAiSetFrequency(temp_t9 & 0xFFFF);
+ temp_a3 = gAudioBufferParameters.unk2;
+ gAudioBufferParameters.unk6 = ((temp_a3 / D_803B717C) + 0xF) & 0xFFF0;
+ temp_v1 = gAudioBufferParameters.unk6;
temp_t0 = temp_v1 + 0x10;
- D_803B7088.unkA = temp_v1 - 0x10;
- D_803B7088.unk8 = temp_t0;
- D_803B7088.unkC = (temp_t0 / 0xC0) + 1;
- temp_a2 = D_803B7088.unkC;
- D_803B7088.unkE = (temp_v1 / temp_a2) & 0xFFF8;
- temp_t1 = D_803B7088.unkE;
+ gAudioBufferParameters.unkA = temp_v1 - 0x10;
+ gAudioBufferParameters.unk8 = temp_t0;
+ gAudioBufferParameters.unkC = (temp_t0 / 0xC0) + 1;
+ temp_a2 = gAudioBufferParameters.unkC;
+ gAudioBufferParameters.unkE = (temp_v1 / temp_a2) & 0xFFF8;
+ temp_t1 = gAudioBufferParameters.unkE;
temp_f0 = temp_a2;
- D_803B7088.unk10 = temp_t1 + 8;
- D_803B7088.unk12 = temp_t1 - 8;
- D_803B7088.unk14 = 32000.0f / temp_a3;
- D_803B7088.unk1C = D_800F2E98 / temp_f0;
- D_803B7088.unk18 = 1.0f / temp_f0;
- D_803B70B0 = temp_s6->unk5;
+ gAudioBufferParameters.unk10 = temp_t1 + 8;
+ gAudioBufferParameters.unk12 = temp_t1 - 8;
+ gAudioBufferParameters.unk14 = 32000.0f / temp_a3;
+ gAudioBufferParameters.unk1C = D_800F2E98 / temp_f0;
+ gAudioBufferParameters.unk18 = 1.0f / temp_f0;
+ gMaxSimultaneousNotes = temp_s6->unk5;
D_803AFBC0 = temp_s6->unkC;
D_803B70B4 = ((temp_f0 * D_800F2E9C) / D_800EA5CC) / D_803B7178;
- D_803B7088.unk0 = temp_s6->unk4;
- temp_a1 = D_803B7088.unk0;
- D_803B7088.unk6 = temp_v1 * temp_a1;
- D_803B7088.unk8 = D_803B7088.unk8 * temp_a1;
- D_803B7088.unkA = D_803B7088.unkA * temp_a1;
- D_803B7088.unkC = temp_a2 * temp_a1;
- D_803B70AC = (D_803B70B0 * 0x14 * D_803B7088.unkC) + (temp_s6->unk6 << 5) + 0x1E0;
+ gAudioBufferParameters.unk0 = temp_s6->unk4;
+ temp_a1 = gAudioBufferParameters.unk0;
+ gAudioBufferParameters.unk6 = temp_v1 * temp_a1;
+ gAudioBufferParameters.unk8 = gAudioBufferParameters.unk8 * temp_a1;
+ gAudioBufferParameters.unkA = gAudioBufferParameters.unkA * temp_a1;
+ gAudioBufferParameters.unkC = temp_a2 * temp_a1;
+ D_803B70AC = (gMaxSimultaneousNotes * 0x14 * gAudioBufferParameters.unkC) + (temp_s6->unk6 << 5) + 0x1E0;
temp_s0 = temp_s6->unk10 + temp_s6->unk14 + temp_s6->unk18;
temp_s1 = temp_s6->unk1C + temp_s6->unk20 + temp_s6->unk24;
temp_t2 = temp_s0 + temp_s1;
@@ -1082,14 +1085,14 @@ void func_800BA250(void) {
D_803B0370.unk8 = temp_s6->unk24;
func_800B9300(&D_803B0370);
func_800B8DE0();
- D_803B1508 = func_800B8FFC(&D_803AFBE8, D_803B70B0 * 0xC0);
+ D_803B1508 = soundAlloc(&gNotesAndBuffersPool, gMaxSimultaneousNotes * 0xC0);
func_800BDD34();
func_800BD368();
- D_803AFBC4 = func_800B8FFC(&D_803AFBE8, D_803B7088.unkC * D_803B70B0 * 0x10);
+ D_803AFBC4 = soundAlloc(&gNotesAndBuffersPool, gAudioBufferParameters.unkC * gMaxSimultaneousNotes * 0x10);
phi_s0 = &D_803B70C8;
do {
temp_s0_2 = phi_s0 + 4;
- temp_s0_2->unk-4 = func_800B8FFC(&D_803AFBE8, D_803B70AC * 8);
+ temp_s0_2->unk-4 = soundAlloc(&gNotesAndBuffersPool, D_803B70AC * 8);
phi_s0 = temp_s0_2;
} while (temp_s0_2 != &D_803B70D0);
phi_s2 = &D_803AF790;
@@ -1109,9 +1112,9 @@ void func_800BA250(void) {
phi_s2_2->unk4 = temp_v0->unk0;
phi_s2_2->unk1 = 8;
phi_s2_2->unk8 = temp_v0->unk2;
- phi_s2_2->unk18 = func_800B8FFC(&D_803AFBE8, (temp_t7 & 0xFFFF) * 2);
+ phi_s2_2->unk18 = soundAlloc(&gNotesAndBuffersPool, (temp_t7 & 0xFFFF) * 2);
temp_v1_2 = phi_s2_2->unk4;
- phi_s2_2->unk1C = func_800B8FFC(&D_803AFBE8, phi_s2_2->unk6 * 2);
+ phi_s2_2->unk1C = soundAlloc(&gNotesAndBuffersPool, phi_s2_2->unk6 * 2);
phi_s2_2->unkC = 0;
phi_s2_2->unk10 = 0;
phi_s2_2->unk3 = 0;
@@ -1120,26 +1123,26 @@ void func_800BA250(void) {
if (temp_v1_2 != 1) {
phi_s2_2->unk0 = 1;
phi_s2_2->unkA = 0x8000 / temp_v1_2;
- phi_s2_2->unk20 = func_800B8FFC(&D_803AFBE8, 0x20);
- phi_s2_2->unk24 = func_800B8FFC(&D_803AFBE8, 0x20);
- phi_s2_2->unk28 = func_800B8FFC(&D_803AFBE8, 0x20);
- phi_s2_2->unk2C = func_800B8FFC(&D_803AFBE8, 0x20);
+ phi_s2_2->unk20 = soundAlloc(&gNotesAndBuffersPool, 0x20);
+ phi_s2_2->unk24 = soundAlloc(&gNotesAndBuffersPool, 0x20);
+ phi_s2_2->unk28 = soundAlloc(&gNotesAndBuffersPool, 0x20);
+ phi_s2_2->unk2C = soundAlloc(&gNotesAndBuffersPool, 0x20);
phi_s1 = 0;
- if (D_803B7088.unkC > 0) {
+ if (gAudioBufferParameters.unkC > 0) {
phi_s0_2 = phi_s2_2;
do {
- temp_v0_2 = func_800B8FFC(&D_803AFBE8, 0x300);
+ temp_v0_2 = soundAlloc(&gNotesAndBuffersPool, 0x300);
temp_t6 = temp_v0_2 + 0x180;
phi_s0_2->unk34 = temp_v0_2;
phi_s0_2->unk38 = temp_t6;
- temp_v0_3 = func_800B8FFC(&D_803AFBE8, 0x300);
+ temp_v0_3 = soundAlloc(&gNotesAndBuffersPool, 0x300);
temp_t8 = temp_v0_3 + 0x180;
phi_s0_2->unk98 = temp_v0_3;
phi_s0_2->unk9C = temp_t8;
temp_s1_2 = phi_s1 + 1;
phi_s0_2 += 0x14;
phi_s1 = temp_s1_2;
- } while (temp_s1_2 < D_803B7088.unkC);
+ } while (temp_s1_2 < gAudioBufferParameters.unkC);
}
}
temp_s5 = phi_s5 + 1;
@@ -1147,7 +1150,7 @@ void func_800BA250(void) {
phi_s2_2 += 0x108;
} while (temp_s5 < D_803AFBC3);
}
- func_800BB030(D_803B70B0);
+ func_800BB030(gMaxSimultaneousNotes);
osWritebackDCacheAll();
}
#else
diff --git a/src/audio/heap.h b/src/audio/heap.h
new file mode 100644
index 000000000..7ca2f2b3d
--- /dev/null
+++ b/src/audio/heap.h
@@ -0,0 +1,27 @@
+#ifndef AUDIO_HEAP_H
+#define AUDIO_HEAP_H
+
+#include <PR/ultratypes.h>
+
+#include "internal.h"
+
+#define SOUND_LOAD_STATUS_NOT_LOADED 0
+#define SOUND_LOAD_STATUS_IN_PROGRESS 1
+#define SOUND_LOAD_STATUS_COMPLETE 2
+#define SOUND_LOAD_STATUS_DISCARDABLE 3
+#define SOUND_LOAD_STATUS_4 4
+#define SOUND_LOAD_STATUS_5 5
+
+#define IS_BANK_LOAD_COMPLETE(bankId) (gBankLoadStatus[bankId] >= SOUND_LOAD_STATUS_COMPLETE)
+#define IS_SEQ_LOAD_COMPLETE(seqId) (gSeqLoadStatus[seqId] >= SOUND_LOAD_STATUS_COMPLETE)
+
+struct SoundAllocPool {
+ u8 *start;
+ u8 *cur;
+ u32 size;
+ s32 numAllocatedEntries;
+}; // size = 0x10
+
+extern struct SoundAllocPool gNotesAndBuffersPool;
+
+#endif // AUDIO_HEAP_H \ No newline at end of file
diff --git a/src/audio/internal.h b/src/audio/internal.h
index afcabb180..f9bbc5593 100644
--- a/src/audio/internal.h
+++ b/src/audio/internal.h
@@ -3,11 +3,57 @@
#include <PR/ultratypes.h>
+
+// No-op printf macro which leaves string literals in rodata in IDO. IDO
+// doesn't support variadic macros, so instead we let the parameter list
+// expand to a no-op comma expression. Another possibility is that it might
+// have expanded to something with "if (0)". See also goddard/gd_main.h.
+// On US/JP, -sopt optimizes away these except for external.c.
+#ifdef __sgi
+#define stubbed_printf
+#else
+#define stubbed_printf(...)
+#endif
+
+#define stubbed_printf_0(msg) stubbed_printf(msg)
+#define stubbed_printf_1(msg, a) stubbed_printf(msg, a)
+#define stubbed_printf_2(msg, a, b) stubbed_printf(msg, a, b)
+#define stubbed_printf_3(msg, a, b, c) stubbed_printf(msg, a, b, c)
+
+
struct AdsrEnvelope {
s16 delay;
s16 arg;
}; // size = 0x4
+struct AdpcmLoop {
+ u32 start;
+ u32 end;
+ u32 count;
+ u32 pad;
+ s16 state[16]; // only exists if count != 0. 8-byte aligned
+};
+
+struct AdpcmBook {
+ s32 order;
+ s32 npredictors;
+ s16 book[1]; // size 8 * order * npredictors. 8-byte aligned
+};
+
+struct AudioBankSample {
+ u8 unused;
+ u8 loaded;
+ u8 *sampleAddr;
+ struct AdpcmLoop *loop;
+ struct AdpcmBook *book;
+ u32 sampleSize; // never read. either 0 or 1 mod 9, depending on padding
+};
+
+struct AudioBankSound {
+ struct AudioBankSample *sample;
+ f32 tuning; // frequency scale factor
+}; // size = 0x8
+
struct NoteSub
{
/*0x00*/ volatile u8 enabled : 1;
@@ -35,4 +81,33 @@ struct NoteSub
} sound;
};
+struct AudioSessionSettings {
+ /*0x00*/ u32 frequency;
+ /*0x04*/ u8 maxSimultaneousNotes;
+ /*0x05*/ u8 reverbDownsampleRate; // always 1
+ /*0x06*/ u16 reverbWindowSize;
+ /*0x08*/ u16 reverbGain;
+ /*0x0A*/ u16 volume;
+ /*0x0C*/ u32 persistentSeqMem;
+ /*0x10*/ u32 persistentBankMem;
+ /*0x14*/ u32 temporarySeqMem;
+ /*0x18*/ u32 temporaryBankMem;
+}; // size = 0x1C
+
+struct AudioBufferParametersEU {
+ /*0x00*/ s16 presetUnk4; // audio frames per vsync?
+ /*0x02*/ u16 frequency;
+ /*0x04*/ u16 aiFrequency; // ?16
+ /*0x06*/ s16 samplesPerFrameTarget;
+ /*0x08*/ s16 maxAiBufferLength;
+ /*0x0A*/ s16 minAiBufferLength;
+ /*0x0C*/ s16 updatesPerFrame;
+ /*0x0E*/ s16 samplesPerUpdate;
+ /*0x10*/ s16 samplesPerUpdateMax;
+ /*0x12*/ s16 samplesPerUpdateMin;
+ /*0x14*/ f32 resampleRate; // contains 32000.0f / frequency
+ /*0x18*/ f32 updatesPerFrameInv; // 1.0f / updatesPerFrame
+ /*0x1C*/ f32 unkUpdatesPerFrameScaled; // 3.0f / (1280.0f * updatesPerFrame)
+};
+
#endif
diff --git a/src/audio/load.c b/src/audio/load.c
index 8dbd8cee0..c0f39c0a4 100644
--- a/src/audio/load.c
+++ b/src/audio/load.c
@@ -1,145 +1,248 @@
#include <ultra64.h>
#include <macros.h>
+#include "load.h"
+#include "data.h"
+#include "heap.h"
+#include "internal.h"
+
+#define ALIGN16(val) (((val) + 0xF) & ~0xF)
+struct SharedDma {
+ /*0x0*/ u8 *buffer; // target, points to pre-allocated buffer
+ /*0x4*/ uintptr_t source; // device address
+ /*0x8*/ u16 sizeUnused; // set to bufSize, never read
+ /*0xA*/ u16 bufSize; // size of buffer
+ /*0xC*/ u8 unused2; // set to 0, never read
+ /*0xD*/ u8 reuseIndex; // position in sSampleDmaReuseQueue1/2, if ttl == 0
+ /*0xE*/ u8 ttl; // duration after which the DMA can be discarded
+}; // size = 0x10
-#ifdef MIPS_TO_C
-//generated by mips_to_c commit 3c3b0cede1a99430bfd3edf8d385802b94f91307
-? osPiStartDma(? *, ?, ?, s32, void *, u32, OSMesgQueue *); // extern
extern OSMesgQueue D_803B6720;
-extern ? D_803B6740;
-
-void func_800BAA80(s32 arg0, void *arg1, u32 arg2) {
- osInvalDCache(arg1, arg2);
- osPiStartDma(&D_803B6740, 1, 0, arg0, arg1, arg2, &D_803B6720);
- osRecvMesg(&D_803B6720, NULL, 1);
+extern OSIoMesg D_803B6740;
+
+extern OSMesgQueue gCurrAudioFrameDmaQueue; // gCurrAudioFrameDmaQueue
+extern OSMesg gCurrAudioFrameDmaMesgBufs[AUDIO_FRAME_DMA_QUEUE_SIZE]; // gCurrAudioFrameDmaMesgBufs
+extern OSIoMesg gCurrAudioFrameDmaIoMesgBufs[AUDIO_FRAME_DMA_QUEUE_SIZE]; // gCurrAudioFrameDmaIoMesgBufs
+
+extern struct SharedDma sSampleDmas[0x60]; // sSampleDmas
+extern u32 gSampleDmaNumListItems; // gSampleDmaNumListItems
+extern u32 sSampleDmaListSize1; // sSampleDmaListSize1
+extern s32 D_803B6E60; // sUnused80226B40
+
+extern u8 sSampleDmaReuseQueue1[256]; // sSampleDmaReuseQueue1
+extern u8 sSampleDmaReuseQueue2[256]; // sSampleDmaReuseQueue2
+extern u8 sSampleDmaReuseQueueTail1; // sSampleDmaReuseQueueTail1
+extern u8 sSampleDmaReuseQueueTail2; // sSampleDmaReuseQueueTail2
+extern u8 sSampleDmaReuseQueueHead1; // sSampleDmaReuseQueueHead1
+extern u8 sSampleDmaReuseQueueHead2; // sSampleDmaReuseQueueHead2
+
+
+
+extern void *soundAlloc(struct SoundAllocPool *pool, u32 size);
+
+/**
+ * Performs an immediate DMA copy
+ */
+// audio_dma_copy_immediate
+void audio_dma_copy_immediate(uintptr_t devAddr, void *vAddr, size_t nbytes) {
+ stubbed_printf_3("Romcopy %x -> %x ,size %x\n", devAddr, vAddr, nbytes);
+ osInvalDCache(vAddr, nbytes);
+ osPiStartDma(&D_803B6740, OS_MESG_PRI_HIGH, OS_READ, devAddr, vAddr, nbytes, &D_803B6720);
+ osRecvMesg(&D_803B6720, NULL, OS_MESG_BLOCK);
+ stubbed_printf_0("Romcopyend\n");
}
-#else
-GLOBAL_ASM("asm/non_matchings/audio/load/func_800BAA80.s")
-#endif
-#ifdef MIPS_TO_C
-//generated by mips_to_c commit 3c3b0cede1a99430bfd3edf8d385802b94f91307
-? osPiStartDma(s32, ?, ?, s32, void *, u32, s32); // extern
-
-void func_800BAAF8(s32 arg0, void *arg1, u32 arg2, s32 arg3, s32 arg4) {
- osInvalDCache(arg1, arg2);
- osPiStartDma(arg4, 0, 0, arg0, arg1, arg2, arg3);
+const char audioString34[] = "CAUTION:WAVE CACHE FULL %d";
+const char audioString35[] = "LOAD Rom :%x -> Ram :%x Len:%x\n";
+const char audioString36[] = "BASE %x %x\n";
+const char audioString37[] = "LOAD %x %x %x\n";
+const char audioString38[] = "INSTTOP %x\n";
+const char audioString39[] = "INSTMAP[0] %x\n";
+const char audioString40[] = "already flags %d\n";
+const char audioString41[] = "already flags %d\n";
+const char audioString42[] = "ERR:SLOW BANK DMA BUSY\n";
+const char audioString43[] = "ERR:SLOW DMA BUSY\n";
+const char audioString44[] = "Check %d bank %d\n";
+const char audioString45[] = "Cache Check\n";
+const char audioString46[] = "NO BANK ERROR\n";
+const char audioString47[] = "BANK %d LOADING START\n";
+const char audioString48[] = "BANK %d LOAD MISS (NO MEMORY)!\n";
+const char audioString49[] = "BANK %d ALREADY CACHED\n";
+const char audioString50[] = "BANK LOAD MISS! FOR %d\n";
+
+
+const char audioString51[] = "Seq %d Loading Start\n";
+
+const char audioString52[] = "Heap Overflow Error\n";
+
+const char asdf[] = "SEQ %d ALREADY CACHED\n";
+const char fdsa[] = "Ok,one bank slow load Start \n";
+const char af[] = "Sorry,too many %d bank is none.fast load Start \n";
+
+
+
+/**
+ * Performs an asynchronus (normal priority) DMA copy
+ */
+//audio_dma_copy_async
+void func_800BAAF8(uintptr_t devAddr, void *vAddr, size_t nbytes, OSMesgQueue *queue, OSIoMesg *mesg) {
+ osInvalDCache(vAddr, nbytes);
+ osPiStartDma(mesg, OS_MESG_PRI_NORMAL, OS_READ, devAddr, vAddr, nbytes, queue);
}
-#else
-GLOBAL_ASM("asm/non_matchings/audio/load/func_800BAAF8.s")
-#endif
+//#else
+//GLOBAL_ASM("asm/non_matchings/audio/load/func_800BAAF8.s")
+//#endif
-#ifdef MIPS_TO_C
+//#ifdef MIPS_TO_C
//generated by mips_to_c commit 3c3b0cede1a99430bfd3edf8d385802b94f91307
-? osPiStartDma(s32, ?, ?, s32, void *, u32, s32); // extern
-
-void func_800BAB58(s32 *arg0, void **arg1, s32 *arg2, s32 arg3, s32 arg4) {
- s32 temp_v0;
- u32 phi_s0;
+//? osPiStartDma(s32, ?, ?, s32, void *, u32, s32); // extern
+
+
+/**
+ * Performs a partial asynchronous (normal priority) DMA copy. This is limited
+ * to 0x1000 bytes transfer at once.
+ */
+// audio_dma_partial_copy_async
+void func_800BAB58(uintptr_t *devAddr, u8 **vAddr, ssize_t *remaining, OSMesgQueue *queue, OSIoMesg *mesg) {
+ ssize_t transfer = (*remaining >= 0x1000 ? 0x1000 : *remaining);
+ *remaining -= transfer;
+ osInvalDCache(*vAddr, transfer);
+ osPiStartDma(mesg, OS_MESG_PRI_NORMAL, OS_READ, *devAddr, *vAddr, transfer, queue);
+ *devAddr += transfer;
+ *vAddr += transfer;
+}
+//#else
+//GLOBAL_ASM("asm/non_matchings/audio/load/func_800BAB58.s")
+//#endif
+
+// decrease_sample_dma_ttls
+
+void func_800BAC04() {
+ u32 i;
+
+ for (i = 0; i < sSampleDmaListSize1; i++) {
+ struct SharedDma *temp = &sSampleDmas[i];
+ if (temp->ttl != 0) {
+ temp->ttl--;
+ if (temp->ttl == 0) {
+ temp->reuseIndex = sSampleDmaReuseQueueHead1;
+ sSampleDmaReuseQueue1[sSampleDmaReuseQueueHead1++] = (u8) i;
+ }
+ }
+ }
- temp_v0 = *arg2;
- phi_s0 = temp_v0;
- if (temp_v0 >= 0x1000) {
- phi_s0 = 0x1000;
+ for (i = sSampleDmaListSize1; i < gSampleDmaNumListItems; i++) {
+ struct SharedDma *temp = &sSampleDmas[i];
+ if (temp->ttl != 0) {
+ temp->ttl--;
+ if (temp->ttl == 0) {
+ temp->reuseIndex = sSampleDmaReuseQueueHead2;
+ sSampleDmaReuseQueue2[sSampleDmaReuseQueueHead2++] = (u8) i;
+ }
+ }
}
- *arg2 = temp_v0 - phi_s0;
- osInvalDCache(*arg1, phi_s0);
- osPiStartDma(arg4, 0, 0, *arg0, *arg1, phi_s0, arg3);
- *arg0 = *arg0 + phi_s0;
- *arg1 = *arg1 + phi_s0;
+
+ D_803B6E60 = 0;
}
-#else
-GLOBAL_ASM("asm/non_matchings/audio/load/func_800BAB58.s")
-#endif
#ifdef MIPS_TO_C
-//generated by mips_to_c commit 3c3b0cede1a99430bfd3edf8d385802b94f91307
-extern ? D_803B6758;
-extern u32 D_803B6E58;
-extern u32 D_803B6E5C;
-extern s32 D_803B6E60;
-extern ? D_803B6E68;
-extern ? D_803B6F68;
-extern u8 D_803B706A;
-extern u8 D_803B706B;
-
-void func_800BAC04(void) {
- u32 temp_v0;
- u32 temp_v0_2;
- u8 temp_t4;
- u8 temp_t6;
- u8 temp_t6_2;
- u8 temp_t8;
- u8 temp_v1;
- u8 temp_v1_2;
- u8 temp_v1_3;
- u8 temp_v1_4;
- ? *phi_a0;
- s8 phi_v0;
- void *phi_a0_2;
- s8 phi_v0_2;
-
- phi_a0 = &D_803B6758;
- phi_v0 = 0;
- if (D_803B6E5C != 0) {
- do {
- temp_v1 = phi_a0->unkE;
- temp_t6 = temp_v1 - 1;
- if (temp_v1 != 0) {
- phi_a0->unkE = temp_t6;
- if ((temp_t6 & 0xFF) == 0) {
- temp_v1_2 = D_803B706A;
- temp_t8 = D_803B706A;
- *(&D_803B6E68 + temp_v1_2) = phi_v0;
- D_803B706A = temp_v1_2 + 1;
- phi_a0->unkD = temp_t8;
+// dma_sample_data 3000 score diff
+void *func_800BAD0C(uintptr_t devAddr, u32 size, s32 arg2, u8 *dmaIndexRef) {
+ s32 hasDma = FALSE;
+ struct SharedDma *dma;
+ uintptr_t dmaDevAddr;
+ u32 transfer;
+ u32 i;
+ u32 dmaIndex;
+ ssize_t bufferPos;
+ UNUSED u32 pad;
+
+ if (arg2 != 0 || *dmaIndexRef >= sSampleDmaListSize1) {
+ for (i = sSampleDmaListSize1; i < gSampleDmaNumListItems; i++) {
+ dma = &sSampleDmas[i];
+ bufferPos = devAddr - dma->source;
+ if (0 <= bufferPos && (size_t) bufferPos <= dma->bufSize - size) {
+ // We already have a DMA request for this memory range.
+ if (dma->ttl == 0 && sSampleDmaReuseQueueTail2 != sSampleDmaReuseQueueHead2) {
+ // Move the DMA out of the reuse queue, by swapping it with the
+ // tail, and then incrementing the tail.
+ if (dma->reuseIndex != sSampleDmaReuseQueueTail2) {
+ sSampleDmaReuseQueue2[dma->reuseIndex] =
+ sSampleDmaReuseQueue2[sSampleDmaReuseQueueTail2];
+ sSampleDmas[sSampleDmaReuseQueue2[sSampleDmaReuseQueueTail2]].reuseIndex =
+ dma->reuseIndex;
+ }
+ sSampleDmaReuseQueueTail2++;
}
+ dma->ttl = 60;
+ *dmaIndexRef = (u8) i;
+ return &dma->buffer[(devAddr - dma->source)];
}
- temp_v0 = phi_v0 + 1;
- phi_a0 += 0x10;
- phi_v0 = temp_v0;
- } while (temp_v0 < D_803B6E5C);
- }
- phi_v0_2 = D_803B6E5C;
- if (D_803B6E5C < D_803B6E58) {
- phi_a0_2 = (D_803B6E5C * 0x10) + &D_803B6758;
- do {
- temp_v1_3 = phi_a0_2->unkE;
- temp_t4 = temp_v1_3 - 1;
- if (temp_v1_3 != 0) {
- phi_a0_2->unkE = temp_t4;
- if ((temp_t4 & 0xFF) == 0) {
- temp_v1_4 = D_803B706B;
- temp_t6_2 = D_803B706B;
- *(&D_803B6F68 + temp_v1_4) = phi_v0_2;
- D_803B706B = temp_v1_4 + 1;
- phi_a0_2->unkD = temp_t6_2;
+ }
+
+ if (sSampleDmaReuseQueueTail2 != sSampleDmaReuseQueueHead2 && arg2 != 0) {
+ // Allocate a DMA from reuse queue 2. This queue can be empty, since
+ // TTL 60 is pretty large.
+ dmaIndex = sSampleDmaReuseQueue2[sSampleDmaReuseQueueTail2];
+ sSampleDmaReuseQueueTail2++;
+ dma = sSampleDmas + dmaIndex;
+ hasDma = TRUE;
+ }
+ } else {
+ dma = sSampleDmas;
+ dma += *dmaIndexRef;
+ bufferPos = devAddr - dma->source;
+ if (0 <= bufferPos && (size_t) bufferPos <= dma->bufSize - size) {
+ // We already have DMA for this memory range.
+ if (dma->ttl == 0) {
+ // Move the DMA out of the reuse queue, by swapping it with the
+ // tail, and then incrementing the tail.
+ if (dma->reuseIndex != sSampleDmaReuseQueueTail1) {
+ if (1) {
+ }
+ sSampleDmaReuseQueue1[dma->reuseIndex] =
+ sSampleDmaReuseQueue1[sSampleDmaReuseQueueTail1];
+ sSampleDmas[sSampleDmaReuseQueue1[sSampleDmaReuseQueueTail1]].reuseIndex =
+ dma->reuseIndex;
}
+ sSampleDmaReuseQueueTail1++;
}
- temp_v0_2 = phi_v0_2 + 1;
- phi_a0_2 += 0x10;
- phi_v0_2 = temp_v0_2;
- } while (temp_v0_2 < D_803B6E58);
+ dma->ttl = 2;
+ return dma->buffer + (devAddr - dma->source);
+ }
}
- D_803B6E60 = 0;
+
+ if (!hasDma) {
+ // Allocate a DMA from reuse queue 1. This queue will hopefully never
+ // be empty, since TTL 2 is so small.
+ dmaIndex = sSampleDmaReuseQueue1[sSampleDmaReuseQueueTail1++];
+ dma = sSampleDmas + dmaIndex;
+ hasDma = TRUE;
+ }
+
+ transfer = dma->bufSize;
+ dmaDevAddr = devAddr & ~0xF;
+ dma->ttl = 2;
+ dma->source = dmaDevAddr;
+ dma->sizeUnused = transfer;
+ osPiStartDma(&gCurrAudioFrameDmaIoMesgBufs[gCurrAudioFrameDmaCount++], OS_MESG_PRI_NORMAL,
+ OS_READ, dmaDevAddr, dma->buffer, transfer, &gCurrAudioFrameDmaQueue);
+ *dmaIndexRef = dmaIndex;
+ return (devAddr - dmaDevAddr) + dma->buffer;
}
-#else
-GLOBAL_ASM("asm/non_matchings/audio/load/func_800BAC04.s")
-#endif
-#ifdef MIPS_TO_C
//generated by mips_to_c commit 3c3b0cede1a99430bfd3edf8d385802b94f91307
? osPiStartDma(void *, ?, ?, s32, s32, s32, ? *); // extern
-extern ? D_803B6008;
-extern ? D_803B6120;
-extern ? D_803B6758;
-extern u32 D_803B6E58;
-extern u32 D_803B6E5C;
-extern ? D_803B6E68;
-extern ? D_803B6F68;
-extern u8 D_803B7068;
-extern u8 D_803B7069;
-extern u8 D_803B706B;
-extern s32 D_803B70BC;
+extern ? gCurrAudioFrameDmaQueue;
+extern ? gCurrAudioFrameDmaIoMesgBufs;
+extern ? sSampleDmas;
+extern u32 gSampleDmaNumListItems;
+extern u32 sSampleDmaListSize1;
+extern ? sSampleDmaReuseQueue1;
+extern ? sSampleDmaReuseQueue2;
+extern u8 sSampleDmaReuseQueueTail1;
+extern u8 sSampleDmaReuseQueueTail2;
+extern u8 sSampleDmaReuseQueueHead2;
+extern s32 gCurrAudioFrameDmaCount;
s32 func_800BAD0C(s32 arg0, s32 arg1, s32 arg2, u8 *arg3) {
void *sp40;
@@ -178,25 +281,25 @@ s32 func_800BAD0C(s32 arg0, s32 arg1, s32 arg2, u8 *arg3) {
phi_t3 = 0;
phi_t3 = 0;
- if ((arg2 != 0) || (temp_a1 = D_803B6E5C, temp_v0 = *arg3, phi_v1 = 0, ((temp_v0 < temp_a1) == 0))) {
- temp_a1_2 = D_803B6E58;
- temp_v1_3 = D_803B6E5C;
+ if ((arg2 != 0) || (temp_a1 = sSampleDmaListSize1, temp_v0 = *arg3, phi_v1 = 0, ((temp_v0 < temp_a1) == 0))) {
+ temp_a1_2 = gSampleDmaNumListItems;
+ temp_v1_3 = sSampleDmaListSize1;
phi_v1_2 = temp_v1_3;
if (temp_v1_3 < temp_a1_2) {
- phi_a0 = (temp_v1_3 * 0x10) + &D_803B6758;
+ phi_a0 = (temp_v1_3 * 0x10) + &sSampleDmas;
loop_4:
temp_v0_4 = arg0 - phi_a0->unk4;
if ((temp_v0_4 >= 0) && ((phi_a0->unkA - arg1) >= temp_v0_4)) {
if (phi_a0->unkE == 0) {
- temp_a1_3 = D_803B7069;
- if (D_803B706B != temp_a1_3) {
+ temp_a1_3 = sSampleDmaReuseQueueTail2;
+ if (sSampleDmaReuseQueueHead2 != temp_a1_3) {
temp_a3 = phi_a0->unkD;
- temp_v0_5 = &D_803B6F68 + temp_a1_3;
+ temp_v0_5 = &sSampleDmaReuseQueue2 + temp_a1_3;
if (temp_a1_3 != temp_a3) {
- *(&D_803B6F68 + temp_a3) = *temp_v0_5;
- (&D_803B6758 + (*temp_v0_5 * 0x10))->unkD = phi_a0->unkD;
+ *(&sSampleDmaReuseQueue2 + temp_a3) = *temp_v0_5;
+ (&sSampleDmas + (*temp_v0_5 * 0x10))->unkD = phi_a0->unkD;
}
- D_803B7069 = temp_a1_3 + 1;
+ sSampleDmaReuseQueueTail2 = temp_a1_3 + 1;
}
}
phi_a0->unkE = 0x3C;
@@ -213,18 +316,18 @@ loop_4:
goto loop_4;
}
block_14:
- temp_a1_4 = D_803B7069;
+ temp_a1_4 = sSampleDmaReuseQueueTail2;
phi_t0_2 = sp40;
- if ((D_803B706B != temp_a1_4) && (arg2 != 0)) {
- temp_t2 = *(&D_803B6F68 + temp_a1_4);
- D_803B7069 = temp_a1_4 + 1;
+ if ((sSampleDmaReuseQueueHead2 != temp_a1_4) && (arg2 != 0)) {
+ temp_t2 = *(&sSampleDmaReuseQueue2 + temp_a1_4);
+ sSampleDmaReuseQueueTail2 = temp_a1_4 + 1;
sp30 = temp_t2;
phi_t3 = 1;
- phi_t0_2 = &D_803B6758 + (temp_t2 * 0x10);
+ phi_t0_2 = &sSampleDmas + (temp_t2 * 0x10);
}
goto block_27;
}
- temp_t0 = &D_803B6758 + (temp_v0 * 0x10);
+ temp_t0 = &sSampleDmas + (temp_v0 * 0x10);
phi_t0 = temp_t0;
phi_t0_2 = temp_t0;
if (temp_a1 != 0) {
@@ -234,19 +337,19 @@ loop_19:
phi_v1 = temp_v1;
if ((temp_v0_2 >= 0) && ((phi_t0->unkA - arg1) >= temp_v0_2)) {
if (phi_t0->unkE == 0) {
- temp_v1_2 = D_803B7068;
+ temp_v1_2 = sSampleDmaReuseQueueTail1;
temp_a0 = phi_t0->unkD;
- temp_v0_3 = &D_803B6E68 + temp_v1_2;
+ temp_v0_3 = &sSampleDmaReuseQueue1 + temp_v1_2;
if (temp_v1_2 != temp_a0) {
- *(&D_803B6E68 + temp_a0) = *temp_v0_3;
- (&D_803B6758 + (*temp_v0_3 * 0x10))->unkD = phi_t0->unkD;
+ *(&sSampleDmaReuseQueue1 + temp_a0) = *temp_v0_3;
+ (&sSampleDmas + (*temp_v0_3 * 0x10))->unkD = phi_t0->unkD;
}
- D_803B7068 = temp_v1_2 + 1;
+ sSampleDmaReuseQueueTail1 = temp_v1_2 + 1;
}
phi_t0->unkE = 2;
return (phi_t0->unk0 + arg0) - phi_t0->unk4;
}
- temp_t0_2 = &D_803B6758 + (phi_v1 * 0x10);
+ temp_t0_2 = &sSampleDmas + (phi_v1 * 0x10);
phi_t0 = temp_t0_2;
phi_t0_2 = temp_t0_2;
if (temp_v1 >= temp_a1) {
@@ -257,10 +360,10 @@ loop_19:
block_27:
phi_t2 = sp30;
if (phi_t3 == 0) {
- temp_v1_5 = D_803B7068;
- temp_t2_2 = *(&D_803B6E68 + temp_v1_5);
- D_803B7068 = temp_v1_5 + 1;
- phi_t0_2 = &D_803B6758 + (temp_t2_2 * 0x10);
+ temp_v1_5 = sSampleDmaReuseQueueTail1;
+ temp_t2_2 = *(&sSampleDmaReuseQueue1 + temp_v1_5);
+ sSampleDmaReuseQueueTail1 = temp_v1_5 + 1;
+ phi_t0_2 = &sSampleDmas + (temp_t2_2 * 0x10);
phi_t2 = temp_t2_2;
}
temp_v0_6 = phi_t0_2->unkA;
@@ -268,12 +371,12 @@ block_27:
phi_t0_2->unkE = 2;
phi_t0_2->unk4 = temp_s0;
phi_t0_2->unk8 = temp_v0_6;
- temp_v1_6 = D_803B70BC;
+ temp_v1_6 = gCurrAudioFrameDmaCount;
temp_t9 = temp_v1_6 * 0x18;
- D_803B70BC = temp_v1_6 + 1;
+ gCurrAudioFrameDmaCount = temp_v1_6 + 1;
sp30 = phi_t2;
- sp40 = phi_t0_2;
- osPiStartDma(temp_t9 + &D_803B6120, 0, 0, temp_s0, phi_t0_2->unk0, temp_v0_6, &D_803B6008);
+ sp40 = phi_t0_2;./
+ osPiStartDma(temp_t9 + &gCurrAudioFrameDmaIoMesgBufs, 0, 0, temp_s0, phi_t0_2->unk0, temp_v0_6, &gCurrAudioFrameDmaQueue);
*arg3 = phi_t2;
return (arg0 - temp_s0) + phi_t0_2->unk0;
}
@@ -281,223 +384,95 @@ block_27:
GLOBAL_ASM("asm/non_matchings/audio/load/func_800BAD0C.s")
#endif
-#ifdef MIPS_TO_C
-//generated by mips_to_c commit 3c3b0cede1a99430bfd3edf8d385802b94f91307
-s32 func_800B8FFC(? *, s32, u32); // extern
-extern ? D_803BFBE8;
-extern ? D_803B6758;
-extern u32 D_803B6E58;
-extern u32 D_803B6E5C;
-extern s8 D_803B6E68;
-extern ? D_803B6F68;
-extern s8 D_803B7068;
-extern s8 D_803B7069;
-extern s8 D_803B706A;
-extern s8 D_803B706B;
-extern s16 D_803B7088;
-extern s32 D_803B70A8;
-extern s32 D_803B70B0;
-
-void func_800BB030(s32 arg0, u32 arg2) {
- s32 temp_a1;
- s32 temp_a1_2;
- s32 temp_s0;
- s32 temp_s0_3;
- s32 temp_v0;
- s32 temp_v0_3;
- s8 temp_v0_4;
- u32 temp_a1_3;
- u32 temp_a2;
- u32 temp_a2_2;
- u32 temp_a2_3;
- u32 temp_s0_2;
- u32 temp_s0_4;
- u32 temp_v0_2;
- u32 temp_v0_5;
- void *temp_v1;
- void *temp_v1_2;
- s32 phi_a1;
- u32 phi_a2;
- s32 phi_s0;
- s8 phi_s0_2;
- s8 *phi_v0;
- ? *phi_v1;
- void *phi_v0_2;
- s32 phi_a1_2;
- s32 phi_s0_3;
- u32 phi_a2_2;
- s8 phi_s0_4;
- s8 *phi_a0;
- s8 phi_v0_3;
- void *phi_v1_2;
- s32 phi_a3;
- void *phi_v0_4;
- u32 phi_a2_3;
+extern u32 D_803B70A8; // sDmaBufSize
+extern s32 gMaxSimultaneousNotes; // gMaxSimultaneousNotes
+extern struct AudioBufferParametersEU gAudioBufferParameters; // gAudioBufferParameters
+//extern struct SoundAllocPool gNotesAndBuffersPool; // remove when possible. This is in heap.h
+// init_sample_dma_buffers
+void func_800BB030(UNUSED s32 arg0) {
+ s32 i;
+#define j i
D_803B70A8 = 0x5A0;
- phi_a1 = 0x5A0;
- phi_a2 = arg2;
- phi_s0 = 0;
- phi_s0_3 = 0;
- if ((D_803B70B0 * 3 * D_803B7088) > 0) {
-loop_1:
- temp_v0 = func_800B8FFC(&D_803BFBE8, phi_a1, phi_a2);
- temp_a2 = D_803B6E58;
- temp_v1 = &D_803B6758 + (temp_a2 * 0x10);
- temp_v1->unk0 = temp_v0;
- phi_a2 = temp_a2;
- if (temp_v0 == 0) {
- } else {
- temp_a1 = D_803B70A8;
- temp_s0 = phi_s0 + 1;
- temp_v1->unk4 = 0;
- temp_v1->unk8 = 0;
- temp_v1->unkC = 0;
- temp_v1->unkE = 0;
- D_803B6E58 = temp_a2 + 1;
- temp_v1->unkA = temp_a1;
- phi_a1 = temp_a1;
- phi_s0 = temp_s0;
- if (temp_s0 >= (D_803B70B0 * 3 * D_803B7088)) {
-
- } else {
- goto loop_1;
- }
+ for (i = 0; i < gMaxSimultaneousNotes * 3 * gAudioBufferParameters.presetUnk4; i++)
+ {
+ sSampleDmas[gSampleDmaNumListItems].buffer = soundAlloc(&gNotesAndBuffersPool, D_803B70A8);
+ if (sSampleDmas[gSampleDmaNumListItems].buffer == NULL) {
+ break;
}
+ sSampleDmas[gSampleDmaNumListItems].bufSize = D_803B70A8;
+ sSampleDmas[gSampleDmaNumListItems].source = 0;
+ sSampleDmas[gSampleDmaNumListItems].sizeUnused = 0;
+ sSampleDmas[gSampleDmaNumListItems].unused2 = 0;
+ sSampleDmas[gSampleDmaNumListItems].ttl = 0;
+ gSampleDmaNumListItems++;
}
- temp_a2_2 = D_803B6E58;
- phi_s0_2 = 0;
- phi_a2_2 = temp_a2_2;
- if (temp_a2_2 != 0) {
- phi_v0 = &D_803B6E68;
- phi_v1 = &D_803B6758;
- do {
- *phi_v0 = phi_s0_2;
- phi_v1->unkD = phi_s0_2;
- temp_s0_2 = phi_s0_2 + 1;
- phi_s0_2 = temp_s0_2;
- phi_v0 += 1;
- phi_v1 += 0x10;
- } while (temp_s0_2 < temp_a2_2);
+
+ for (i = 0; (u32) i < gSampleDmaNumListItems; i++) {
+ sSampleDmaReuseQueue1[i] = (u8) i;
+ sSampleDmas[i].reuseIndex = (u8) i;
}
- phi_a3 = temp_a2_2;
- if (temp_a2_2 < 0x100) {
- phi_v0_2 = temp_a2_2 + &D_803B6E68;
- do {
- temp_v0_2 = phi_v0_2 + 1;
- temp_v0_2->unk-1 = 0;
- phi_v0_2 = temp_v0_2;
- } while (temp_v0_2 < &D_803B6F68);
+
+ for (j = gSampleDmaNumListItems; j < 0x100; j++) {
+ sSampleDmaReuseQueue1[j] = 0;
}
- D_803B7068 = 0;
- D_803B706A = temp_a2_2;
- D_803B6E5C = temp_a2_2;
+
+ sSampleDmaReuseQueueTail1 = 0;
+ sSampleDmaReuseQueueHead1 = (u8) gSampleDmaNumListItems;
+ sSampleDmaListSize1 = gSampleDmaNumListItems;
+
D_803B70A8 = 0x180;
- if (D_803B70B0 > 0) {
- phi_a1_2 = 0x180;
-loop_13:
- temp_v0_3 = func_800B8FFC(&D_803BFBE8, phi_a1_2, D_803B6E58);
- temp_a2_3 = D_803B6E58;
- temp_s0_3 = phi_s0_3 + 1;
- temp_v1_2 = &D_803B6758 + (temp_a2_3 * 0x10);
- temp_v1_2->unk0 = temp_v0_3;
- phi_s0_3 = temp_s0_3;
- phi_a2_3 = temp_a2_3;
- if (temp_v0_3 == 0) {
-
- } else {
- temp_a1_2 = D_803B70A8;
- temp_v1_2->unk4 = 0;
- temp_v1_2->unk8 = 0;
- temp_v1_2->unkC = 0;
- temp_v1_2->unkE = 0;
- D_803B6E58 = temp_a2_3 + 1;
- temp_v1_2->unkA = temp_a1_2;
- phi_a1_2 = temp_a1_2;
- if (temp_s0_3 >= D_803B70B0) {
- phi_a2_3 = D_803B6E58;
- } else {
- goto loop_13;
- }
+ for (i = 0; i < gMaxSimultaneousNotes; i++) {
+ sSampleDmas[gSampleDmaNumListItems].buffer = soundAlloc(&gNotesAndBuffersPool, D_803B70A8);
+ if (sSampleDmas[gSampleDmaNumListItems].buffer == NULL) {
+ break;
}
- phi_a2_2 = phi_a2_3;
- phi_a3 = phi_a2_3;
+ sSampleDmas[gSampleDmaNumListItems].bufSize = D_803B70A8;
+ sSampleDmas[gSampleDmaNumListItems].source = 0;
+ sSampleDmas[gSampleDmaNumListItems].sizeUnused = 0;
+ sSampleDmas[gSampleDmaNumListItems].unused2 = 0;
+ sSampleDmas[gSampleDmaNumListItems].ttl = 0;
+ gSampleDmaNumListItems++;
}
- temp_a1_3 = D_803B6E5C;
- phi_s0_4 = temp_a1_3;
- if (temp_a1_3 < phi_a2_2) {
- temp_v0_4 = temp_a1_3 * 0;
- phi_a0 = temp_v0_4 + &D_803B6F68;
- phi_v0_3 = temp_v0_4;
- phi_v1_2 = (temp_a1_3 * 0x10) + &D_803B6758;
- do {
- *phi_a0 = phi_s0_4;
- temp_s0_4 = phi_s0_4 + 1;
- phi_v1_2->unkD = phi_v0_3;
- phi_s0_4 = temp_s0_4;
- phi_a0 += 1;
- phi_v0_3 += 1;
- phi_v1_2 += 0x10;
- } while (temp_s0_4 < phi_a2_2);
+
+ for (i = sSampleDmaListSize1; (u32) i < gSampleDmaNumListItems; i++) {
+ sSampleDmaReuseQueue2[i - sSampleDmaListSize1] = (u8) i;
+ sSampleDmas[i].reuseIndex = (u8)(i - sSampleDmaListSize1);
}
- if (phi_a3 < 0x100) {
- phi_v0_4 = phi_a3 + &D_803B6F68;
- do {
- temp_v0_5 = phi_v0_4 + 1;
- temp_v0_5->unk-1 = temp_a1_3;
- phi_v0_4 = temp_v0_5;
- } while (temp_v0_5 < &D_803B7068);
+
+ // This probably meant to touch the range size1..size2 as well... but it
+ // doesn't matter, since these values are never read anyway.
+ for (j = gSampleDmaNumListItems; j < 0x100; j++) {
+ sSampleDmaReuseQueue2[j] = sSampleDmaListSize1;
}
- D_803B7069 = 0;
- D_803B706B = phi_a2_2 - temp_a1_3;
-}
-#else
-GLOBAL_ASM("asm/non_matchings/audio/load/func_800BB030.s")
-#endif
-#ifdef MIPS_TO_C
-//generated by mips_to_c commit 3c3b0cede1a99430bfd3edf8d385802b94f91307
-s32 func_800B8FFC(? *, s32, void *); // extern
-? func_800BAA80(s32, s32, s32, void *); // extern
-extern ? D_803BFBE8;
+ sSampleDmaReuseQueueTail2 = 0;
+ sSampleDmaReuseQueueHead2 = gSampleDmaNumListItems - sSampleDmaListSize1;
+#undef j
+}
-void func_800BB304(void *arg0) {
- s32 sp1C;
- s32 temp_a0;
- s32 temp_a1;
- s32 temp_a1_2;
- s32 temp_a2;
- s32 temp_v0;
- void *temp_a3;
- void *temp_a3_2;
+// Similar to patch_sound, but not really
+s32 func_800BB304(struct AudioBankSample *sample) {
+ //struct AudioBankSample *sample = sound->sample;
+ UNUSED u8 *mem;
- temp_a3 = arg0;
- if (arg0 == 0) {
- return;
+ if (sample == (void *)NULL) {
+ return -1;
}
- if (temp_a3->unk1 == 1) {
- temp_a1 = temp_a3->unk10;
- arg0 = temp_a3;
- temp_v0 = func_800B8FFC(&D_803BFBE8, temp_a1, temp_a3);
- temp_a3_2 = arg0;
- temp_a1_2 = temp_v0;
- if (temp_v0 == 0) {
- return;
+
+ if (sample->loaded == 1) {
+ //temp_a1 = sound->sampleAddr // unk10;
+ mem = soundAlloc(&gNotesAndBuffersPool, sample->sampleSize);
+ //temp_a1_2 = temp_v0;
+ if (mem == (void *)NULL) {
+ return -1;
}
- temp_a0 = temp_a3_2->unk4;
- temp_a2 = temp_a3_2->unk10;
- arg0 = temp_a3_2;
- sp1C = temp_a1_2;
- func_800BAA80(temp_a0, temp_a1_2, temp_a2, temp_a3_2);
- arg0->unk1 = 0x81;
- arg0->unk4 = temp_a1_2;
- // Duplicate return node #6. Try simplifying control flow for better match
+ audio_dma_copy_immediate((uintptr_t)sample->sampleAddr, mem, sample->sampleSize);
+ sample->loaded = 0x81;
+ sample->sampleAddr = mem; // sound->unk4
}
}
-#else
-GLOBAL_ASM("asm/non_matchings/audio/load/func_800BB304.s")
-#endif
#ifdef MIPS_TO_C
//generated by mips_to_c commit 3c3b0cede1a99430bfd3edf8d385802b94f91307
@@ -574,9 +549,9 @@ GLOBAL_ASM("asm/non_matchings/audio/load/func_800BB43C.s")
#ifdef MIPS_TO_C
//generated by mips_to_c commit 3c3b0cede1a99430bfd3edf8d385802b94f91307
-s32 func_800B8FFC(? *, s32, s32); // extern
-? func_800BAA80(s32, s32, s32, s32); // extern
-extern ? D_803BFBE8;
+s32 soundAlloc(? *, s32, s32); // extern
+? audio_dma_copy_immediate(s32, s32, s32, s32); // extern
+extern ? gNotesAndBuffersPool;
void func_800BB484(void **arg0, s32 arg1, s32 arg2) {
void *sp2C;
@@ -604,14 +579,14 @@ void func_800BB484(void **arg0, s32 arg1, s32 arg2) {
temp_a3_2 = temp_a3->unk4 + arg2;
sp28 = temp_a3_2;
sp2C = temp_a3;
- temp_v0_2 = func_800B8FFC(&D_803BFBE8, temp_a3->unk10, temp_a3_2);
+ temp_v0_2 = soundAlloc(&gNotesAndBuffersPool, temp_a3->unk10, temp_a3_2);
if (temp_v0_2 == 0) {
temp_a3->unk4 = temp_a3_2;
temp_a3->unk1 = 1;
} else {
sp24 = temp_v0_2;
sp2C = temp_a3;
- func_800BAA80(temp_a3_2, temp_v0_2, temp_a3->unk10, temp_a3_2);
+ audio_dma_copy_immediate(temp_a3_2, temp_v0_2, temp_a3->unk10, temp_a3_2);
temp_a3->unk1 = 0x81;
temp_a3->unk4 = temp_v0_2;
}
@@ -723,10 +698,12 @@ void func_800BB624(void **arg0, ? arg1, s32 arg2, s32 arg3) {
GLOBAL_ASM("asm/non_matchings/audio/load/func_800BB624.s")
#endif
+
+
#ifdef MIPS_TO_C
//generated by mips_to_c commit 3c3b0cede1a99430bfd3edf8d385802b94f91307
s32 func_800B93BC(? *, ?, s32, ?, s32); // extern
-? func_800BAA80(s32, s32, s32); // extern
+? audio_dma_copy_immediate(s32, s32, s32); // extern
? func_800BB584(s32); // extern
extern ? D_803AFE18;
extern ? D_803B03C0;
@@ -751,7 +728,7 @@ s32 func_800BB780(s32 arg0, ? arg1) {
return 0;
}
sp2C = temp_v0_2;
- func_800BAA80(sp28 + 0x10, temp_v0_2, temp_a2);
+ audio_dma_copy_immediate(sp28 + 0x10, temp_v0_2, temp_a2);
(D_803B7080 + (arg0 * 0xC))->unk4 = sp2C + 4;
func_800BB584(arg0);
temp_v0_3 = arg0 + &D_803B03C0;
@@ -819,7 +796,7 @@ GLOBAL_ASM("asm/non_matchings/audio/load/func_800BB864.s")
#ifdef MIPS_TO_C
//generated by mips_to_c commit 3c3b0cede1a99430bfd3edf8d385802b94f91307
s32 func_800B93BC(? *, ?, s32, ?, s32); // extern
-? func_800BAA80(s32, s32, s32); // extern
+? audio_dma_copy_immediate(s32, s32, s32); // extern
extern ? D_803AFC48;
extern ? D_803B0400;
extern s32 D_803B706C;
@@ -842,7 +819,7 @@ s32 func_800BB99C(s32 arg0, ? arg1) {
return 0;
}
sp28 = temp_v0;
- func_800BAA80(sp24, temp_v0, sp2C);
+ audio_dma_copy_immediate(sp24, temp_v0, sp2C);
temp_v0_3 = arg0 + &D_803B0400;
if (*temp_v0_3 != 5) {
*temp_v0_3 = 2;
@@ -856,7 +833,7 @@ GLOBAL_ASM("asm/non_matchings/audio/load/func_800BB99C.s")
#ifdef MIPS_TO_C
//generated by mips_to_c commit 3c3b0cede1a99430bfd3edf8d385802b94f91307
s32 func_800B93BC(? *, ?, s32, ?, s32); // extern
-? func_800BAA80(s32, s32, s32); // extern
+? audio_dma_copy_immediate(s32, s32, s32); // extern
? func_800BAAF8(s32, s32, s32, OSMesgQueue *, void *); // extern
extern ? D_803AFC48;
extern ? D_803B0400;
@@ -882,13 +859,13 @@ s32 func_800BBA50(s32 arg0, ? arg1, u8 *arg2) {
return 0;
}
if (temp_s0 < 0x41) {
- func_800BAA80(sp3C, temp_v0, temp_s0);
+ audio_dma_copy_immediate(sp3C, temp_v0, temp_s0);
temp_v0_3 = arg0 + &D_803B0400;
if (*temp_v0_3 != 5) {
*temp_v0_3 = 2;
}
} else {
- func_800BAA80(sp3C, temp_v0, 0x40);
+ audio_dma_copy_immediate(sp3C, temp_v0, 0x40);
temp_a3 = arg2 + 0xD4;
sp34 = temp_a3;
osCreateMesgQueue(temp_a3, arg2 + 0xEC, 1);
@@ -1064,24 +1041,20 @@ block_11:
#else
GLOBAL_ASM("asm/non_matchings/audio/load/func_800BBDDC.s")
#endif
-
-#ifdef MIPS_TO_C
-//generated by mips_to_c commit 3c3b0cede1a99430bfd3edf8d385802b94f91307
-? func_800BBF44(); // extern
-extern s32 D_800EA5DC;
-
-void func_800BBEF0(s32 arg2) {
- if (arg2 == 0) {
- D_800EA5DC = 0x19710515;
+extern volatile s32 D_800EA5DC;
+//load_sequence_internal
+void func_800BBF44(u32 player, u32 seqId, s32 loadAsync);
+//load_sequence
+void func_800BBEF0(u32 player, u32 seqId, s32 loadAsync) {
+ if (!loadAsync) {
+ D_800EA5DC = AUDIO_LOCK_LOADING; // gAudioLoadLock
}
- func_800BBF44();
- if (arg2 == 0) {
- D_800EA5DC = 0x76557364;
+ func_800BBF44(player, seqId, loadAsync);
+ if (!loadAsync) {
+ D_800EA5DC = AUDIO_LOCK_NOT_LOADING;
}
}
-#else
-GLOBAL_ASM("asm/non_matchings/audio/load/func_800BBEF0.s")
-#endif
+//GLOBAL_ASM("asm/non_matchings/audio/load/func_800BBEF0.s")
#ifdef MIPS_TO_C
//generated by mips_to_c commit 3c3b0cede1a99430bfd3edf8d385802b94f91307
diff --git a/src/audio/load.h b/src/audio/load.h
new file mode 100644
index 000000000..0ef0bea99
--- /dev/null
+++ b/src/audio/load.h
@@ -0,0 +1,12 @@
+#ifndef AUDIO_LOAD_H
+#define AUDIO_LOAD_H
+
+#include <PR/ultratypes.h>
+#include "internal.h"
+
+#define AUDIO_FRAME_DMA_QUEUE_SIZE 0x40
+
+#define PRELOAD_BANKS 2
+#define PRELOAD_SEQUENCE 1
+
+#endif // AUDIO_LOAD_H
diff --git a/src/audio/playback.c b/src/audio/playback.c
index d33b31e7b..b3c127225 100644
--- a/src/audio/playback.c
+++ b/src/audio/playback.c
@@ -292,7 +292,7 @@ f32 func_800BE5E0(void *); // extern
? func_800BEBA4(void *, u32); // extern
? func_800BF004(s32, void *); // extern
extern s32 D_803B1508;
-extern s32 D_803B70B0;
+extern s32 gMaxSimultaneousNotes;
void func_800BCBC4(void) {
u8 sp4B;
@@ -327,7 +327,7 @@ void func_800BCBC4(void) {
s32 phi_v0_2;
s32 phi_v1;
- temp_v1 = D_803B70B0;
+ temp_v1 = gMaxSimultaneousNotes;
phi_v1 = temp_v1;
if (temp_v1 > 0) {
phi_s5 = 0;
@@ -347,7 +347,7 @@ void func_800BCBC4(void) {
if (temp_v0 == 0) {
func_800BEBA4(temp_a0, temp_a1);
temp_s1_2->unk0 = 1;
- temp_v1_2 = D_803B70B0;
+ temp_v1_2 = gMaxSimultaneousNotes;
phi_v0_2 = temp_v1_2 * 3;
phi_v1 = temp_v1_2;
} else {
@@ -436,7 +436,7 @@ block_27:
phi_s3->unk1 = ((phi_s2 * 4) & 0x1C) | (phi_s3->unk1 & 0xFFE3);
}
}
- temp_v1_3 = D_803B70B0;
+ temp_v1_3 = gMaxSimultaneousNotes;
phi_v0_2 = temp_v1_3 * 3;
phi_v1 = temp_v1_3;
}
@@ -670,7 +670,7 @@ GLOBAL_ASM("asm/non_matchings/audio/playback/func_800BD318.s")
? func_800BF004(? *, s32); // extern
extern s32 D_803B1508;
extern ? D_803B5FC8;
-extern s32 D_803B70B0;
+extern s32 gMaxSimultaneousNotes;
void func_800BD368(void) {
s32 temp_s1;
@@ -681,7 +681,7 @@ void func_800BD368(void) {
func_800BD318(&D_803B5FC8);
phi_s0 = 0;
phi_s1 = 0;
- if (D_803B70B0 > 0) {
+ if (gMaxSimultaneousNotes > 0) {
do {
temp_v0 = D_803B1508;
(temp_v0 + phi_s0)->unk8 = phi_s0 + temp_v0;
@@ -690,7 +690,7 @@ void func_800BD368(void) {
temp_s1 = phi_s1 + 1;
phi_s0 += 0xC0;
phi_s1 = temp_s1;
- } while (temp_s1 < D_803B70B0);
+ } while (temp_s1 < gMaxSimultaneousNotes);
}
}
#else
@@ -1186,10 +1186,10 @@ GLOBAL_ASM("asm/non_matchings/audio/playback/func_800BDA44.s")
#ifdef MIPS_TO_C
//generated by mips_to_c commit 3c3b0cede1a99430bfd3edf8d385802b94f91307
-s32 func_800B8FFC(? *, ?); // extern
-extern ? D_803AFBE8;
+s32 soundAlloc(? *, ?); // extern
+extern ? gNotesAndBuffersPool;
extern s32 D_803B1508;
-extern s32 D_803B70B0;
+extern s32 gMaxSimultaneousNotes;
extern ? gZeroNoteSub;
void func_800BDD34(void) {
@@ -1199,7 +1199,7 @@ void func_800BDD34(void) {
s32 phi_s1;
phi_s1 = 0;
- if (D_803B70B0 > 0) {
+ if (gMaxSimultaneousNotes > 0) {
phi_s2 = 0;
do {
temp_s0 = phi_s2 + D_803B1508;
@@ -1219,11 +1219,11 @@ void func_800BDD34(void) {
temp_s0->unk80 = 0.0f;
temp_s0->unk84 = 0.0f;
temp_s0->unkBC = gZeroNoteSub.unkC;
- temp_s0->unk1C = func_800B8FFC(&D_803AFBE8, 0xA0);
+ temp_s0->unk1C = soundAlloc(&gNotesAndBuffersPool, 0xA0);
temp_s1 = phi_s1 + 1;
phi_s2 += 0xC0;
phi_s1 = temp_s1;
- } while (temp_s1 < D_803B70B0);
+ } while (temp_s1 < gMaxSimultaneousNotes);
}
}
#else
diff --git a/src/audio/port_eu.c b/src/audio/port_eu.c
index d261572fb..a4990188d 100644
--- a/src/audio/port_eu.c
+++ b/src/audio/port_eu.c
@@ -14,10 +14,10 @@ extern OSMesgQueue *D_800EA3B4;
extern s32 D_800EA484;
extern u8 D_803B0500;
extern u8 D_803B0501;
-extern OSMesgQueue D_803B6008;
-extern ? D_803B7088;
+extern OSMesgQueue gCurrAudioFrameDmaQueue;
+extern ? gAudioBufferParameters;
extern s32 D_803B70B8;
-extern s32 D_803B70BC;
+extern s32 gCurrAudioFrameDmaCount;
extern s32 D_803B70C0;
extern s32 D_803B70C4;
extern ? D_803B70C8;
@@ -64,7 +64,7 @@ void *create_next_audio_frame_task(void) {
s32 phi_s1_3;
D_803B70B8 = D_803B70B8 + 1;
- if ((D_803B70B8 % D_803B7088.unk0) != 0) {
+ if ((D_803B70B8 % gAudioBufferParameters.unk0) != 0) {
return NULL;
}
osSendMesg(D_800EA3A8, D_803B70B8, 0);
@@ -79,7 +79,7 @@ void *create_next_audio_frame_task(void) {
if (temp_v1 != 0) {
osAiSetNextBuffer(*(&D_803B7180 + (temp_hi * 4)), temp_v1 * 4);
}
- temp_s1 = D_803B70BC;
+ temp_s1 = gCurrAudioFrameDmaCount;
phi_s0 = 0;
phi_s1 = temp_s1;
phi_s0_2 = 0;
@@ -88,31 +88,31 @@ void *create_next_audio_frame_task(void) {
if (temp_s1 > 0) {
do {
phi_s1_2 = phi_s1_3;
- if (osRecvMesg(&D_803B6008, NULL, 0) == 0) {
+ if (osRecvMesg(&gCurrAudioFrameDmaQueue, NULL, 0) == 0) {
phi_s1_2 = phi_s1_3 - 1;
}
temp_s0 = phi_s0 + 1;
phi_s0 = temp_s0;
phi_s1 = phi_s1_2;
phi_s1_3 = phi_s1_2;
- } while (temp_s0 < D_803B70BC);
+ } while (temp_s0 < gCurrAudioFrameDmaCount);
}
if ((phi_s1 != 0) && (phi_s1 > 0)) {
do {
- osRecvMesg(&D_803B6008, NULL, 1);
+ osRecvMesg(&gCurrAudioFrameDmaQueue, NULL, 1);
temp_s0_2 = phi_s0_2 + 1;
phi_s0_2 = temp_s0_2;
} while (temp_s0_2 != phi_s1);
}
- temp_s1_2 = D_803B6008.validCount;
+ temp_s1_2 = gCurrAudioFrameDmaQueue.validCount;
if ((temp_s1_2 != 0) && (temp_s1_2 > 0)) {
do {
- osRecvMesg(&D_803B6008, NULL, 0);
+ osRecvMesg(&gCurrAudioFrameDmaQueue, NULL, 0);
temp_s0_3 = phi_s0_3 + 1;
phi_s0_3 = temp_s0_3;
} while (temp_s0_3 != temp_s1_2);
}
- D_803B70BC = 0;
+ gCurrAudioFrameDmaCount = 0;
func_800BAC04();
if (osRecvMesg(D_800EA3B0, &sp58, 0) != -1) {
D_803B0501 = sp58;
@@ -131,12 +131,12 @@ void *create_next_audio_frame_task(void) {
D_803B70D0 = *(&D_803B70C8 + (temp_v0 * 4));
sp60 = *temp_a3;
temp_s1_3 = (temp_s0_4 * 2) + &D_803B718C;
- *temp_s1_3 = (((D_803B7088.unk6 - sp74) + 0x40) & 0xFFF0) + 0x10;
- temp_a0 = D_803B7088.unkA;
+ *temp_s1_3 = (((gAudioBufferParameters.unk6 - sp74) + 0x40) & 0xFFF0) + 0x10;
+ temp_a0 = gAudioBufferParameters.unkA;
if (*temp_s1_3 < temp_a0) {
*temp_s1_3 = temp_a0;
}
- temp_v0_2 = D_803B7088.unk8;
+ temp_v0_2 = gAudioBufferParameters.unk8;
if (temp_v0_2 < *temp_s1_3) {
*temp_s1_3 = temp_v0_2;
}
diff --git a/src/audio/synthesis.c b/src/audio/synthesis.c
index 0cfca8028..11602ee5d 100644
--- a/src/audio/synthesis.c
+++ b/src/audio/synthesis.c
@@ -62,8 +62,8 @@ s8 gUseReverb;
s8 gNumSynthesisReverbs;
struct NoteSubEu *gNoteSubsEu;
-extern struct Note *D_803B7088;
-extern s32 D_803B70B0;
+extern struct Note *gAudioBufferParameters;
+extern s32 gMaxSimultaneousNotes;
f32 gLeftVolRampings;
//f32 gRightVolRampings[3][1024];
@@ -164,9 +164,9 @@ void synthesis_load_note_subs_eu(s32 updateIndex) {
struct NoteSubEu *dest;
s32 i;
- for (i = 0; i < D_803B70B0; i++) {
- src = &D_803B7088[i].noteSubEu;
- dest = &gNoteSubsEu[D_803B70B0 * updateIndex + i];
+ for (i = 0; i < gMaxSimultaneousNotes; i++) {
+ src = &gAudioBufferParameters[i].noteSubEu;
+ dest = &gNoteSubsEu[gMaxSimultaneousNotes * updateIndex + i];
if (src->enabled) {
*dest = *src;
src->needsInit = FALSE;
@@ -183,11 +183,11 @@ void func_800B6FB4(s32 arg0, s32 arg1) {
s32 phi_v0;
temp_v0 = arg0 + 1;
- if (i = 0; temp_v0 < (s32) D_803B7088.unkC; i++) {
+ if (i = 0; temp_v0 < (s32) gAudioBufferParameters.unkC; i++) {
phi_v0 = temp_v0;
- for(i = 0; temp_v0_2 < (s32) D_803B7088.unkC; i++) {
- dest = &gNoteSubsEu[D_803B70B0 * phi_v0 + (arg1 * 0x10)];
+ 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);
@@ -205,8 +205,8 @@ GLOBAL_ASM("asm/non_matchings/audio/synthesis/func_800B6F1C.s")
#ifdef MIPS_TO_C
//generated by mips_to_c commit 3c3b0cede1a99430bfd3edf8d385802b94f91307
Tried to use struct NoteSubEu before it is defined.
-extern ? D_803B7088;
-extern s32 D_803B70B0;
+extern ? gAudioBufferParameters;
+extern s32 gMaxSimultaneousNotes;
extern ? gNoteSubsEu;
void synthesis_load_note_subs_eu(s32 arg0, s32 arg1) {
@@ -217,16 +217,16 @@ void synthesis_load_note_subs_eu(s32 arg0, s32 arg1) {
temp_v0 = arg0 + 1;
phi_v0 = temp_v0;
- if (temp_v0 < D_803B7088.unkC) {
+ if (temp_v0 < gAudioBufferParameters.unkC) {
// Error: Tried to use struct NoteSubEu before it is defined.
// At instruction: lui $a1, %hi(gNoteSubsEu)
loop_2:
- temp_a0 = *arg1 + (D_803B70B0 * phi_v0 * 0x10) + (arg1 * 0x10);
+ temp_a0 = *arg1 + (gMaxSimultaneousNotes * phi_v0 * 0x10) + (arg1 * 0x10);
if ((*temp_a0 * 2) >= 0) {
temp_v0_2 = phi_v0 + 1;
*temp_a0 = *temp_a0 & 0xFF7F;
phi_v0 = temp_v0_2;
- if (temp_v0_2 < D_803B7088.unkC) {
+ if (temp_v0_2 < gAudioBufferParameters.unkC) {
goto loop_2;
}
}
@@ -239,7 +239,7 @@ GLOBAL_ASM("asm/non_matchings/audio/synthesis/synthesis_load_note_subs_eu.s")
#ifdef MIPS_TO_C
//generated by mips_to_c commit 3c3b0cede1a99430bfd3edf8d385802b94f91307
Tried to use struct NoteSubEu before it is defined.
-extern s32 D_803B70B0;
+extern s32 gMaxSimultaneousNotes;
extern ? gNoteSubsEu;
void func_800B7034(s32 arg0) {
@@ -252,13 +252,13 @@ void func_800B7034(s32 arg0) {
phi_a1 = 0;
phi_v0 = 0;
- if (D_803B70B0 > 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_2 = temp_a0 + 0xB0;
- temp_a2 = (((D_803B70B0 * arg0) + phi_v0) * 0x10) + *MIPS2C_ERROR(Read from unset register $t2);
+ 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;
@@ -271,7 +271,7 @@ void func_800B7034(s32 arg0) {
temp_v0 = phi_v0 + 1;
phi_a1 += 0xC0;
phi_v0 = temp_v0;
- } while (temp_v0 < D_803B70B0);
+ } while (temp_v0 < gMaxSimultaneousNotes);
}
}
#else
@@ -284,7 +284,7 @@ GLOBAL_ASM("asm/non_matchings/audio/synthesis/func_800B7034.s")
void *func_800B775C(s32, s32, void *, s32); // extern
? func_800C1138(s32); // extern
? prepare_reverb_ring_buffer(s32, s32, s32); // extern
-extern ? D_803B7088;
+extern ? gAudioBufferParameters;
void *func_800B70EC(void *arg0, s32 *arg1, s32 arg2, s32 arg3) {
s16 temp_s2;
@@ -317,20 +317,20 @@ void *func_800B70EC(void *arg0, s32 *arg1, s32 arg2, s32 arg3) {
void *phi_fp_2;
s16 phi_s2_3;
- temp_s4 = D_803B7088.unkC;
+ temp_s4 = gAudioBufferParameters.unkC;
phi_s4 = temp_s4;
phi_s6 = arg3;
if (temp_s4 > 0) {
do {
temp_s0 = phi_s4 - 1;
func_800C1138(temp_s0);
- func_800B7034(D_803B7088.unkC - phi_s4);
+ func_800B7034(gAudioBufferParameters.unkC - phi_s4);
phi_s4 = temp_s0;
} while (temp_s0 > 0);
}
arg0->unk0 = 0x7000000;
arg0->unk4 = 0;
- temp_s4_2 = D_803B7088.unkC;
+ temp_s4_2 = gAudioBufferParameters.unkC;
temp_fp = arg0 + 8;
phi_s4_2 = temp_s4_2;
phi_s7 = arg2;
@@ -338,7 +338,7 @@ void *func_800B70EC(void *arg0, s32 *arg1, s32 arg2, s32 arg3) {
phi_fp_2 = temp_fp;
if (temp_s4_2 > 0) {
do {
- temp_s2 = D_803B7088.unkC;
+ temp_s2 = gAudioBufferParameters.unkC;
phi_s2 = temp_s2;
phi_s1 = 0;
phi_s2_2 = temp_s2;
@@ -346,15 +346,15 @@ void *func_800B70EC(void *arg0, s32 *arg1, s32 arg2, s32 arg3) {
phi_s3 = phi_s6;
} else {
temp_lo = phi_s6 / phi_s4_2;
- temp_v1 = D_803B7088.unk10;
+ temp_v1 = gAudioBufferParameters.unk10;
if (temp_lo >= temp_v1) {
phi_s3 = temp_v1;
} else {
- temp_v1_2 = D_803B7088.unk12;
+ temp_v1_2 = gAudioBufferParameters.unk12;
if (temp_v1_2 >= temp_lo) {
phi_s3 = temp_v1_2;
} else {
- phi_s3 = D_803B7088.unkE;
+ phi_s3 = gAudioBufferParameters.unkE;
}
}
}
@@ -367,7 +367,7 @@ void *func_800B70EC(void *arg0, s32 *arg1, s32 arg2, s32 arg3) {
if (phi_s0->useReverb != 0) {
prepare_reverb_ring_buffer(phi_s3, phi_s2 - phi_s4_2, phi_s1);
phi_v0 = gNumSynthesisReverbs;
- phi_s2_3 = D_803B7088.unkC;
+ phi_s2_3 = gAudioBufferParameters.unkC;
}
temp_s1 = phi_s1 + 1;
phi_s0 += 0x108;
@@ -553,7 +553,7 @@ void *func_800B7630(void *, s16, s16); // extern
void *func_800B7C30(u8, s32, s32, s32, s32, void *, s32); // extern
extern ? D_803B03C0;
extern s32 D_803B1508;
-extern s32 D_803B70B0;
+extern s32 gMaxSimultaneousNotes;
extern s32 D_803B7198;
extern ? gNoteSubsEu;
extern u8 gUseReverb;
@@ -627,7 +627,7 @@ void *func_800B775C(s32 arg0, s32 arg1, void *arg2, s16 arg3) {
phi_s2_8 = 0;
phi_s2_4 = 0;
if (temp_t1 == 0) {
- temp_a0 = D_803B70B0;
+ temp_a0 = gMaxSimultaneousNotes;
phi_s1 = 0;
if (temp_a0 > 0) {
// Error: Tried to use struct NoteSubEu before it is defined.
@@ -649,7 +649,7 @@ void *func_800B775C(s32 arg0, s32 arg1, void *arg2, s16 arg3) {
} else {
phi_s3 = 0;
if (temp_t1 > 0) {
- temp_a0_2 = D_803B70B0;
+ temp_a0_2 = gMaxSimultaneousNotes;
do {
phi_s1_2 = 0;
phi_s2_2 = phi_s2_6;
@@ -676,7 +676,7 @@ void *func_800B775C(s32 arg0, s32 arg1, void *arg2, s16 arg3) {
phi_s2_8 = phi_s2_10;
} while (temp_s3 < temp_t1);
}
- temp_a0_3 = D_803B70B0;
+ temp_a0_3 = gMaxSimultaneousNotes;
phi_s1_3 = 0;
phi_s2_3 = phi_s2_8;
phi_s2_4 = phi_s2_8;
@@ -727,7 +727,7 @@ void *func_800B775C(s32 arg0, s32 arg1, void *arg2, s16 arg3) {
loop_31:
temp_v1 = *phi_s0;
temp_t0 = *saved_reg_s6;
- temp_lo = arg3 * D_803B70B0;
+ temp_lo = arg3 * gMaxSimultaneousNotes;
phi_s4_3 = phi_s4_2;
phi_s1_8 = phi_s1_5;
if (phi_s3_2 == ((temp_t0 + (temp_v1 * 0x10) + (temp_lo * 0x10))->unk1 >> 5)) {
@@ -765,7 +765,7 @@ loop_31:
do {
temp_v1_2 = *phi_s0_2;
temp_t0_2 = *saved_reg_s6;
- temp_lo_2 = arg3 * D_803B70B0;
+ temp_lo_2 = arg3 * gMaxSimultaneousNotes;
temp_a1 = (temp_t0_2 + (temp_v1_2 * 0x10) + (temp_lo_2 * 0x10))->unk2;
phi_s4_9 = phi_s4_4;
if (((*(&D_803B03C0 + temp_a1) < 2) ^ 1) == 1) {