From fe8384a44038525085f1fdaa58f4b088418f3936 Mon Sep 17 00:00:00 2001 From: gheskett Date: Thu, 24 Feb 2022 02:07:39 -0500 Subject: [PATCH 1/9] Deprecate sBackgroundMusicDefaultVolume --- src/audio/external.c | 14 ++++++++++---- src/audio/internal.h | 2 +- src/audio/seqplayer.c | 16 +++++++++++++--- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/audio/external.c b/src/audio/external.c index 4aca7632..7f77c613 100644 --- a/src/audio/external.c +++ b/src/audio/external.c @@ -259,7 +259,12 @@ u16 sLevelAcousticReaches[LEVEL_COUNT] = { #define VOLUME_RANGE_UNK2 0.8f #endif -// Default volume for background music sequences (playing on player 0). +// sBackgroundMusicDefaultVolume represents the default volume for background music sequences using the level player (deprecated). +// This code block is simply commented out for now as to not destroy compatibility with any streamed audio tools. +// TODO: Delete this entirely once the unsupporting streamed tools or their builds are outdated. + +/* + u8 sBackgroundMusicDefaultVolume[] = { 127, // SEQ_SOUND_PLAYER 80, // SEQ_EVENT_CUTSCENE_COLLECT_STAR @@ -301,6 +306,8 @@ u8 sBackgroundMusicDefaultVolume[] = { STATIC_ASSERT(ARRAY_COUNT(sBackgroundMusicDefaultVolume) == SEQ_COUNT, "change this array if you are adding sequences"); +*/ + u8 sCurrentBackgroundMusicSeqId = SEQUENCE_NONE; u8 sMusicDynamicDelay = 0; u8 sSoundBankUsedListBack[SOUND_BANK_COUNT] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; @@ -1885,7 +1892,7 @@ static u8 begin_background_music_fade(u16 fadeDuration) { targetVolume = 40; } - if (sSoundBanksThatLowerBackgroundMusic != 0 && targetVolume > 20) { + if (sSoundBanksThatLowerBackgroundMusic && targetVolume > 20) { targetVolume = 20; } @@ -1894,8 +1901,7 @@ static u8 begin_background_music_fade(u16 fadeDuration) { seq_player_fade_to_target_volume(SEQ_PLAYER_LEVEL, fadeDuration, targetVolume); } else { #if defined(VERSION_JP) || defined(VERSION_US) - gSequencePlayers[SEQ_PLAYER_LEVEL].volume = - sBackgroundMusicDefaultVolume[sCurrentBackgroundMusicSeqId] / 127.0f; + gSequencePlayers[SEQ_PLAYER_LEVEL].volume = gSequencePlayers[SEQ_PLAYER_LEVEL].volumeDefault; #endif seq_player_fade_to_normal_volume(SEQ_PLAYER_LEVEL, fadeDuration); } diff --git a/src/audio/internal.h b/src/audio/internal.h index f8465693..c9077872 100644 --- a/src/audio/internal.h +++ b/src/audio/internal.h @@ -300,7 +300,7 @@ struct SequencePlayer { /* , 0x028, 0x02C*/ f32 fadeVolumeScale; /* , 0x02C*/ f32 appliedFadeVolume; #else - /* */ u8 pad2[4]; + /*0x028, */ f32 volumeDefault; #endif /*0x02C, 0x030, 0x034*/ struct SequenceChannel *channels[CHANNELS_MAX]; /*0x06C, 0x070*/ struct M64ScriptState scriptState; diff --git a/src/audio/seqplayer.c b/src/audio/seqplayer.c index 766d9b37..6628da32 100644 --- a/src/audio/seqplayer.c +++ b/src/audio/seqplayer.c @@ -2493,6 +2493,10 @@ void sequence_player_process_sequence(struct SequencePlayer *seqPlayer) { #else case 0xdb: // seq_setvol cmd = m64_read_u8(state); + seqPlayer->volumeDefault = FLOAT_CAST(cmd) / 127.0f; + if (seqPlayer->volumeDefault >= 1.0f) + seqPlayer->volumeDefault = 1.0f; + switch (seqPlayer->state) { case SEQUENCE_PLAYER_STATE_2: if (seqPlayer->fadeRemainingFrames != 0) { @@ -2513,9 +2517,14 @@ void sequence_player_process_sequence(struct SequencePlayer *seqPlayer) { break; case 0xda: // seq_changevol - temp = m64_read_u8(state); - seqPlayer->fadeVolume = - seqPlayer->fadeVolume + (f32)(s8) temp / 127.0f; + temp = (f32)(s8) m64_read_u8(state) / 127.0f; + seqPlayer->fadeVolume += temp; + + seqPlayer->volumeDefault += temp; + if (seqPlayer->volumeDefault > 1.0f) + seqPlayer->volumeDefault = 1.0f; + else if (seqPlayer->volumeDefault < 0.0f) + seqPlayer->volumeDefault = 0.0f; break; #endif @@ -2707,6 +2716,7 @@ void init_sequence_player(u32 player) { seqPlayer->state = 1; #else seqPlayer->state = SEQUENCE_PLAYER_STATE_0; + seqPlayer->volumeDefault = 1.0f; #endif seqPlayer->fadeRemainingFrames = 0; #if defined(VERSION_EU) || defined(VERSION_SH) From 6bd3988dd8600fdccfacfe6f6744ccd2954b6593 Mon Sep 17 00:00:00 2001 From: gheskett Date: Fri, 25 Feb 2022 05:11:16 -0500 Subject: [PATCH 2/9] Add MAX_SIMULTANEOUS_NOTES defines and better document audio allocations for audio heap (looks kinda awful still) --- include/config/config_audio.h | 11 +++++-- include/config/config_safeguards.h | 33 +++++++++++++++++++ src/audio/data.c | 9 +++--- src/audio/data.h | 51 ++++++++++++++++++++++++------ src/audio/heap.c | 18 ++++++++--- src/audio/internal.h | 4 ++- src/audio/load.c | 17 +++------- src/audio/playback.c | 6 ++-- src/audio/synthesis.h | 17 +++++++++- src/boot/main.c | 10 ++++++ src/game/game_init.c | 9 ------ 11 files changed, 139 insertions(+), 46 deletions(-) diff --git a/include/config/config_audio.h b/include/config/config_audio.h index 1d1f5270..5aa64360 100644 --- a/include/config/config_audio.h +++ b/include/config/config_audio.h @@ -4,12 +4,19 @@ * 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. +#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. //#define BETTER_REVERB diff --git a/include/config/config_safeguards.h b/include/config/config_safeguards.h index 0a5dd97d..23d6b989 100644 --- a/include/config/config_safeguards.h +++ b/include/config/config_safeguards.h @@ -10,6 +10,39 @@ */ +/***************** + * config_audio + */ + +#ifndef MAX_SIMULTANEOUS_NOTES_EMULATOR + #ifdef EXPAND_AUDIO_HEAP + #define MAX_SIMULTANEOUS_NOTES_EMULATOR 40 + #else + #define MAX_SIMULTANEOUS_NOTES_EMULATOR 20 + #endif +#endif // MAX_SIMULTANEOUS_NOTES_EMULATOR + +#ifndef MAX_SIMULTANEOUS_NOTES_CONSOLE + #ifdef EXPAND_AUDIO_HEAP + #define MAX_SIMULTANEOUS_NOTES_EMULATOR 32 + #else + #define MAX_SIMULTANEOUS_NOTES_EMULATOR 16 + #endif +#endif // MAX_SIMULTANEOUS_NOTES_CONSOLE + +#if (MAX_SIMULTANEOUS_NOTES_EMULATOR >= MAX_SIMULTANEOUS_NOTES_CONSOLE) + #define MAX_SIMULTANEOUS_NOTES MAX_SIMULTANEOUS_NOTES_EMULATOR +#else + #define MAX_SIMULTANEOUS_NOTES MAX_SIMULTANEOUS_NOTES_CONSOLE +#endif + +// Anything higher than 64 will most likely crash on boot. Even if it doesn't, it's still dangerous. +#if (MAX_SIMULTANEOUS_NOTES > 64) + #undef MAX_SIMULTANEOUS_NOTES + #define MAX_SIMULTANEOUS_NOTES 64 +#endif + + /***************** * config_graphics */ diff --git a/src/audio/data.c b/src/audio/data.c index 95917497..801c7233 100644 --- a/src/audio/data.c +++ b/src/audio/data.c @@ -38,9 +38,9 @@ struct ReverbSettingsEU sReverbSettings[8] = { struct AudioSessionSettingsEU gAudioSessionPresets[] = { #ifdef EXPAND_AUDIO_HEAP - { /*1*/ 32000,/*2*/ 1,/*3*/ 40,/*4*/ 1,/*5*/ 0, &sReverbSettings[0],/*6*/ 0x7FFF,/*7*/ 0,/*8*/ 0x8200,/*9*/ 0xDC00,/*10*/ 0xE800,/*11*/ 0x5500 }, + { /*1*/ 32000,/*2*/ 1,/*3*/ MAX_SIMULTANEOUS_NOTES,/*4*/ 1,/*5*/ 0, &sReverbSettings[0],/*6*/ 0x7FFF,/*7*/ 0,/*8*/ 0x8200,/*9*/ 0xDC00,/*10*/ 0xE800,/*11*/ 0x5500 }, #else - { /*1*/ 32000,/*2*/ 1,/*3*/ 20,/*4*/ 1,/*5*/ 0, &sReverbSettings[0],/*6*/ 0x7FFF,/*7*/ 0,/*8*/ 0x4100,/*9*/ 0x6E00,/*10*/ 0x7400,/*11*/ 0x2A80 }, + { /*1*/ 32000,/*2*/ 1,/*3*/ MAX_SIMULTANEOUS_NOTES,/*4*/ 1,/*5*/ 0, &sReverbSettings[0],/*6*/ 0x7FFF,/*7*/ 0,/*8*/ 0x4100,/*9*/ 0x6E00,/*10*/ 0x7400,/*11*/ 0x2A80 }, #endif }; #endif @@ -80,14 +80,13 @@ struct ReverbSettingsUS gReverbSettings[18] = { { 1, 0x0800, 0x2FFF }, }; -// TODO: Does using 40/20 instead of 32/16 for gMaxSimultaneousNotes cause memory problems at high capacities or is it good as is? #ifdef EXPAND_AUDIO_HEAP struct AudioSessionSettings gAudioSessionPresets[1] = { - { 32000, 40, 1, 0x1000, 0x2FFF, 0x7FFF, 0x8200, 0xDC00, 0xE800, 0x5500 }, + { 32000, MAX_SIMULTANEOUS_NOTES, 1, 0x1000, 0x2FFF, 0x7FFF, 0x8200, 0xDC00, 0xE800, 0x5500 }, }; #else struct AudioSessionSettings gAudioSessionPresets[1] = { - { 32000, 20, 1, 0x1000, 0x2FFF, 0x7FFF, 0x4100, 0x6E00, 0x7400, 0x2A80 }, + { 32000, MAX_SIMULTANEOUS_NOTES, 1, 0x1000, 0x2FFF, 0x7FFF, 0x4100, 0x6E00, 0x7400, 0x2A80 }, }; #endif #endif diff --git a/src/audio/data.h b/src/audio/data.h index 8e947aa9..ab31a82f 100644 --- a/src/audio/data.h +++ b/src/audio/data.h @@ -13,6 +13,14 @@ #define NUMAIBUFFERS 3 +#if defined(VERSION_EU) +#define DMA_BUF_SIZE_0 0x400 +#define DMA_BUF_SIZE_1 0x200 +#else +#define DMA_BUF_SIZE_0 (144 * 9) +#define DMA_BUF_SIZE_1 (160 * 9) +#endif + // constant .data #if defined(VERSION_EU) || defined(VERSION_SH) extern struct AudioSessionSettingsEU gAudioSessionPresets[]; @@ -108,18 +116,42 @@ extern s16 gAiBufferLengths[NUMAIBUFFERS]; extern u32 gAudioRandom; +#if defined(VERSION_US) || defined(VERSION_JP) +#define NOTES_BUFFER_SIZE \ +( \ + MAX_SIMULTANEOUS_NOTES * ((4 /* updatesPerFrame */ * 20 * 2 * sizeof(u64)) \ + + ALIGN16(sizeof(struct Note)) \ + + (DMA_BUF_SIZE_0 * 3) \ + + (DMA_BUF_SIZE_1) \ + + ALIGN16(sizeof(struct NoteSynthesisBuffers))) \ + + 320 * 2 * sizeof(u64) /* gMaxAudioCmds */ \ +) +#elif defined(VERSION_EU) +#define NOTES_BUFFER_SIZE \ +( \ + MAX_SIMULTANEOUS_NOTES * ((4 /* updatesPerFrame */ * 0x10 * 2 * sizeof(u64)) \ + + ALIGN16(sizeof(struct Note)) \ + + (DMA_BUF_SIZE_0 * 3 * 1 /* presetUnk4 */) \ + + (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 */ \ +) +#endif + #ifdef EXPAND_AUDIO_HEAP #if defined(VERSION_US) || defined(VERSION_JP) || defined(VERSION_EU) -#define EXT_AUDIO_HEAP_SIZE 0x27400 -#define EXT_AUDIO_INIT_POOL_SIZE 0x02000 +#define EXT_AUDIO_INIT_POOL_SIZE (0x1800 + 0x300) +#define EXT_AUDIO_HEAP_SIZE 0x14D80 #else // SH not yet supported for expanded audio heap -#define EXT_AUDIO_HEAP_SIZE 0x0 #define EXT_AUDIO_INIT_POOL_SIZE 0x0 +#define EXT_AUDIO_HEAP_SIZE 0x0 #endif #else -#define EXT_AUDIO_HEAP_SIZE 0x0 #define EXT_AUDIO_INIT_POOL_SIZE 0x0 +#define EXT_AUDIO_HEAP_SIZE 0x0 #endif #ifdef VERSION_SH @@ -148,14 +180,15 @@ extern OSMesgQueue *D_SH_80350FA8; #endif #if defined(VERSION_EU) || defined(VERSION_SH) -#define AUDIO_HEAP_BASE 0x36B00 -#define AUDIO_INIT_POOL_SIZE (0x2C00 + EXT_AUDIO_INIT_POOL_SIZE) +#define AUDIO_INIT_POOL_SIZE (0x1B00 + EXT_AUDIO_INIT_POOL_SIZE + ALIGN16(MAX_SIMULTANEOUS_NOTES * sizeof(struct Note))) #else -#define AUDIO_HEAP_BASE 0x30750 -#define AUDIO_INIT_POOL_SIZE (0x2500 + EXT_AUDIO_INIT_POOL_SIZE) +#define AUDIO_INIT_POOL_SIZE (0x1600 + EXT_AUDIO_INIT_POOL_SIZE + ALIGN16(MAX_SIMULTANEOUS_NOTES * sizeof(struct Note))) #endif -#define AUDIO_HEAP_SIZE (AUDIO_HEAP_BASE + EXT_AUDIO_HEAP_SIZE + EXT_AUDIO_INIT_POOL_SIZE + BETTER_REVERB_SIZE + REVERB_WINDOW_HEAP_SIZE) +// TODO: needs validation once EU can compile. EU is very likely incorrect! +#define AUDIO_HEAP_BASE (0x14D80 /* sound bank space */ + AUDIO_INIT_POOL_SIZE + EXT_AUDIO_HEAP_SIZE + NOTES_BUFFER_SIZE) + +#define AUDIO_HEAP_SIZE (AUDIO_HEAP_BASE + BETTER_REVERB_SIZE + REVERB_WINDOW_HEAP_SIZE) #ifdef VERSION_SH extern u32 D_SH_80315EF0; diff --git a/src/audio/heap.c b/src/audio/heap.c index b6aba644..3c08d8a7 100644 --- a/src/audio/heap.c +++ b/src/audio/heap.c @@ -1382,19 +1382,20 @@ void audio_reset_session(void) { #if defined(VERSION_JP) || defined(VERSION_US) for (j = 0; j < 2; j++) { - gAudioCmdBuffers[j] = soundAlloc(&gNotesAndBuffersPool, gMaxAudioCmds * sizeof(u64)); + gAudioCmdBuffers[j] = soundAlloc(&gNotesAndBuffersPool, ALIGN16(gMaxAudioCmds * sizeof(u64))); } #endif - gNotes = soundAlloc(&gNotesAndBuffersPool, gMaxSimultaneousNotes * sizeof(struct Note)); + gNotes = soundAlloc(&gNotesAndBuffersPool, ALIGN16(gMaxSimultaneousNotes * sizeof(struct Note))); note_init_all(); init_note_free_list(); #if defined(VERSION_EU) || defined(VERSION_SH) - gNoteSubsEu = soundAlloc(&gNotesAndBuffersPool, (gAudioBufferParameters.updatesPerFrame * gMaxSimultaneousNotes) * sizeof(struct NoteSubEu)); + // NOTE: Cannot be computed automatically in the audio heap define; approximation to be used instead + gNoteSubsEu = soundAlloc(&gNotesAndBuffersPool, ALIGN16((gAudioBufferParameters.updatesPerFrame * gMaxSimultaneousNotes) * sizeof(struct NoteSubEu))); for (j = 0; j != 2; j++) { - gAudioCmdBuffers[j] = soundAlloc(&gNotesAndBuffersPool, gMaxAudioCmds * sizeof(u64)); + gAudioCmdBuffers[j] = soundAlloc(&gNotesAndBuffersPool, ALIGN16(gMaxAudioCmds * sizeof(u64))); } init_reverb_eu(); @@ -1427,6 +1428,15 @@ void audio_reset_session(void) { append_puppyprint_log("Audio Initialised in %dus.", (s32)OS_CYCLES_TO_USEC(osGetTime() - first)); #endif #endif + + if (gIsConsole) + gMaxSimultaneousNotes = MAX_SIMULTANEOUS_NOTES_CONSOLE; + else + gMaxSimultaneousNotes = MAX_SIMULTANEOUS_NOTES_EMULATOR; + + if (gMaxSimultaneousNotes > MAX_SIMULTANEOUS_NOTES) + gMaxSimultaneousNotes = MAX_SIMULTANEOUS_NOTES; + sAudioFirstBoot = 1; } diff --git a/src/audio/internal.h b/src/audio/internal.h index c9077872..d01da280 100644 --- a/src/audio/internal.h +++ b/src/audio/internal.h @@ -680,6 +680,7 @@ struct Note { /*0x18, 0x38*/ f32 portamentoFreqScale; /*0x1C, 0x3C*/ f32 vibratoFreqScale; /*0x20*/ u16 samplePosFrac; + /* */ u8 pad2[2]; /*0x24*/ struct AudioBankSound *sound; /*0x28, 0x40*/ struct SequenceChannelLayer *prevParentLayer; /*0x2C, 0x44*/ struct SequenceChannelLayer *parentLayer; @@ -690,6 +691,7 @@ struct Note { /*0x3E*/ u16 targetVolRight; // Q1.15, but will always be non-negative /*0x40*/ u8 reverbVol; // Q1.7 /*0x41*/ u8 unused1; // never read, set to 0x3f + /* */ u8 pad3[2]; /*0x44*/ struct NoteAttributes attributes; /*0x54, 0x58*/ struct AdsrState adsr; /*0x74, 0x7C*/ struct Portamento portamento; @@ -699,7 +701,7 @@ struct Note { /*0xA0*/ s16 reverbVolShifted; // Q1.15 /*0xA2*/ s16 unused2; // never read, set to 0 /*0xA4, 0x00*/ struct AudioListItem listItem; - /* */ u8 pad2[0xc]; + /* */ u8 pad4[0xc]; }; // size = 0xC0 #endif diff --git a/src/audio/load.c b/src/audio/load.c index 268fbf2a..d2003701 100644 --- a/src/audio/load.c +++ b/src/audio/load.c @@ -42,7 +42,7 @@ OSMesgQueue gAudioDmaMesgQueue; OSMesg gAudioDmaMesg; OSIoMesg gAudioDmaIoMesg; -struct SharedDma sSampleDmas[0x60]; +struct SharedDma sSampleDmas[MAX_SIMULTANEOUS_NOTES * 4]; u32 gSampleDmaNumListItems; // sh: 0x803503D4 u32 sSampleDmaListSize1; // sh: 0x803503D8 @@ -335,11 +335,7 @@ void init_sample_dma_buffers(UNUSED s32 arg0) { s32 j; #endif -#if defined(VERSION_EU) - sDmaBufSize = 0x400; -#else - sDmaBufSize = 144 * 9; -#endif + sDmaBufSize = DMA_BUF_SIZE_0; #if defined(VERSION_EU) for (i = 0; i < gMaxSimultaneousNotes * 3 * gAudioBufferParameters.presetUnk4; i++) { @@ -378,11 +374,8 @@ out1: sSampleDmaReuseQueueHead1 = (u8) gSampleDmaNumListItems; sSampleDmaListSize1 = gSampleDmaNumListItems; -#if defined(VERSION_EU) - sDmaBufSize = 0x200; -#else - sDmaBufSize = 160 * 9; -#endif + sDmaBufSize = DMA_BUF_SIZE_1; + for (i = 0; i < gMaxSimultaneousNotes; i++) { sSampleDmas[gSampleDmaNumListItems].buffer = soundAlloc(&gNotesAndBuffersPool, sDmaBufSize); if (sSampleDmas[gSampleDmaNumListItems].buffer == NULL) { @@ -442,7 +435,7 @@ void patch_sound(UNUSED struct AudioBankSound *sound, UNUSED u8 *memBase, UNUSED #if defined(VERSION_EU) else if (sample->loaded == 0x80) { PATCH(sample->sampleAddr, offsetBase); - u8 *mem = soundAlloc(&gNotesAndBuffersPool, sample->sampleSize); // TODO: Memory leak! + u8 *mem = soundAlloc(&gNotesAndBuffersPool, sample->sampleSize); // TODO: Memory issue most likely! if (mem == NULL) { sample->sampleAddr = patched; sample->loaded = 1; diff --git a/src/audio/playback.c b/src/audio/playback.c index 0c0b1fff..9a29f8c4 100644 --- a/src/audio/playback.c +++ b/src/audio/playback.c @@ -1443,9 +1443,9 @@ void note_init_all(void) { #if defined(VERSION_SH) note->synthesisState.synthesisBuffers = sound_alloc_uninitialized(&gNotesAndBuffersPool, sizeof(struct NoteSynthesisBuffers)); #elif defined(VERSION_EU) - note->synthesisState.synthesisBuffers = soundAlloc(&gNotesAndBuffersPool, sizeof(struct NoteSynthesisBuffers)); + note->synthesisState.synthesisBuffers = soundAlloc(&gNotesAndBuffersPool, ALIGN16(sizeof(struct NoteSynthesisBuffers))); #else - note->synthesisBuffers = soundAlloc(&gNotesAndBuffersPool, sizeof(struct NoteSynthesisBuffers)); + note->synthesisBuffers = soundAlloc(&gNotesAndBuffersPool, ALIGN16(sizeof(struct NoteSynthesisBuffers))); #endif } -} +} \ No newline at end of file diff --git a/src/audio/synthesis.h b/src/audio/synthesis.h index eb0242d3..b29cc399 100644 --- a/src/audio/synthesis.h +++ b/src/audio/synthesis.h @@ -63,7 +63,22 @@ extern u8 toggleBetterReverb; #endif -#define REVERB_WINDOW_HEAP_SIZE (REVERB_WINDOW_SIZE_MAX * sizeof(s16) * 2) +#if defined(VERSION_JP) || defined(VERSION_US) +#define REVERB_WINDOW_HEAP_SIZE \ +( \ + (REVERB_WINDOW_SIZE_MAX * sizeof(s16) * 2) \ + + (4 * (16 * sizeof(s16))) \ + + (4 /* gAudioUpdatesPerFrame */ * (2 * DEFAULT_LEN_2CH)) \ +) +#else +#define REVERB_WINDOW_HEAP_SIZE \ +( \ + ((REVERB_WINDOW_SIZE_MAX * sizeof(s16) * 2) \ + + (4 * (16 * sizeof(s16))) \ + + (4 /* gAudioUpdatesPerFrame */ * (2 * DEFAULT_LEN_2CH))) \ + * 4 /* gNumSynthesisReverbs */ \ +) +#endif struct ReverbRingBufferItem { s16 numSamplesAfterDownsampling; diff --git a/src/boot/main.c b/src/boot/main.c index 7761f07a..75a9dc54 100644 --- a/src/boot/main.c +++ b/src/boot/main.c @@ -13,6 +13,7 @@ #include "game/main.h" #include "game/rumble_init.h" #include "game/version.h" +#include "game/vc_check.h" #ifdef UNF #include "usb/usb.h" #include "usb/debug.h" @@ -317,6 +318,15 @@ void thread3_main(UNUSED void *arg) { osSyncPrintf("Linker : %s\n", __linker__); #endif + if (IO_READ(DPC_CLOCK_REG) == 0) { + gIsConsole = FALSE; + gBorderHeight = BORDER_HEIGHT_EMULATOR; + gIsVC = IS_VC(); + } else { + gIsConsole = TRUE; + gBorderHeight = BORDER_HEIGHT_CONSOLE; + } + create_thread(&gSoundThread, THREAD_4_SOUND, thread4_sound, NULL, gThread4Stack + 0x2000, 20); osStartThread(&gSoundThread); diff --git a/src/game/game_init.c b/src/game/game_init.c index 545e9e66..4a8934c6 100644 --- a/src/game/game_init.c +++ b/src/game/game_init.c @@ -391,15 +391,6 @@ void render_init(void) { #ifdef DEBUG_FORCE_CRASH_ON_BOOT FORCE_CRASH #endif - if (IO_READ(DPC_PIPEBUSY_REG) == 0) { - gIsConsole = FALSE; - gBorderHeight = BORDER_HEIGHT_EMULATOR; - gIsVC = IS_VC(); - } else { - gIsConsole = TRUE; - gBorderHeight = BORDER_HEIGHT_CONSOLE; - } - gGfxPool = &gGfxPools[0]; set_segment_base_addr(SEGMENT_RENDER, gGfxPool->buffer); gGfxSPTask = &gGfxPool->spTask; From 056e3191050b12563d9b67d670c4722ecbcd178e Mon Sep 17 00:00:00 2001 From: gheskett Date: Sat, 26 Feb 2022 01:56:07 -0500 Subject: [PATCH 3/9] Some formatting changes :( (But also some safeguards and updated documentation) --- include/config/config_audio.h | 24 ++++++++++++++++-------- include/config/config_safeguards.h | 7 +++++++ src/audio/data.c | 4 ++-- src/audio/data.h | 9 ++++----- src/audio/heap.c | 13 ++++++------- src/audio/synthesis.c | 4 ++-- src/audio/synthesis.h | 2 +- src/game/puppyprint.c | 2 +- src/game/puppyprint.h | 2 +- 9 files changed, 40 insertions(+), 27 deletions(-) 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 From 8f2b9c89796b9a96eb2ed67f7b9c847a6f6dfbff Mon Sep 17 00:00:00 2001 From: gheskett Date: Sat, 26 Feb 2022 02:52:40 -0500 Subject: [PATCH 4/9] Pointless memory allocation --- include/config/config_audio.h | 6 +++--- src/audio/data.h | 6 +++--- src/audio/heap.c | 2 +- src/game/puppyprint.c | 14 +++++++------- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/include/config/config_audio.h b/include/config/config_audio.h index 5111911b..332e09b3 100644 --- a/include/config/config_audio.h +++ b/include/config/config_audio.h @@ -10,7 +10,7 @@ #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 larger/more custom sequences/banks/sfx to be imported without causing issues (not supported for SH). */ #define EXPAND_AUDIO_HEAP @@ -21,10 +21,10 @@ * 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 +#define MAX_SIMULTANEOUS_NOTES_CONSOLE 24 /** * 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 +// #define BETTER_REVERB diff --git a/src/audio/data.h b/src/audio/data.h index 826ae059..d0395357 100644 --- a/src/audio/data.h +++ b/src/audio/data.h @@ -141,7 +141,7 @@ extern u32 gAudioRandom; #ifdef EXPAND_AUDIO_HEAP #if defined(VERSION_US) || defined(VERSION_JP) || defined(VERSION_EU) -#define EXT_AUDIO_INIT_POOL_SIZE (0x1800 + 0x300) +#define EXT_AUDIO_INIT_POOL_SIZE (0x2000 + 0x300) #define EXT_AUDIO_HEAP_SIZE 0x14D80 #else // SH not yet supported for expanded audio heap @@ -179,9 +179,9 @@ extern OSMesgQueue *D_SH_80350FA8; #endif #if defined(VERSION_EU) || defined(VERSION_SH) -#define AUDIO_INIT_POOL_SIZE (0x1B00 + EXT_AUDIO_INIT_POOL_SIZE + ALIGN16(MAX_SIMULTANEOUS_NOTES * sizeof(struct Note))) +#define AUDIO_INIT_POOL_SIZE (0x2C00 + EXT_AUDIO_INIT_POOL_SIZE) #else -#define AUDIO_INIT_POOL_SIZE (0x1600 + EXT_AUDIO_INIT_POOL_SIZE + ALIGN16(MAX_SIMULTANEOUS_NOTES * sizeof(struct Note))) +#define AUDIO_INIT_POOL_SIZE (0x2500 + EXT_AUDIO_INIT_POOL_SIZE) #endif // TODO: needs validation once EU can compile. EU is very likely incorrect! diff --git a/src/audio/heap.c b/src/audio/heap.c index b94d65ed..3660ce5d 100644 --- a/src/audio/heap.c +++ b/src/audio/heap.c @@ -307,8 +307,8 @@ void puppyprint_get_allocated_pools(s32 *audioPoolList) { &gAudioInitPool, &gNotesAndBuffersPool, &gSeqLoadedPool.persistent.pool, - &gSeqLoadedPool.temporary.pool, &gBankLoadedPool.persistent.pool, + &gSeqLoadedPool.temporary.pool, &gBankLoadedPool.temporary.pool, #ifdef BETTER_REVERB &gBetterReverbPool, diff --git a/src/game/puppyprint.c b/src/game/puppyprint.c index 2b1a64cc..a30f9123 100644 --- a/src/game/puppyprint.c +++ b/src/game/puppyprint.c @@ -310,14 +310,14 @@ void print_ram_overview(void) { } const char *audioPoolNames[NUM_AUDIO_POOLS] = { - "gAudioInitPool", - "gNotesAndBuffersPool", - "gSeqLoadedPool.persistent.pool", - "gSeqLoadedPool.temporary.pool", - "gBankLoadedPool.persistent.pool", - "gBankLoadedPool.temporary.pool", + "Audio Init Pool", + "Notes And Buffers Pool", + "Persistent Sequence Pool", + "Persistent Bank Pool", + "Temporary Sequence Pool", + "Temporary Bank Pool", #ifdef BETTER_REVERB - "gBetterReverbPool", + "Better Reverb Pool", #endif }; From f061076a4f15e3ac6df81d8e5d69a5f97a90f170 Mon Sep 17 00:00:00 2001 From: gheskett Date: Sat, 26 Feb 2022 03:01:08 -0500 Subject: [PATCH 5/9] Audio safeguard error --- include/config/config_safeguards.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/config/config_safeguards.h b/include/config/config_safeguards.h index 6971fe96..559dbc92 100644 --- a/include/config/config_safeguards.h +++ b/include/config/config_safeguards.h @@ -24,9 +24,9 @@ #ifndef MAX_SIMULTANEOUS_NOTES_CONSOLE #ifdef EXPAND_AUDIO_HEAP - #define MAX_SIMULTANEOUS_NOTES_EMULATOR 32 + #define MAX_SIMULTANEOUS_NOTES_CONSOLE 24 #else - #define MAX_SIMULTANEOUS_NOTES_EMULATOR 16 + #define MAX_SIMULTANEOUS_NOTES_CONSOLE 16 #endif #endif // MAX_SIMULTANEOUS_NOTES_CONSOLE From c4a23d0036eed0734da47bfc3ba03a884399e69b Mon Sep 17 00:00:00 2001 From: gheskett Date: Sun, 27 Feb 2022 00:20:52 -0500 Subject: [PATCH 6/9] Bugfix: the smaller MAX_SIMULTANEOUS_NOTES define, when used, can lead to silence on audio init --- src/audio/heap.c | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/audio/heap.c b/src/audio/heap.c index 3660ce5d..c6836c17 100644 --- a/src/audio/heap.c +++ b/src/audio/heap.c @@ -1313,6 +1313,16 @@ void audio_reset_session(void) { gAudioBufferParameters.minAiBufferLength *= gAudioBufferParameters.presetUnk4; gAudioBufferParameters.updatesPerFrame *= gAudioBufferParameters.presetUnk4; + if (gIsConsole) + gMaxSimultaneousNotes = MAX_SIMULTANEOUS_NOTES_CONSOLE; + else + gMaxSimultaneousNotes = MAX_SIMULTANEOUS_NOTES_EMULATOR; + + if (gMaxSimultaneousNotes > MAX_SIMULTANEOUS_NOTES) + gMaxSimultaneousNotes = MAX_SIMULTANEOUS_NOTES; + else if (gMaxSimultaneousNotes < 0) + gMaxSimultaneousNotes = 0; + #ifdef VERSION_SH if (gAudioBufferParameters.presetUnk4 >= 2) { gAudioBufferParameters.maxAiBufferLength -= 0x10; @@ -1330,6 +1340,16 @@ void audio_reset_session(void) { gMinAiBufferLength = gSamplesPerFrameTarget - 0x10; gAudioUpdatesPerFrame = updatesPerFrame = gSamplesPerFrameTarget / 160 + 1; + if (gIsConsole) + gMaxSimultaneousNotes = MAX_SIMULTANEOUS_NOTES_CONSOLE; + else + gMaxSimultaneousNotes = MAX_SIMULTANEOUS_NOTES_EMULATOR; + + if (gMaxSimultaneousNotes > MAX_SIMULTANEOUS_NOTES) + gMaxSimultaneousNotes = MAX_SIMULTANEOUS_NOTES; + else if (gMaxSimultaneousNotes < 0) + gMaxSimultaneousNotes = 0; + // Compute conversion ratio from the internal unit tatums/tick to the // external beats/minute (JP) or tatums/minute (US). In practice this is // 300 on JP and 14360 on US. @@ -1426,16 +1446,6 @@ void audio_reset_session(void) { #endif #endif - if (gIsConsole) - gMaxSimultaneousNotes = MAX_SIMULTANEOUS_NOTES_CONSOLE; - else - gMaxSimultaneousNotes = MAX_SIMULTANEOUS_NOTES_EMULATOR; - - if (gMaxSimultaneousNotes > MAX_SIMULTANEOUS_NOTES) - gMaxSimultaneousNotes = MAX_SIMULTANEOUS_NOTES; - else if (gMaxSimultaneousNotes < 0) - gMaxSimultaneousNotes = 0; - sAudioFirstBoot = 1; } From 448d18de2b179ac20b1aae72e115562c79f92705 Mon Sep 17 00:00:00 2001 From: gheskett Date: Tue, 8 Mar 2022 00:49:13 -0500 Subject: [PATCH 7/9] Bugfixes, sound bank heap defines, BETTER_REVERB improvements --- src/audio/data.c | 14 ++----------- src/audio/data.h | 40 +++++++++++++++++++------------------ src/audio/load.c | 9 ++------- src/audio/playback.c | 2 +- src/audio/seqplayer.c | 6 +++--- src/audio/synthesis.c | 46 +++++++++++++++---------------------------- src/audio/synthesis.h | 6 ++++-- 7 files changed, 49 insertions(+), 74 deletions(-) diff --git a/src/audio/data.c b/src/audio/data.c index d536a227..bfe942ce 100644 --- a/src/audio/data.c +++ b/src/audio/data.c @@ -37,11 +37,7 @@ struct ReverbSettingsEU sReverbSettings[8] = { */ struct AudioSessionSettingsEU gAudioSessionPresets[] = { -#ifdef EXPAND_AUDIO_HEAP - { /*1*/ 32000,/*2*/ 1,/*3*/ MAX_SIMULTANEOUS_NOTES,/*4*/ 1,/*5*/ 0, &sReverbSettings[0],/*6*/ 0x7FFF,/*7*/ 0,/*8*/ 0x8200,/*9*/ 0xDC00,/*10*/ 0xE800,/*11*/ 0x5500 }, -#else - { /*1*/ 32000,/*2*/ 1,/*3*/ MAX_SIMULTANEOUS_NOTES,/*4*/ 1,/*5*/ 0, &sReverbSettings[0],/*6*/ 0x7FFF,/*7*/ 0,/*8*/ 0x4100,/*9*/ 0x6E00,/*10*/ 0x7400,/*11*/ 0x2A80 }, -#endif + { /*1*/ 32000,/*2*/ 1,/*3*/ MAX_SIMULTANEOUS_NOTES,/*4*/ 1,/*5*/ 0, &sReverbSettings[0],/*6*/ 0x7FFF,/*7*/ 0,/*8*/ PERSISTENT_SEQ_MEM,/*9*/ PERSISTENT_BANK_MEM,/*10*/ TEMPORARY_SEQ_MEM,/*11*/ TEMPORARY_BANK_MEM }, }; #endif @@ -80,15 +76,9 @@ struct ReverbSettingsUS gReverbSettings[18] = { { 1, 0x0800, 0x2FFF }, }; -#ifdef EXPAND_AUDIO_HEAP struct AudioSessionSettings gAudioSessionPresets[1] = { - { 32000, MAX_SIMULTANEOUS_NOTES, 1, 0x1000, 0x2FFF, 0x7FFF, 0x8200, 0xDC00, 0xE800, 0x5500 }, + { 32000, MAX_SIMULTANEOUS_NOTES, 1, 0x1000, 0x2FFF, 0x7FFF, PERSISTENT_SEQ_MEM, PERSISTENT_BANK_MEM, TEMPORARY_SEQ_MEM, TEMPORARY_BANK_MEM }, }; -#else -struct AudioSessionSettings gAudioSessionPresets[1] = { - { 32000, MAX_SIMULTANEOUS_NOTES, 1, 0x1000, 0x2FFF, 0x7FFF, 0x4100, 0x6E00, 0x7400, 0x2A80 }, -}; -#endif #endif // gAudioCosineTable[k] = round((2**15 - 1) * cos(pi/2 * k / 127)). Unused. #if defined(VERSION_JP) || defined(VERSION_US) diff --git a/src/audio/data.h b/src/audio/data.h index d0395357..b6b42777 100644 --- a/src/audio/data.h +++ b/src/audio/data.h @@ -21,6 +21,24 @@ #define DMA_BUF_SIZE_1 (160 * 9) #endif +#ifdef EXPAND_AUDIO_HEAP +#define PERSISTENT_SEQ_MEM 0x8200 +#define PERSISTENT_BANK_MEM 0xDC00 +#define TEMPORARY_SEQ_MEM 0xE800 +#define TEMPORARY_BANK_MEM 0x5500 +#define BANK_SETS_ALLOC 0x400 +#define EXT_AUDIO_INIT_POOL_SIZE 0x2000 +#else +#define PERSISTENT_SEQ_MEM 0x4100 +#define PERSISTENT_BANK_MEM 0x6E00 +#define TEMPORARY_SEQ_MEM 0x7400 +#define TEMPORARY_BANK_MEM 0x2A80 +#define BANK_SETS_ALLOC 0x100 +#define EXT_AUDIO_INIT_POOL_SIZE 0x0 +#endif + +#define SEQ_BANK_MEM (PERSISTENT_SEQ_MEM + PERSISTENT_BANK_MEM + TEMPORARY_SEQ_MEM + TEMPORARY_BANK_MEM) + // constant .data #if defined(VERSION_EU) || defined(VERSION_SH) extern struct AudioSessionSettingsEU gAudioSessionPresets[]; @@ -139,20 +157,6 @@ extern u32 gAudioRandom; ) #endif -#ifdef EXPAND_AUDIO_HEAP -#if defined(VERSION_US) || defined(VERSION_JP) || defined(VERSION_EU) -#define EXT_AUDIO_INIT_POOL_SIZE (0x2000 + 0x300) -#define EXT_AUDIO_HEAP_SIZE 0x14D80 -#else -// SH not yet supported for expanded audio heap -#define EXT_AUDIO_INIT_POOL_SIZE 0x0 -#define EXT_AUDIO_HEAP_SIZE 0x0 -#endif -#else -#define EXT_AUDIO_INIT_POOL_SIZE 0x0 -#define EXT_AUDIO_HEAP_SIZE 0x0 -#endif - #ifdef VERSION_SH extern f32 unk_sh_data_1[]; @@ -179,15 +183,13 @@ extern OSMesgQueue *D_SH_80350FA8; #endif #if defined(VERSION_EU) || defined(VERSION_SH) -#define AUDIO_INIT_POOL_SIZE (0x2C00 + EXT_AUDIO_INIT_POOL_SIZE) +#define AUDIO_INIT_POOL_SIZE (0x2C00 + BANK_SETS_ALLOC + EXT_AUDIO_INIT_POOL_SIZE) #else -#define AUDIO_INIT_POOL_SIZE (0x2500 + EXT_AUDIO_INIT_POOL_SIZE) +#define AUDIO_INIT_POOL_SIZE (0x2500 + BANK_SETS_ALLOC + EXT_AUDIO_INIT_POOL_SIZE) #endif // TODO: needs validation once EU can compile. EU is very likely incorrect! -#define AUDIO_HEAP_BASE (0x14D80 /* sound bank space */ + AUDIO_INIT_POOL_SIZE + EXT_AUDIO_HEAP_SIZE + NOTES_BUFFER_SIZE) - -#define AUDIO_HEAP_SIZE (AUDIO_HEAP_BASE + BETTER_REVERB_SIZE + REVERB_WINDOW_HEAP_SIZE) +#define AUDIO_HEAP_SIZE (SEQ_BANK_MEM + AUDIO_INIT_POOL_SIZE + NOTES_BUFFER_SIZE + BETTER_REVERB_SIZE + REVERB_WINDOW_HEAP_SIZE) #ifdef VERSION_SH extern u32 D_SH_80315EF0; diff --git a/src/audio/load.c b/src/audio/load.c index d2003701..79ee38f1 100644 --- a/src/audio/load.c +++ b/src/audio/load.c @@ -983,13 +983,8 @@ void audio_init() { alSeqFileNew(gAlTbl, gSoundDataRaw); // Load bank sets for each sequence -#ifdef EXPAND_AUDIO_HEAP - gAlBankSets = soundAlloc(&gAudioInitPool, 0x400); - audio_dma_copy_immediate((uintptr_t) gBankSetsData, gAlBankSets, 0x400); -#else - gAlBankSets = soundAlloc(&gAudioInitPool, 0x100); - audio_dma_copy_immediate((uintptr_t) gBankSetsData, gAlBankSets, 0x100); -#endif + gAlBankSets = soundAlloc(&gAudioInitPool, BANK_SETS_ALLOC); + audio_dma_copy_immediate((uintptr_t) gBankSetsData, gAlBankSets, BANK_SETS_ALLOC); init_sequence_players(); gAudioLoadLock = AUDIO_LOCK_NOT_LOADING; diff --git a/src/audio/playback.c b/src/audio/playback.c index 9a29f8c4..efa8aa08 100644 --- a/src/audio/playback.c +++ b/src/audio/playback.c @@ -1448,4 +1448,4 @@ void note_init_all(void) { note->synthesisBuffers = soundAlloc(&gNotesAndBuffersPool, ALIGN16(sizeof(struct NoteSynthesisBuffers))); #endif } -} \ No newline at end of file +} diff --git a/src/audio/seqplayer.c b/src/audio/seqplayer.c index 6628da32..8b5b917b 100644 --- a/src/audio/seqplayer.c +++ b/src/audio/seqplayer.c @@ -2517,10 +2517,10 @@ void sequence_player_process_sequence(struct SequencePlayer *seqPlayer) { break; case 0xda: // seq_changevol - temp = (f32)(s8) m64_read_u8(state) / 127.0f; - seqPlayer->fadeVolume += temp; + temp = m64_read_u8(state); + seqPlayer->fadeVolume += (f32)(s8) temp / 127.0f; - seqPlayer->volumeDefault += temp; + seqPlayer->volumeDefault += (f32)(s8) temp / 127.0f; if (seqPlayer->volumeDefault > 1.0f) seqPlayer->volumeDefault = 1.0f; else if (seqPlayer->volumeDefault < 0.0f) diff --git a/src/audio/synthesis.c b/src/audio/synthesis.c index 0f5f5315..7800ca81 100644 --- a/src/audio/synthesis.c +++ b/src/audio/synthesis.c @@ -61,6 +61,7 @@ * * This is also known to cause severe lag on emulators that have counter factor set to 2 or greater. * Be sure either you alert the user in advance, or check for and set betterReverbDownsampleEmulator to -1 if it's detected the user isn't using good settings. + * Reducing performance heavy parameters or using RCVI hack may be another working solution to this problem. */ @@ -80,28 +81,28 @@ s8 betterReverbDownsampleEmulator = 2; // This value represents the number of filters to use with the reverb. This can be decreased to improve performance, but at the cost of a lesser presence of reverb in the final audio. // Filter count should always be a multiple of 3. Never ever set this value to be greater than NUM_ALLPASS. // Setting it to anything less than 3 will disable reverb outright. -// This can be changed at any time, but is best set when calling audio_reset_session. +// This can be changed at any time, but is best set immediately before calling audio_reset_session. u32 reverbFilterCountConsole = (NUM_ALLPASS - 6); // This value represents the number of filters to use with the reverb. This can be decreased to improve performance, but at the cost of a lesser presence of reverb in the final audio. // Filter count should always be a multiple of 3. Never ever set this value to be greater than NUM_ALLPASS. // Setting it to anything less than 3 will disable reverb outright. -// This can be changed at any time, but is best set when calling audio_reset_session. +// This can be changed at any time, but is best set immediately before calling audio_reset_session. u32 reverbFilterCountEmulator = NUM_ALLPASS; // Set this to TRUE to use mono over stereo for reverb. This should increase performance, but at the cost of a less fullfilling reverb experience. // If performance is desirable, it is recommended to change reverbFilterCountConsole or betterReverbDownsampleConsole first. -// This can be changed at any time, but is best set when calling audio_reset_session. +// This can be changed at any time, but is best set immediately before calling audio_reset_session. u8 monoReverbConsole = FALSE; // Set this to TRUE to use mono over stereo for reverb. This should increase performance, but at the cost of a less fullfilling reverb experience. // If performance is desirable, it is recommended to change reverbFilterCountEmulator or betterReverbDownsampleEmulator first. -// This can be changed at any time, but is best set when calling audio_reset_session. +// This can be changed at any time, but is best set immediately before calling audio_reset_session. u8 monoReverbEmulator = FALSE; // This value controls the size of the reverb buffer. It affects the global reverb delay time. This variable is one of the easiest to control. -// It is not recommended setting this to values greater than 0x1000 * 2^(downsample factor - 1), as you run the risk of running into a memory issue (though this is far from a guarantee). // Setting the value lower than the downsample buffer size will destroy the game audio. This is taken into account automatically, but also means the value set here isn't what always gets used. +// Similarly, this value maxes out at (REVERB_WINDOW_SIZE_MAX * 2^(downsample factor - 1)). // If this value is changed, it will go into effect the next time audio_reset_session is called. // Set to -1 to use a default preset instead. Higher values represent more audio delay (usually better for echoey spaces). s32 betterReverbWindowsSize = -1; @@ -120,32 +121,15 @@ s32 betterReverbWindowsSize = -1; // These values affect filter delays. Bigger values will result in fatter echo (and more memory); must be cumulatively smaller than BETTER_REVERB_SIZE/2. // If setting a reverb downsample value to 1, these must be cumulatively smaller than BETTER_REVERB_SIZE/4. -// These values should never be changed unless in this declaration or during a call to audio_reset_session, as it could otherwise lead to a major memory leak or garbage audio. -// None of the delay values should ever be smaller than 1 either; these are s32s purely to avoid typecasts. -// These values are currently set by using delaysBaseline in the audio_reset_session function, so its behavior must be overridden to use dynamically (or at all). -s32 delaysL[NUM_ALLPASS] = { +// None of the delay values should ever be smaller than 1; these are s32s purely to avoid typecasts. +// These values are applied any time audio_reset_session is called, and as such can be changed at any time without issues. +s32 delaysBaselineL[NUM_ALLPASS] = { 1080, 1352, 1200, 1200, 1232, 1432, 1384, 1048, 1352, 928, 1504, 1512 }; -s32 delaysR[NUM_ALLPASS] = { - 1384, 1352, 1048, - 928, 1512, 1504, - 1080, 1200, 1352, - 1200, 1432, 1232 -}; - -// Like the delays array, but represents default max values that don't change (also probably somewhat redundant) -// Change this array rather than the delays array to customize reverb delay times globally. -// Similarly to delaysL/R, these should be kept within the memory constraints defined by BETTER_REVERB_SIZE. -const s32 delaysBaselineL[NUM_ALLPASS] = { - 1080, 1352, 1200, - 1200, 1232, 1432, - 1384, 1048, 1352, - 928, 1504, 1512 -}; -const s32 delaysBaselineR[NUM_ALLPASS] = { +s32 delaysBaselineR[NUM_ALLPASS] = { 1384, 1352, 1048, 928, 1512, 1504, 1080, 1200, 1352, @@ -164,10 +148,12 @@ s32 reverbFilterCount = NUM_ALLPASS; s32 reverbFilterCountm1 = (NUM_ALLPASS - 1); u8 monoReverb = FALSE; u8 toggleBetterReverb = TRUE; -s32 allpassIdxL[NUM_ALLPASS] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; -s32 allpassIdxR[NUM_ALLPASS] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; -s32 tmpBufL[NUM_ALLPASS] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; -s32 tmpBufR[NUM_ALLPASS] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; +s32 allpassIdxL[NUM_ALLPASS] = {0}; +s32 allpassIdxR[NUM_ALLPASS] = {0}; +s32 tmpBufL[NUM_ALLPASS] = {0}; +s32 tmpBufR[NUM_ALLPASS] = {0}; +s32 delaysL[NUM_ALLPASS] = {0}; +s32 delaysR[NUM_ALLPASS] = {0}; s32 **delayBufsL; s32 **delayBufsR; #endif diff --git a/src/audio/synthesis.h b/src/audio/synthesis.h index 1adaa6d9..54403016 100644 --- a/src/audio/synthesis.h +++ b/src/audio/synthesis.h @@ -39,8 +39,8 @@ extern u8 monoReverbConsole; extern u8 monoReverbEmulator; extern s32 betterReverbWindowsSize; -extern const s32 delaysBaselineL[NUM_ALLPASS]; -extern const s32 delaysBaselineR[NUM_ALLPASS]; +extern s32 delaysBaselineL[NUM_ALLPASS]; +extern s32 delaysBaselineR[NUM_ALLPASS]; extern s32 delaysL[NUM_ALLPASS]; extern s32 delaysR[NUM_ALLPASS]; extern s32 reverbMultsL[NUM_ALLPASS / 3]; @@ -51,6 +51,8 @@ extern s32 **delayBufsR; extern u8 toggleBetterReverb; #define REVERB_WINDOW_SIZE_MAX 0x2000 +STATIC_ASSERT(NUM_ALLPASS % 3 == 0, "NUM_ALLPASS must be a multiple of 3!"); + #else #define BETTER_REVERB_SIZE 0 From 9f2f4a27b60c4f1a2482be3a657bb19b0f3a9326 Mon Sep 17 00:00:00 2001 From: gheskett Date: Tue, 8 Mar 2022 00:51:22 -0500 Subject: [PATCH 8/9] Whoops --- src/audio/data.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/audio/data.h b/src/audio/data.h index b6b42777..e4351788 100644 --- a/src/audio/data.h +++ b/src/audio/data.h @@ -183,9 +183,9 @@ extern OSMesgQueue *D_SH_80350FA8; #endif #if defined(VERSION_EU) || defined(VERSION_SH) -#define AUDIO_INIT_POOL_SIZE (0x2C00 + BANK_SETS_ALLOC + EXT_AUDIO_INIT_POOL_SIZE) +#define AUDIO_INIT_POOL_SIZE (0x2B00 + BANK_SETS_ALLOC + EXT_AUDIO_INIT_POOL_SIZE) #else -#define AUDIO_INIT_POOL_SIZE (0x2500 + BANK_SETS_ALLOC + EXT_AUDIO_INIT_POOL_SIZE) +#define AUDIO_INIT_POOL_SIZE (0x2400 + BANK_SETS_ALLOC + EXT_AUDIO_INIT_POOL_SIZE) #endif // TODO: needs validation once EU can compile. EU is very likely incorrect! From 8163bc48375873dcb27631dd51511edfe9075e36 Mon Sep 17 00:00:00 2001 From: gheskett Date: Tue, 8 Mar 2022 01:03:54 -0500 Subject: [PATCH 9/9] sAudioFirstBoot renamed to sAudioIsInitialized --- src/audio/heap.c | 20 ++++++++++---------- src/audio/load.h | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/audio/heap.c b/src/audio/heap.c index c6836c17..573b3d4e 100644 --- a/src/audio/heap.c +++ b/src/audio/heap.c @@ -985,7 +985,7 @@ void wait_for_audio_frames(s32 frames) { } #endif -u8 sAudioFirstBoot = 0; +u8 sAudioIsInitialized = FALSE; // Separate the reverb settings into their own func. Bit unstable currently, so still only runs at boot. #if defined(VERSION_EU) || defined(VERSION_SH) void init_reverb_eu(void) { @@ -1000,7 +1000,7 @@ void init_reverb_eu(void) { gSynthesisReverbs[j].useReverb = 0; // Both left and right channels are allocated/cleared together, then separated based on the reverb window size - if (!sAudioFirstBoot) { + if (!sAudioIsInitialized) { gSynthesisReverbs[j].ringBuffer.left = soundAlloc(&gNotesAndBuffersPool, REVERB_WINDOW_SIZE_MAX * 4); } } @@ -1015,7 +1015,7 @@ void init_reverb_eu(void) { if (reverb->windowSize > REVERB_WINDOW_SIZE_MAX) { reverb->windowSize = REVERB_WINDOW_SIZE_MAX; } - if (sAudioFirstBoot) { + if (sAudioIsInitialized) { bzero(reverb->ringBuffer.left, (REVERB_WINDOW_SIZE_MAX * 4)); } else { reverb->resampleRate = (0x8000 / reverb->downsampleRate); @@ -1041,7 +1041,7 @@ void init_reverb_eu(void) { reverb->framesLeftToIgnore = 2; if (reverb->downsampleRate != 1) { reverb->resampleRate = (0x8000 / reverb->downsampleRate); - if (sAudioFirstBoot) { + if (sAudioIsInitialized) { bzero(reverb->resampleStateLeft, (16 * sizeof(s16))); bzero(reverb->resampleStateRight, (16 * sizeof(s16))); bzero(reverb->unk24, (16 * sizeof(s16))); @@ -1096,7 +1096,7 @@ void init_reverb_us(s32 presetId) { reverbWindowSize = REVERB_WINDOW_SIZE_MAX; } // Both left and right channels are allocated/cleared together, then separated based on the reverb window size - if (!sAudioFirstBoot) { + if (!sAudioIsInitialized) { gSynthesisReverb.ringBuffer.left = soundAlloc(&gNotesAndBuffersPool, REVERB_WINDOW_SIZE_MAX * 2 * sizeof(s16)); gSynthesisReverb.resampleStateLeft = soundAlloc(&gNotesAndBuffersPool, (16 * sizeof(s16))); @@ -1130,7 +1130,7 @@ void init_reverb_us(s32 presetId) { if (gReverbDownsampleRate != 1) { gSynthesisReverb.resampleFlags = A_INIT; gSynthesisReverb.resampleRate = (0x8000 / gReverbDownsampleRate); - if (sAudioFirstBoot) { + if (sAudioIsInitialized) { bzero(gSynthesisReverb.resampleStateLeft, (16 * sizeof(s16))); bzero(gSynthesisReverb.resampleStateRight, (16 * sizeof(s16))); bzero(gSynthesisReverb.unk24, (16 * sizeof(s16))); @@ -1145,7 +1145,7 @@ void init_reverb_us(s32 presetId) { // However, reseting this allows for proper clearing of the reverb buffers, as well as dynamic customization of the delays array. #ifdef BETTER_REVERB if (toggleBetterReverb) { - if (sAudioFirstBoot) { + if (sAudioIsInitialized) { bzero(delayBufsL[0], (BETTER_REVERB_SIZE - BETTER_REVERB_PTR_SIZE)); } @@ -1166,7 +1166,7 @@ void init_reverb_us(s32 presetId) { #if defined(VERSION_JP) || defined(VERSION_US) void audio_reset_session(struct AudioSessionSettings *preset, s32 presetId) { - if (sAudioFirstBoot) { + if (sAudioIsInitialized) { bzero(&gAiBuffers[0][0], (AIBUFFER_LEN * NUMAIBUFFERS)); persistent_pool_clear(&gSeqLoadedPool.persistent); persistent_pool_clear(&gBankLoadedPool.persistent); @@ -1187,7 +1187,7 @@ void audio_reset_session(struct AudioSessionSettings *preset, s32 presetId) { } #else void audio_reset_session(void) { - if (sAudioFirstBoot) { + if (sAudioIsInitialized) { persistent_pool_clear(&gSeqLoadedPool.persistent); persistent_pool_clear(&gBankLoadedPool.persistent); temporary_pool_clear(&gSeqLoadedPool.temporary); @@ -1446,7 +1446,7 @@ void audio_reset_session(void) { #endif #endif - sAudioFirstBoot = 1; + sAudioIsInitialized = TRUE; } #ifdef VERSION_SH diff --git a/src/audio/load.h b/src/audio/load.h index 4dcc24f5..12b6ed6c 100644 --- a/src/audio/load.h +++ b/src/audio/load.h @@ -16,7 +16,7 @@ enum Preloads { #define IS_SEQUENCE_CHANNEL_VALID(ptr) ((uintptr_t)(ptr) != (uintptr_t)&gSequenceChannelNone) extern struct Note *gNotes; -extern u8 sAudioFirstBoot; +extern u8 sAudioIsInitialized; // Music in SM64 is played using 3 players: // gSequencePlayers[0] is level background music