documented most audio stuff

This commit is contained in:
Henny022p
2021-03-24 01:58:52 +01:00
parent 58b4df70b5
commit 5af4805e59
45 changed files with 223 additions and 507 deletions
+106 -111
View File
@@ -3,88 +3,86 @@
#include "gba/m4a.h"
#include "audio.h"
#include "utils.h"
#include "structures.h"
s32 sub_080A3518(s32, s32);
void sub_080A353C(u32);
void sub_080A35A0(u32);
void sub_080A35B4(u32);
void sub_080A35C8(void);
#define IS_BGM(song) (song) - 1 <= NUM_BGM - 1
#define IS_SFX(song) (song) - 1 > NUM_BGM - 1
void sub_080A3210(void);
void InitSoundPlayingInfo(void);
s32 fade(s32 target, s32 current);
void doPlaySound(u32 sound);
void PlayFadeIn(u32 sound);
void PlayFadeOut(u32 sound);
void InitVolume(void);
void InitSound(void){
sub_080A3210();
void InitSound(void) {
InitSoundPlayingInfo();
m4aSoundInit();
}
void sub_080A3210(void){
MemClear(&gUnk_02021EE0, 0x18);
sub_080A35C8();
gUnk_02021EE0.unk_12 = 0x100;
gUnk_02021EE0.unk_04 = 0x100;
void InitSoundPlayingInfo(void) {
MemClear(&gSoundPlayingInfo, sizeof(gSoundPlayingInfo));
InitVolume();
gSoundPlayingInfo.volumeSfx = 0x100;
gSoundPlayingInfo.unk_04 = 0x100;
m4aMPlayAllStop();
}
void sub_080A3234(u32 arg){
gUnk_02021EE0.unk_08 = arg;
gUnk_02021EE0.unk_0a = arg;
sub_080A353C(gUnk_02021EE0.currentBgm);
void SetMasterVolume(u32 volume) {
gSoundPlayingInfo.volumeMaster = volume;
gSoundPlayingInfo.volumeMasterTarget = volume;
doPlaySound(gSoundPlayingInfo.currentBgm);
}
void sub_080A3248(u32 arg){
gUnk_02021EE0.unk_10 = arg;
gUnk_02021EE0.unk_0e = arg;
sub_080A353C(gUnk_02021EE0.currentBgm);
void SetBgmVolume(u32 volume) {
gSoundPlayingInfo.volumeBgmTarget = volume;
gSoundPlayingInfo.volumeBgm = volume;
doPlaySound(gSoundPlayingInfo.currentBgm);
}
void sub_080A325C(u32 arg){
gUnk_02021EE0.unk_12 = arg;
void SetSfxVolume(u32 volume) {
gSoundPlayingInfo.volumeSfx = volume;
}
void SoundReq(Sound sound) {
u32 song;
struct_02021EE0* ptr;
SoundPlayingInfo* ptr;
if (gMain.field_0x7)
return;
ptr = &gUnk_02021EE0;
ptr = &gSoundPlayingInfo;
song = sound & 0xffff;
switch (sound & 0xffff0000) {
case SONG_STOP_ALL:
ptr->currentBgm = 0;
m4aMPlayAllStop();
return;
case SONG_VOL_ZERO:
sub_080A3234(0);
case SONG_MUTE:
SetMasterVolume(0);
return;
case SONG_VOL_RESET_ALL:
sub_080A35C8();
ptr->unk_12 = 0x100;
sub_080A353C(ptr->currentBgm);
case SONG_PLAY_VOL_RESET_ALL:
InitVolume();
ptr->volumeSfx = 0x100;
doPlaySound(ptr->currentBgm);
return;
case SONG_VOL_FADE_OUT:
sub_080A35B4(ptr->currentBgm);
PlayFadeOut(ptr->currentBgm);
return;
case SONG_UNK_9:
case SONG_FADE_IN:
if (song == 0)
song = ptr->currentBgm;
if (IS_SFX(song))
return;
ptr->currentBgm = song;
m4aSongNumStart(song);
sub_080A35A0(song);
PlayFadeIn(song);
return;
case SONG_UNK_A:
case SONG_FADE_IN_CONTINUE:
if (IS_SFX(song))
return;
ptr->currentBgm = song;
m4aSongNumStartOrContinue(song);
sub_080A35A0(song);
PlayFadeIn(song);
return;
case SONG_UNK_C:
case SONG_PLAY_TEMPO_CONTROL:
m4aMPlayTempoControl(gMPlayTable[gSongTable[ptr->currentBgm].ms].info, song);
return;
case SONG_VSYNC_OFF:
@@ -98,34 +96,34 @@ void SoundReq(Sound sound) {
return;
case SONG_VSYNC_ON:
m4aSoundVSyncOn();
case SONG_UNK_7:
case SONG_CONTINUE:
if (ptr->currentBgm == 0)
return;
m4aSongNumStartOrContinue(ptr->currentBgm);
sub_080A353C(ptr->currentBgm);
doPlaySound(ptr->currentBgm);
return;
case SONG_VOL_RESET:
case SONG_PLAY_VOL_RESET:
if (IS_SFX(song))
return;
ptr->currentBgm = song;
m4aSongNumStartOrContinue(song);
sub_080A35C8();
sub_080A353C(song);
InitVolume();
doPlaySound(song);
return;
case SONG_VOL_CHAN1_SILENT:
ptr->unk_10 = 0;
case SONG_FADE_OUT_BGM:
ptr->volumeBgmTarget = 0;
return;
case SONG_RESET_UNK:
ptr->unk_10 = 0;
ptr->unk_02 = 1;
case SONG_STOP_BGM:
ptr->volumeBgmTarget = 0;
ptr->stopBgm = TRUE;
return;
case SONG_VOL_CHAN1_RESET:
ptr->unk_10 = 0x100;
case SONG_FADE_IN_BGM:
ptr->volumeBgmTarget = 0x100;
return;
case SONG_UNK_F:
sub_080A35C8();
case SONG_INIT:
InitVolume();
return;
case SONG_UNK_11:
case SONG_BGM_0:
ptr->currentBgm = 0;
return;
default:
@@ -133,109 +131,106 @@ void SoundReq(Sound sound) {
if (IS_BGM(song)) {
ptr->currentBgm = song;
m4aSongNumStart(song);
sub_080A35C8();
InitVolume();
} else {
m4aSongNumStart(song);
}
sub_080A353C(song);
doPlaySound(song);
}
return;
}
}
void sub_080A3480(void) {
u32 iVar2;
struct_02021EE0* ptr = &gUnk_02021EE0;
void SoundLoop(void) {
s32 fadeValue;
SoundPlayingInfo* ptr = &gSoundPlayingInfo;
if (ptr->unk_0a != ptr->unk_08) {
iVar2 = sub_080A3518(ptr->unk_0a, ptr->unk_08);
if (iVar2 == 0) {
ptr->unk_08 = ptr->unk_0a;
if (ptr->volumeMasterTarget != ptr->volumeMaster) {
fadeValue = fade(ptr->volumeMasterTarget, ptr->volumeMaster);
if (fadeValue == 0) {
ptr->volumeMaster = ptr->volumeMasterTarget;
} else {
ptr->unk_08 = ptr->unk_08 + iVar2;
ptr->volumeMaster = ptr->volumeMaster + fadeValue;
}
if (ptr->unk_08 < 0) {
ptr->unk_0a = 0;
ptr->unk_08 = 0;
if (ptr->volumeMaster < 0) {
ptr->volumeMasterTarget = 0;
ptr->volumeMaster = 0;
}
sub_080A353C(ptr->currentBgm);
doPlaySound(ptr->currentBgm);
} else {
if (ptr->unk_10 != ptr->unk_0e) {
iVar2 = sub_080A3518(ptr->unk_10, ptr->unk_0e);
if (iVar2 == 0) {
if (ptr->unk_02 != 0 && ptr->unk_10 == 0) {
ptr->unk_02 = 0;
if (ptr->volumeBgmTarget != ptr->volumeBgm) {
fadeValue = fade(ptr->volumeBgmTarget, ptr->volumeBgm);
if (fadeValue == 0) {
if (ptr->stopBgm && ptr->volumeBgmTarget == 0) {
ptr->stopBgm = FALSE;
ptr->currentBgm = 0;
m4aSongNumStop(0);
} else {
ptr->unk_0e = ptr->unk_10;
ptr->volumeBgm = ptr->volumeBgmTarget;
}
} else {
ptr->unk_0e += iVar2;
ptr->volumeBgm += fadeValue;
}
if (ptr->unk_0e < 0) {
ptr->unk_10 = 0;
ptr->unk_0e = 0;
if (ptr->volumeBgm < 0) {
ptr->volumeBgmTarget = 0;
ptr->volumeBgm = 0;
}
sub_080A353C(ptr->currentBgm);
doPlaySound(ptr->currentBgm);
}
}
}
s32 sub_080A3518(s32 unk_1, s32 unk_2){
if (unk_1 - unk_2 >= 1) {
unk_2 += 4;
if (unk_1 > unk_2)
s32 fade(s32 target, s32 current) {
if (target - current >= 1) {
current += 4;
if (target > current)
return 4;
else
return 0;
return 0;
} else {
unk_2 -= 4;
if (unk_1 < unk_2)
current -= 4;
if (target < current)
return -4;
else
return 0;
return 0;
}
}
void sub_080A353C(u32 song){
void doPlaySound(u32 sound) {
u32 volume;
u32 iVar2;
MusicPlayerInfo* musicPlayerInfo;
if(song == 0)
if (sound == 0)
return;
if (IS_BGM(song)) {
volume = gUnk_02021EE0.unk_0e;
if (IS_BGM(sound)) {
volume = gSoundPlayingInfo.volumeBgm;
} else {
volume = gSoundPlayingInfo.volumeSfx;
}
else{
volume = gUnk_02021EE0.unk_12;
}
iVar2 = gUnk_02021EE0.unk_08;
iVar2 = gSoundPlayingInfo.volumeMaster;
volume = iVar2 * volume / 0x100;
musicPlayerInfo = gMPlayTable[gSongTable[song].ms].info;
musicPlayerInfo = gMPlayTable[gSongTable[sound].ms].info;
m4aMPlayImmInit(musicPlayerInfo);
m4aMPlayVolumeControl(musicPlayerInfo, 0xffff, volume);
}
void sub_080A35A0(u32 song){
gUnk_02021EE0.unk_0a = 0x100;
sub_080A353C(song);
void PlayFadeIn(u32 sound) {
gSoundPlayingInfo.volumeMasterTarget = 0x100;
doPlaySound(sound);
}
void sub_080A35B4(u32 song){
gUnk_02021EE0.unk_0a = 0;
sub_080A353C(song);
void PlayFadeOut(u32 sound) {
gSoundPlayingInfo.volumeMasterTarget = 0;
doPlaySound(sound);
}
void sub_080A35C8(){
gUnk_02021EE0.unk_06 = 0x100;
gUnk_02021EE0.unk_08 = 0x100;
gUnk_02021EE0.unk_0a = 0x100;
gUnk_02021EE0.unk_0c = 0x100;
gUnk_02021EE0.unk_0e = 0x100;
gUnk_02021EE0.unk_10 = 0x100;
void InitVolume() {
gSoundPlayingInfo.volumeMasterUnk = 0x100;
gSoundPlayingInfo.volumeMaster = 0x100;
gSoundPlayingInfo.volumeMasterTarget = 0x100;
gSoundPlayingInfo.volumeBgmUnk = 0x100;
gSoundPlayingInfo.volumeBgm = 0x100;
gSoundPlayingInfo.volumeBgmTarget = 0x100;
}
extern const SongHeader sfxNone;
+1 -1
View File
@@ -33,7 +33,7 @@ void sub_0805FA04(void) {
sub_08053320();
sub_0801D79C(0, 0x1144);
gMain.funcIndex = 1;
sub_080A3210();
InitSoundPlayingInfo();
sub_08050008();
}
+1 -1
View File
@@ -190,7 +190,7 @@ static void HandleFileScreenEnter(void) {
u32 i;
DispReset(1);
sub_080A3210();
InitSoundPlayingInfo();
MemClear((void*)VRAM, 0x80); // clear palettes
MessageInitialize();
EraseAllEntities();
+1 -1
View File
@@ -158,7 +158,7 @@ static void HandleTitlescreen(void) {
gIntroState.swordBgScaleRatio = 0x10;
UpdateSwordBgAffineData();
}
sub_080A3210();
InitSoundPlayingInfo();
SoundReq(BGM_TITLE_SCREEN);
DoFade(6, 8);
break;
+1 -1
View File
@@ -73,7 +73,7 @@ void AgbMain(void) {
sScreenHandlers[gMain.screen]();
MessageUpdate();
sub_08050154();
sub_080A3480();
SoundLoop();
break;
}
PrepNextFrame();
+1 -1
View File
@@ -81,7 +81,7 @@ void sub_0805A370(Manager15* this) {
if (this->manager.unk_0d) {
LoadRoomEntityList((EntityData*)&gUnk_080E4C08);
this->manager.action = 3;
SoundReq(SONG_RESET_UNK);
SoundReq(SONG_STOP_BGM);
}
}
+2 -2
View File
@@ -19,7 +19,7 @@
void (*const ManagerB_ActionFuncs[])(Manager*);
void sub_080585F0(Manager* this) {
// make a distincion if this is a controller (unk_0a = 0) or a helper (unk_0a = 1)
// make a distincion if this is a controller (volumeMasterTarget = 0) or a helper (volumeMasterTarget = 1)
ManagerB_ActionFuncs[this->unk_0a](this);
}
@@ -141,7 +141,7 @@ void ManagerBHelper_Monitor(ManagerBHelper* this, Entity* ent, u32 index) {
this->manager.unk_0e++;
}
// case unk_0a is 1: The manager is a helper
// case volumeMasterTarget is 1: The manager is a helper
void ManagerBHelper_Main(Manager* this) {
u8 i, anyRemaining;
+10 -10
View File
@@ -2241,7 +2241,7 @@ void sub_0804CD48(void) {
if (CheckGlobalFlag(LV1_CLEAR)) {
LoadRoomEntityList(&gUnk_080DF94C);
} else {
SoundReq(SONG_RESET_UNK);
SoundReq(SONG_STOP_BGM);
gArea.musicIndex = gArea.pMusicIndex;
}
}
@@ -2429,7 +2429,7 @@ void sub_0804CED8(void) {
sub_0807AABC(&gPlayerEntity);
LoadRoomEntityList(&gUnk_080E1814);
} else {
SoundReq(SONG_RESET_UNK);
SoundReq(SONG_STOP_BGM);
gArea.musicIndex = gArea.pMusicIndex;
}
}
@@ -2523,7 +2523,7 @@ void sub_0804CFB0(void) {
if (!CheckFlags(0x31)) {
if (gScreenTransition.field_0x38 == 0) {
SoundReq(SONG_RESET_UNK);
SoundReq(SONG_STOP_BGM);
} else {
if (gScreenTransition.field_0x39 == 0) {
SoundReq(SONG_STOP);
@@ -2761,7 +2761,7 @@ void sub_0804D140(void) {
if (CheckGlobalFlag(LV4_CLEAR)) {
LoadRoomEntityList(&gUnk_080E49F4);
} else {
SoundReq(SONG_RESET_UNK);
SoundReq(SONG_STOP_BGM);
gArea.musicIndex = gArea.pMusicIndex;
}
}
@@ -3090,7 +3090,7 @@ void sub_0804D384(void) {
sub_08078A90(3);
LoadRoomEntityList(&gUnk_080E72E4);
gArea.musicIndex = gArea.pMusicIndex;
SoundReq(SONG_RESET_UNK);
SoundReq(SONG_STOP_BGM);
}
}
}
@@ -3498,7 +3498,7 @@ u32 sub_0804D6C4() {
}
void sub_0804D6C8(void) {
SoundReq(SONG_RESET_UNK);
SoundReq(SONG_STOP_BGM);
gArea.musicIndex = gArea.pMusicIndex;
}
@@ -4506,7 +4506,7 @@ void sub_0804E3C4() {
index = 0xE;
}
sub_0804B3C4(&gUnk_080F0E1C[index]);
SoundReq(SONG_RESET_UNK);
SoundReq(SONG_STOP_BGM);
}
u32 sub_0804E45C() {
@@ -4714,7 +4714,7 @@ extern EntityData gUnk_080F2E2C;
void sub_0804E6E8(void) {
if (!CheckGlobalFlag(OUTDOOR)) {
gArea.musicIndex = gArea.pMusicIndex;
SoundReq(SONG_VOL_RESET | BGM_MINISH_CAP);
SoundReq(SONG_PLAY_VOL_RESET | BGM_MINISH_CAP);
}
if (!CheckGlobalFlag(START)) {
LoadRoomEntityList(&gUnk_080F2E2C);
@@ -4731,7 +4731,7 @@ extern EntityData gUnk_080F2EC4;
void sub_0804E72C(void) {
if (!CheckGlobalFlag(OUTDOOR)) {
gArea.musicIndex = gArea.pMusicIndex;
SoundReq(SONG_VOL_RESET | BGM_MINISH_CAP);
SoundReq(SONG_PLAY_VOL_RESET | BGM_MINISH_CAP);
}
if (!CheckGlobalFlag(START)) {
LoadRoomEntityList(&gUnk_080F2E94);
@@ -4783,7 +4783,7 @@ void sub_0804E7DC(void) {
}
if (!CheckGlobalFlag(OUTDOOR)) {
gArea.musicIndex = gArea.pMusicIndex;
SoundReq(SONG_VOL_RESET | BGM_MINISH_CAP);
SoundReq(SONG_PLAY_VOL_RESET | BGM_MINISH_CAP);
}
if ((gPlayerState.flags.all & 8) == 0) {
LoadRoomEntityList(&gUnk_080F31D8);
+6 -5
View File
@@ -1,5 +1,6 @@
#include "save.h"
#include "gba/eeprom.h"
#include "audio.h"
typedef struct SaveFileStatus {
u16 checksum1;
@@ -67,8 +68,8 @@ SaveResult HandleSave(u32 arg0) {
}
SaveResult HandleSaveInit(u32 arg0) {
gUnk_02021EE0.unk_0a -= 8;
if (gUnk_02021EE0.unk_08 <= 0) {
gSoundPlayingInfo.volumeMasterTarget -= 8;
if (gSoundPlayingInfo.volumeMaster <= 0) {
gMenu.field_0xa = 8;
gMenu.storyPanelIndex = SAVE_IN_PROGRESS;
}
@@ -105,9 +106,9 @@ SaveResult HandleSaveDone(u32 arg0) {
SaveResult result;
result = SAVE_BUSY;
gUnk_02021EE0.unk_0a += 8;
if (gUnk_02021EE0.unk_06 <= gUnk_02021EE0.unk_0a) {
gUnk_02021EE0.unk_0a = gUnk_02021EE0.unk_06;
gSoundPlayingInfo.volumeMasterTarget += 8;
if (gSoundPlayingInfo.volumeMasterUnk <= gSoundPlayingInfo.volumeMasterTarget) {
gSoundPlayingInfo.volumeMasterTarget = gSoundPlayingInfo.volumeMasterUnk;
sub_08050384();
gMenu.storyPanelIndex = SAVE_INIT;
if (gMenu.field_0xa == 1) {
+4 -4
View File
@@ -141,7 +141,7 @@ void ScriptCommand_DoPostScriptAction2(Entity* entity, ScriptExecutionContext* c
void ScriptCommand_PlaySound(Entity* entity, ScriptExecutionContext* context);
void ScriptCommand_PlayBgm(Entity* entity, ScriptExecutionContext* context);
void ScriptCommand_SoundReq(Entity* entity, ScriptExecutionContext* context);
void ScriptCommand_SoundReq0x80100000(Entity* entity, ScriptExecutionContext* context);
void ScriptCommand_StopBgm(Entity* entity, ScriptExecutionContext* context);
void ScriptCommand_ModRupees(Entity* entity, ScriptExecutionContext* context);
void ScriptCommand_ModHealth(Entity* entity, ScriptExecutionContext* context);
void ScriptCommand_IncreaseMaxHealth(Entity* entity, ScriptExecutionContext* context);
@@ -287,7 +287,7 @@ const ScriptCommand gScriptCommands[] = { ScriptCommandNop,
ScriptCommand_PlaySound,
ScriptCommand_PlayBgm,
ScriptCommand_SoundReq,
ScriptCommand_SoundReq0x80100000,
ScriptCommand_StopBgm,
ScriptCommand_ModRupees,
ScriptCommand_ModHealth,
ScriptCommand_IncreaseMaxHealth,
@@ -1467,8 +1467,8 @@ void ScriptCommand_SoundReq(Entity* entity, ScriptExecutionContext* context) {
SoundReq(GetNextScriptCommandWordAfterCommandMetadata(context->scriptInstructionPointer));
}
void ScriptCommand_SoundReq0x80100000(Entity* entity, ScriptExecutionContext* context) {
SoundReq(SONG_RESET_UNK);
void ScriptCommand_StopBgm(Entity* entity, ScriptExecutionContext* context) {
SoundReq(SONG_STOP_BGM);
}
void ScriptCommand_ModRupees(Entity* entity, ScriptExecutionContext* context) {