diff --git a/include/config/config_audio.h b/include/config/config_audio.h index 5aa64360..5111911b 100644 --- a/include/config/config_audio.h +++ b/include/config/config_audio.h @@ -4,19 +4,27 @@ * AUDIO SETTINGS * ******************/ -// Fixes the castle music sometimes triggering after getting a dialog. +/** + * Fixes the castle music sometimes triggering after getting a dialog. + */ #define CASTLE_MUSIC_FIX -// Increase audio heap size to allow for more concurrent notes to be played and for more custom sequences/banks to be imported (not supported for SH). +/** + * Increase audio heap size to allow for more concurrent notes to be played and for more custom sequences/banks to be imported (not supported for SH). + */ #define EXPAND_AUDIO_HEAP -// The maximum number of notes (sfx inclusive) that can sound at any given time (not supported for SH). -// Lower values may cause notes to get cut more easily but can potentially improve performance slightly. -// Lower values may cause problems with streamed audio if a sequence used for it is missing channel priority data. -// Vanilla by default only generally allocates 16 or 20 notes at once. Memory usage is always determined by the largest of the two values here. +/** + * The maximum number of notes (sfx inclusive) that can sound at any given time (not supported for SH). + * Lower values may cause notes to get cut more easily but can potentially improve performance slightly. + * Lower values may cause problems with streamed audio if a sequence used for it is missing channel priority data. + * Vanilla by default only generally allocates 16 or 20 notes at once. Memory usage is always determined by the largest of the two values here (~7200 bytes per US/JP note). + */ #define MAX_SIMULTANEOUS_NOTES_EMULATOR 40 #define MAX_SIMULTANEOUS_NOTES_CONSOLE 32 -// Use a much better implementation of reverb over vanilla's fake echo reverb. Great for caves or eerie levels, as well as just a better audio experience in general. -// Reverb parameters can be configured in audio/synthesis.c to meet desired aesthetic/performance needs. Currently US/JP only. Hurts emulator and console performance. +/** + * Use a much better implementation of reverb over vanilla's fake echo reverb. Great for caves or eerie levels, as well as just a better audio experience in general. + * Reverb parameters can be configured in audio/synthesis.c to meet desired aesthetic/performance needs. Currently US/JP only. Hurts emulator and console performance. + */ //#define BETTER_REVERB diff --git a/include/config/config_safeguards.h b/include/config/config_safeguards.h index 23d6b989..6971fe96 100644 --- a/include/config/config_safeguards.h +++ b/include/config/config_safeguards.h @@ -40,6 +40,13 @@ #if (MAX_SIMULTANEOUS_NOTES > 64) #undef MAX_SIMULTANEOUS_NOTES #define MAX_SIMULTANEOUS_NOTES 64 +#elif (MAX_SIMULTANEOUS_NOTES < 0) + #undef MAX_SIMULTANEOUS_NOTES + #define MAX_SIMULTANEOUS_NOTES 0 +#endif + +#if defined(BETTER_REVERB) && !(defined(VERSION_US) || defined(VERSION_JP)) + #undef BETTER_REVERB #endif diff --git a/src/audio/data.c b/src/audio/data.c index 801c7233..d536a227 100644 --- a/src/audio/data.c +++ b/src/audio/data.c @@ -10,7 +10,7 @@ extern struct OSMesgQueue OSMesgQueue3; // Since the audio session is just one now, the reverb settings are duplicated to match the original audio setting scenario. // It's a bit hacky but whatever lol. Index range must be defined, since it's needed by the compiler. -// To increase reverb window sizes beyond 64, please increase the REVERB_WINDOW_SIZE_MAX in heap.c by a factor of 0x40 and update AUDIO_HEAP_SIZE by 4x the same amount. +// To increase reverb window sizes beyond 64, please increase the REVERB_WINDOW_SIZE_MAX in heap.c by a factor of 0x40. #ifdef VERSION_EU struct ReverbSettingsEU sReverbSettings[8] = { { /*Downsample Rate*/ 1, /*Window Size*/ 64, /*Gain*/ 0x2FFF }, @@ -57,7 +57,7 @@ struct AudioSessionSettingsEU gAudioSessionPresets[] = { // - memory used for temporary sequences // - memory used for temporary banks -// To increase reverb window sizes beyond 0x1000, please increase the REVERB_WINDOW_SIZE_MAX in heap.c and update AUDIO_HEAP_SIZE by the same amount. +// To increase reverb window sizes beyond 0x1000, please increase the REVERB_WINDOW_SIZE_MAX in heap.c. #if defined(VERSION_JP) || defined(VERSION_US) struct ReverbSettingsUS gReverbSettings[18] = { { 1, 0x0C00, 0x2FFF }, diff --git a/src/audio/data.h b/src/audio/data.h index ab31a82f..826ae059 100644 --- a/src/audio/data.h +++ b/src/audio/data.h @@ -122,11 +122,11 @@ extern u32 gAudioRandom; MAX_SIMULTANEOUS_NOTES * ((4 /* updatesPerFrame */ * 20 * 2 * sizeof(u64)) \ + ALIGN16(sizeof(struct Note)) \ + (DMA_BUF_SIZE_0 * 3) \ - + (DMA_BUF_SIZE_1) \ + + DMA_BUF_SIZE_1 \ + ALIGN16(sizeof(struct NoteSynthesisBuffers))) \ - + 320 * 2 * sizeof(u64) /* gMaxAudioCmds */ \ + + (320 * 2 * sizeof(u64)) /* gMaxAudioCmds */ \ ) -#elif defined(VERSION_EU) +#else // Probably SH incompatible but that's an entirely different headache to save at this point tbh #define NOTES_BUFFER_SIZE \ ( \ MAX_SIMULTANEOUS_NOTES * ((4 /* updatesPerFrame */ * 0x10 * 2 * sizeof(u64)) \ @@ -135,8 +135,7 @@ extern u32 gAudioRandom; + (DMA_BUF_SIZE_1) \ + ALIGN16(sizeof(struct NoteSynthesisBuffers)) \ + ALIGN16(4 /* updatesPerFrame */ * sizeof(struct NoteSubEu))) \ - + (0x300 + 4 /* numReverbs */ * 0x20) * 2 * sizeof(u64) /* gMaxAudioCmds */ \ - + 0x4000 /* Extra space to hopefully tolerate whatever the note patch behavior is */ \ + + ((0x300 + (4 /* numReverbs */ * 0x20)) * 2 * sizeof(u64)) /* gMaxAudioCmds */ \ ) #endif diff --git a/src/audio/heap.c b/src/audio/heap.c index 3c08d8a7..b94d65ed 100644 --- a/src/audio/heap.c +++ b/src/audio/heap.c @@ -32,7 +32,7 @@ struct SoundAllocPool gAudioSessionPool; struct SoundAllocPool gAudioInitPool; struct SoundAllocPool gNotesAndBuffersPool; u8 sAudioHeapPad[0x20]; // probably two unused pools -#if defined(BETTER_REVERB) && (defined(VERSION_US) || defined(VERSION_JP)) +#ifdef BETTER_REVERB struct SoundAllocPool gBetterReverbPool; #endif struct SoundAllocPool gSeqAndBankPool; @@ -310,7 +310,7 @@ void puppyprint_get_allocated_pools(s32 *audioPoolList) { &gSeqLoadedPool.temporary.pool, &gBankLoadedPool.persistent.pool, &gBankLoadedPool.temporary.pool, -#if defined(BETTER_REVERB) && (defined(VERSION_US) || defined(VERSION_JP)) +#ifdef BETTER_REVERB &gBetterReverbPool, #endif }; @@ -332,7 +332,7 @@ void session_pools_init(struct PoolSplit *a) { gAudioSessionPool.cur = gAudioSessionPool.start; sound_alloc_pool_init(&gNotesAndBuffersPool, SOUND_ALLOC_FUNC(&gAudioSessionPool, a->wantSeq ), a->wantSeq ); sound_alloc_pool_init(&gSeqAndBankPool, SOUND_ALLOC_FUNC(&gAudioSessionPool, a->wantCustom ), a->wantCustom ); -#if defined(BETTER_REVERB) && (defined(VERSION_US) || defined(VERSION_JP)) +#ifdef BETTER_REVERB sound_alloc_pool_init(&gBetterReverbPool, SOUND_ALLOC_FUNC(&gAudioSessionPool, BETTER_REVERB_SIZE), BETTER_REVERB_SIZE); #endif } @@ -1344,12 +1344,9 @@ void audio_reset_session(void) { #if defined(VERSION_SH) persistentMem = DOUBLE_SIZE_ON_64_BIT(preset->persistentSeqMem + preset->persistentBankMem + preset->unk18 + preset->unkMem28 + 0x10); temporaryMem = DOUBLE_SIZE_ON_64_BIT(preset->temporarySeqMem + preset->temporaryBankMem + preset->unk24 + preset->unkMem2C + 0x10); -#elif defined(VERSION_EU) +#else persistentMem = DOUBLE_SIZE_ON_64_BIT(preset->persistentSeqMem + preset->persistentBankMem); temporaryMem = DOUBLE_SIZE_ON_64_BIT(preset->temporarySeqMem + preset->temporaryBankMem); -#else - persistentMem = DOUBLE_SIZE_ON_64_BIT(preset->persistentBankMem + preset->persistentSeqMem); - temporaryMem = DOUBLE_SIZE_ON_64_BIT(preset->temporaryBankMem + preset->temporarySeqMem); #endif totalMem = persistentMem + temporaryMem; wantMisc = gAudioSessionPool.size - totalMem - BETTER_REVERB_SIZE; @@ -1436,6 +1433,8 @@ void audio_reset_session(void) { if (gMaxSimultaneousNotes > MAX_SIMULTANEOUS_NOTES) gMaxSimultaneousNotes = MAX_SIMULTANEOUS_NOTES; + else if (gMaxSimultaneousNotes < 0) + gMaxSimultaneousNotes = 0; sAudioFirstBoot = 1; } diff --git a/src/audio/synthesis.c b/src/audio/synthesis.c index 551c75d5..0f5f5315 100644 --- a/src/audio/synthesis.c +++ b/src/audio/synthesis.c @@ -39,7 +39,7 @@ #define AUDIO_ALIGN(val, amnt) (((val) + (1 << amnt) - 1) & ~((1 << amnt) - 1)) -#if defined(BETTER_REVERB) && (defined(VERSION_US) || defined(VERSION_JP)) +#ifdef BETTER_REVERB /* ----------------------------------------------------------------------BEGIN REVERB PARAMETERS---------------------------------------------------------------------- */ @@ -206,7 +206,7 @@ struct SynthesisReverb gSynthesisReverb; u8 sAudioSynthesisPad[0x20]; #endif -#if defined(BETTER_REVERB) && (defined(VERSION_US) || defined(VERSION_JP)) +#ifdef BETTER_REVERB static inline void reverb_samples(s16 *outSampleL, s16 *outSampleR, s32 inSampleL, s32 inSampleR) { s32 i = 0; s32 j = 0; diff --git a/src/audio/synthesis.h b/src/audio/synthesis.h index b29cc399..1adaa6d9 100644 --- a/src/audio/synthesis.h +++ b/src/audio/synthesis.h @@ -19,7 +19,7 @@ #define ALIGN16(val) (((val) + 0xF) & ~0xF) -#if defined(BETTER_REVERB) && (defined(VERSION_US) || defined(VERSION_JP)) +#ifdef BETTER_REVERB #define NUM_ALLPASS 12 // Number of delay filters to use with better reverb; do not change this value if you don't know what you're doing. #define BETTER_REVERB_PTR_SIZE ALIGN16(NUM_ALLPASS * sizeof(s32*) * 2) // Allocation space consumed by dynamically allocated pointers diff --git a/src/game/puppyprint.c b/src/game/puppyprint.c index 9987026b..2b1a64cc 100644 --- a/src/game/puppyprint.c +++ b/src/game/puppyprint.c @@ -316,7 +316,7 @@ const char *audioPoolNames[NUM_AUDIO_POOLS] = { "gSeqLoadedPool.temporary.pool", "gBankLoadedPool.persistent.pool", "gBankLoadedPool.temporary.pool", -#if defined(BETTER_REVERB) && (defined(VERSION_US) || defined(VERSION_JP)) +#ifdef BETTER_REVERB "gBetterReverbPool", #endif }; diff --git a/src/game/puppyprint.h b/src/game/puppyprint.h index 7608adc9..621a3fc1 100644 --- a/src/game/puppyprint.h +++ b/src/game/puppyprint.h @@ -33,7 +33,7 @@ enum PuppyprintTextAlign { }; #if PUPPYPRINT_DEBUG -#if defined(BETTER_REVERB) && (defined(VERSION_US) || defined(VERSION_JP)) +#ifdef BETTER_REVERB #define NUM_AUDIO_POOLS 7 #else #define NUM_AUDIO_POOLS 6