diff --git a/src/audio/external.h b/src/audio/external.h index 8265cde4..8417ecbf 100644 --- a/src/audio/external.h +++ b/src/audio/external.h @@ -13,9 +13,11 @@ enum SoundModes { SOUND_MODE_STEREO, - SOUND_MODE_HEADSET, - SOUND_MODE_UNUSED, SOUND_MODE_MONO, +#ifdef ENABLE_STEREO_HEADSET_EFFECTS + SOUND_MODE_HEADSET, +#endif + SOUND_MODE_COUNT, }; enum SequencePlayers { diff --git a/src/game/save_file.c b/src/game/save_file.c index 9c01abb8..bb9eed9c 100644 --- a/src/game/save_file.c +++ b/src/game/save_file.c @@ -3,6 +3,7 @@ #include "sm64.h" #include "game_init.h" #include "main.h" +#include "audio/external.h" #include "engine/math_util.h" #include "area.h" #include "level_update.h" @@ -717,6 +718,10 @@ void save_file_set_widescreen_mode(u8 mode) { #endif u32 save_file_get_sound_mode(void) { + if (gSaveBuffer.menuData.soundMode >= SOUND_MODE_COUNT) { + return 0; + } + return gSaveBuffer.menuData.soundMode; } diff --git a/src/game/sound_init.c b/src/game/sound_init.c index 4d79c72b..fe60afcb 100644 --- a/src/game/sound_init.c +++ b/src/game/sound_init.c @@ -36,11 +36,6 @@ static u16 sCurrentCapMusic = MUSIC_NONE; #ifdef ENABLE_VANILLA_LEVEL_SPECIFIC_CHECKS static u8 sPlayingInfiniteStairs = FALSE; #endif -#ifdef ENABLE_STEREO_HEADSET_EFFECTS -static s16 sSoundMenuModeToSoundMode[3] = { SOUND_MODE_STEREO, SOUND_MODE_MONO, SOUND_MODE_HEADSET }; -#else -static s16 sSoundMenuModeToSoundMode[2] = { SOUND_MODE_STEREO, SOUND_MODE_MONO }; -#endif // Only the 20th array element is used. static u32 sMenuSoundsExtra[] = { SOUND_MOVING_TERRAIN_SLIDE + (0 << 16), @@ -147,8 +142,8 @@ void enable_background_sound(void) { * Called from threads: thread5_game_loop */ void set_sound_mode(u16 soundMode) { - if (soundMode < ARRAY_COUNT(sSoundMenuModeToSoundMode)) { - gSoundMode = sSoundMenuModeToSoundMode[soundMode]; + if (soundMode < SOUND_MODE_COUNT) { + gSoundMode = soundMode; } } diff --git a/src/game/sound_init.h b/src/game/sound_init.h index 26c59e84..0681c2d5 100644 --- a/src/game/sound_init.h +++ b/src/game/sound_init.h @@ -17,12 +17,6 @@ enum SoundMenuFlags { SOUND_MENU_FLAG_EXTRA = (1 << 8), // 0x100 }; -enum SoundMenuMode { - SOUND_MENU_MODE_STEREO, - SOUND_MENU_MODE_MONO, - SOUND_MENU_MODE_HEADSET -}; - void reset_volume(void); void raise_background_noise(s32 a); void lower_background_noise(s32 a); diff --git a/src/menu/file_select.c b/src/menu/file_select.c index ce205042..751e9c95 100644 --- a/src/menu/file_select.c +++ b/src/menu/file_select.c @@ -87,11 +87,10 @@ u8 sTextFadeAlpha = 0; // and when you click yes/no in the erase confirmation prompt. s16 sMainMenuTimer = 0; -// Sound mode menu buttonID, has different values compared to gSoundMode in audio. -// 0: gSoundMode = 0 (Stereo) | 1: gSoundMode = 3 (Mono) | 2: gSoundMode = 1 (Headset) +// Sound mode menu buttonID s8 sSoundMode = 0; -// Active language for EU arrays, values defined similar to sSoundMode +// Active language for EU arrays // 0: English | 1: French | 2: German // Tracks which button will be pressed in the erase confirmation prompt (yes/no). @@ -836,7 +835,7 @@ void render_sound_mode_menu_buttons(struct Object *soundModeButton) { sMainMenuButtons[MENU_BUTTON_LANGUAGE_RETURN]->oMenuButtonScale = MENU_BUTTON_SCALE; #else // Zoom in current selection - sMainMenuButtons[MENU_BUTTON_OPTION_MIN + sSoundMode]->oMenuButtonState = MENU_BUTTON_STATE_ZOOM_IN; + sMainMenuButtons[MENU_BUTTON_SOUND_OPTION_MIN + sSoundMode]->oMenuButtonState = MENU_BUTTON_STATE_ZOOM_IN; #endif } @@ -856,12 +855,7 @@ void check_sound_mode_menu_clicked_buttons(struct Object *soundModeButton) { if (check_clicked_button(buttonX, buttonY, 22.0f) == TRUE) { // If sound mode button clicked, select it and define sound mode // The check will always be true because of the group configured above (In JP & US) -#ifdef ENABLE_STEREO_HEADSET_EFFECTS - if (buttonID == MENU_BUTTON_STEREO || buttonID == MENU_BUTTON_MONO - || buttonID == MENU_BUTTON_HEADSET) { -#else - if (buttonID == MENU_BUTTON_STEREO || buttonID == MENU_BUTTON_MONO) { -#endif + if (buttonID >= MENU_BUTTON_SOUND_OPTION_MIN && buttonID < MENU_BUTTON_SOUND_OPTION_MAX) { if (soundModeButton->oMenuButtonActionPhase == SOUND_MODE_PHASE_MAIN) { play_sound(SOUND_MENU_CLICK_FILE_SELECT, gGlobalSoundSource); #if ENABLE_RUMBLE @@ -873,7 +867,7 @@ void check_sound_mode_menu_clicked_buttons(struct Object *soundModeButton) { // because they don't have a case in bhv_menu_button_manager_loop sSelectedButtonID = buttonID; #endif - sSoundMode = buttonID - MENU_BUTTON_OPTION_MIN; + sSoundMode = buttonID - MENU_BUTTON_SOUND_OPTION_MIN; save_file_set_sound_mode(sSoundMode); } } @@ -2062,3 +2056,5 @@ s32 lvl_update_obj_and_load_file_selected(UNUSED s32 arg, UNUSED s32 unused) { area_update_objects(); return sSelectedFileNum; } + +STATIC_ASSERT(SOUND_MODE_COUNT == MENU_BUTTON_SOUND_OPTION_MAX - MENU_BUTTON_SOUND_OPTION_MIN, "Mismatch between number of sound modes in audio code and file select!"); diff --git a/src/menu/file_select.h b/src/menu/file_select.h index b6ad1e4c..51966231 100644 --- a/src/menu/file_select.h +++ b/src/menu/file_select.h @@ -79,22 +79,26 @@ enum MenuButtonTypes { // This menu includes language settings on EU MENU_BUTTON_SOUND_MODE = MENU_BUTTON_ERASE_MAX, MENU_BUTTON_OPTION_MIN, - MENU_BUTTON_STEREO = MENU_BUTTON_OPTION_MIN, + MENU_BUTTON_SOUND_OPTION_MIN = MENU_BUTTON_OPTION_MIN, + MENU_BUTTON_STEREO = MENU_BUTTON_SOUND_OPTION_MIN, MENU_BUTTON_MONO, #ifdef ENABLE_STEREO_HEADSET_EFFECTS MENU_BUTTON_HEADSET, #endif + MENU_BUTTON_SOUND_OPTION_MAX, #if MULTILANG // Language Menu - MENU_BUTTON_LANGUAGE_MIN, + MENU_BUTTON_LANGUAGE_MIN = MENU_BUTTON_SOUND_OPTION_MAX, MENU_BUTTON_LANGUAGE_ENGLISH = MENU_BUTTON_LANGUAGE_MIN, MENU_BUTTON_LANGUAGE_FRENCH, MENU_BUTTON_LANGUAGE_GERMAN, MENU_BUTTON_LANGUAGE_RETURN, -#endif MENU_BUTTON_OPTION_MAX +#else + MENU_BUTTON_OPTION_MAX = MENU_BUTTON_SOUND_OPTION_MAX +#endif }; enum ScoreMenuMessageID {