From 5a9c2871ed5f774c845a4f83d38bec5884b25f3e Mon Sep 17 00:00:00 2001 From: Tharo <17233964+Thar0@users.noreply.github.com> Date: Sat, 21 Dec 2024 01:41:28 +0000 Subject: [PATCH] Move gAudioTatumInit and gAudioHeapInitSizes to their own file, using data-with-rodata instead of const qualifiers (#1771) * Do not qualify gAudioHeapInitSizes with const under AVOID_UB * Move gAudioTatumInit and gAudioHeapInitSizes to their own file, move data to rodata * Space --- Makefile | 11 +++++++++-- include/variables.h | 6 ++---- include/z64audio.h | 2 ++ spec | 1 + src/audio/lib/load.c | 3 +-- src/audio/session_config.c | 24 ------------------------ src/audio/session_init.c | 26 ++++++++++++++++++++++++++ 7 files changed, 41 insertions(+), 32 deletions(-) create mode 100644 src/audio/session_init.c diff --git a/Makefile b/Makefile index 51cc13dd2c..5caf087bd1 100644 --- a/Makefile +++ b/Makefile @@ -593,6 +593,15 @@ $(BUILD_DIR)/src/code/z_game_over.o: src/code/z_game_over.c $(OBJDUMP_CMD) $(RM_MDEBUG) +# Incremental link audio/session_init data into rodata +$(BUILD_DIR)/src/audio/session_init.o: src/audio/session_init.c $(BUILD_DIR)/assets/audio/soundfont_sizes.h $(BUILD_DIR)/assets/audio/sequence_sizes.h + $(CC_CHECK_COMP) $(CC_CHECK_FLAGS) $(IINC) $(CC_CHECK_WARNINGS) $(C_DEFINES) $(MIPS_BUILTIN_DEFS) -o $(@:.o=.tmp) $< + $(CC) -c $(CFLAGS) $(IINC) $(WARNINGS) $(C_DEFINES) $(MIPS_VERSION) $(ENDIAN) $(OPTFLAGS) -o $(@:.o=.tmp) $< + $(LD) -r -T linker_scripts/data_with_rodata.ld $(@:.o=.tmp) -o $@ + @$(RM) $(@:.o=.tmp) + $(OBJDUMP_CMD) + $(RM_MDEBUG) + $(SHIFTJIS_O_FILES): $(BUILD_DIR)/src/%.o: src/%.c $(SHIFTJIS_CONV) -o $(@:.o=.enc.c) $< $(CC_CHECK_COMP) $(CC_CHECK_FLAGS) $(IINC) $(CC_CHECK_WARNINGS) $(C_DEFINES) $(MIPS_BUILTIN_DEFS) -o $@ $(@:.o=.enc.c) @@ -783,8 +792,6 @@ $(BUILD_DIR)/assets/audio/sequence_font_table.o: $(BUILD_DIR)/assets/audio/seque # make headers with file sizes and amounts -$(BUILD_DIR)/src/audio/session_config.o: $(BUILD_DIR)/assets/audio/soundfont_sizes.h $(BUILD_DIR)/assets/audio/sequence_sizes.h - $(BUILD_DIR)/assets/audio/soundfont_sizes.h: $(SOUNDFONT_O_FILES) $(AFILE_SIZES) $@ NUM_SOUNDFONTS SOUNDFONT_SIZES .rodata $^ diff --git a/include/variables.h b/include/variables.h index 961b1a2f1b..8ac8fcba9a 100644 --- a/include/variables.h +++ b/include/variables.h @@ -36,8 +36,8 @@ extern AudioSpec gAudioSpecs[21]; // rodata extern const u16 gAudioEnvironmentalSfx[]; -extern const s16 gAudioTatumInit[]; -extern const AudioHeapInitSizes gAudioHeapInitSizes; +extern s16 gAudioTatumInit[]; +extern AudioHeapInitSizes gAudioHeapInitSizes; extern AudioTable gSoundFontTable; extern u8 gSequenceFontTable[]; extern u8 gSequenceTable[]; @@ -48,8 +48,6 @@ extern AudioTable gSampleBankTable; extern u64* gAudioSPDataPtr; extern u32 gAudioSPDataSize; -extern AudioContext gAudioCtx; // at 0x80200C70 - // other segments extern Mtx D_01000000; extern Gfx D_08000000[]; diff --git a/include/z64audio.h b/include/z64audio.h index 68fc2f8a4f..8e53f2ecea 100644 --- a/include/z64audio.h +++ b/include/z64audio.h @@ -261,4 +261,6 @@ typedef struct AudioContext { /* 0x81F4 */ UNK_TYPE1 unk_81F4[4]; } AudioContext; // size = 0x81F8 +extern AudioContext gAudioCtx; // at 0x80200C70 + #endif diff --git a/spec b/spec index b0df5c0b68..d5c82aa769 100644 --- a/spec +++ b/spec @@ -771,6 +771,7 @@ beginseg include "$(BUILD_DIR)/src/audio/sfx.o" include "$(BUILD_DIR)/src/audio/sequence.o" include "$(BUILD_DIR)/src/audio/session_config.o" + include "$(BUILD_DIR)/src/audio/session_init.o" include "$(BUILD_DIR)/src/code/jpegutils.o" include "$(BUILD_DIR)/src/code/jpegdecoder.o" include "$(BUILD_DIR)/src/code/z_game_over.o" diff --git a/src/audio/lib/load.c b/src/audio/lib/load.c index d3d32f6c4a..d4a3b9d813 100644 --- a/src/audio/lib/load.c +++ b/src/audio/lib/load.c @@ -1339,8 +1339,7 @@ void AudioLoad_Init(void* heap, size_t heapSize) { } if (addr = AudioHeap_Alloc(&gAudioCtx.initPool, gAudioHeapInitSizes.permanentPoolSize), addr == NULL) { - // cast away const from gAudioHeapInitSizes - *((u32*)&gAudioHeapInitSizes.permanentPoolSize) = 0; + gAudioHeapInitSizes.permanentPoolSize = 0; } AudioHeap_InitPool(&gAudioCtx.permanentPool, addr, gAudioHeapInitSizes.permanentPoolSize); diff --git a/src/audio/session_config.c b/src/audio/session_config.c index 37125864fe..4f6d9c68d7 100644 --- a/src/audio/session_config.c +++ b/src/audio/session_config.c @@ -1,10 +1,4 @@ #include "global.h" -#include "buffers.h" -#include "assets/audio/sequence_sizes.h" -#include "assets/audio/soundfont_sizes.h" -#define SFX_SEQ_SIZE Sequence_0_SIZE -#define AMBIENCE_SEQ_SIZE Sequence_1_SIZE -#define SFX_SOUNDFONTS_SIZE (Soundfont_0_SIZE + Soundfont_1_SIZE + Soundfont_2_SIZE) static s32 sBssPad[36]; AudioContext gAudioCtx; @@ -14,24 +8,6 @@ AudioCustomReverbFunction gAudioCustomReverbFunction; AudioCustomSynthFunction gAudioCustomSynthFunction; static s32 sBssPad2[3]; -const s16 gAudioTatumInit[] = { - 0x1C00, // unused - TATUMS_PER_BEAT, // gTatumsPerBeat -}; - -// Sizes of everything on the init pool -#define AI_BUFFERS_SIZE (AIBUF_SIZE * ARRAY_COUNT(gAudioCtx.aiBuffers)) -#define SOUNDFONT_LIST_SIZE (NUM_SOUNDFONTS * sizeof(SoundFont)) - -// 0x19BD0 -#define PERMANENT_POOL_SIZE (SFX_SEQ_SIZE + AMBIENCE_SEQ_SIZE + SFX_SOUNDFONTS_SIZE + 0x430) - -const AudioHeapInitSizes gAudioHeapInitSizes = { - ALIGN16(sizeof(gAudioHeap) - 0x100), // audio heap size - ALIGN16(PERMANENT_POOL_SIZE + AI_BUFFERS_SIZE + SOUNDFONT_LIST_SIZE + 0x40), // init pool size - ALIGN16(PERMANENT_POOL_SIZE), // permanent pool size -}; - #define REVERB_INDEX_0_SETTINGS \ { 1, 0x30, 0x3000, 0, 0, 0x7FFF, 0x0000, 0x0000, REVERB_INDEX_NONE, 0x3000, 0, 0 } diff --git a/src/audio/session_init.c b/src/audio/session_init.c new file mode 100644 index 0000000000..24649b597c --- /dev/null +++ b/src/audio/session_init.c @@ -0,0 +1,26 @@ +#include "z64audio.h" +#include "buffers.h" +#include "assets/audio/sequence_sizes.h" +#include "assets/audio/soundfont_sizes.h" + +#define SFX_SEQ_SIZE Sequence_0_SIZE +#define AMBIENCE_SEQ_SIZE Sequence_1_SIZE +#define SFX_SOUNDFONTS_SIZE (Soundfont_0_SIZE + Soundfont_1_SIZE + Soundfont_2_SIZE) + +s16 gAudioTatumInit[] = { + 0x1C00, // unused + TATUMS_PER_BEAT, // gTatumsPerBeat +}; + +// Sizes of everything on the init pool +#define AI_BUFFERS_SIZE (AIBUF_SIZE * ARRAY_COUNT(gAudioCtx.aiBuffers)) +#define SOUNDFONT_LIST_SIZE (NUM_SOUNDFONTS * sizeof(SoundFont)) + +// 0x19BD0 +#define PERMANENT_POOL_SIZE (SFX_SEQ_SIZE + AMBIENCE_SEQ_SIZE + SFX_SOUNDFONTS_SIZE + 0x430) + +AudioHeapInitSizes gAudioHeapInitSizes = { + ALIGN16(sizeof(gAudioHeap) - 0x100), // audio heap size + ALIGN16(PERMANENT_POOL_SIZE + AI_BUFFERS_SIZE + SOUNDFONT_LIST_SIZE + 0x40), // init pool size + ALIGN16(PERMANENT_POOL_SIZE), // permanent pool size +};