From f501bfaefbcbf5c9d27117d3a608d43481e00e7c Mon Sep 17 00:00:00 2001 From: damiencarol Date: Mon, 4 Mar 2024 07:52:05 +0100 Subject: [PATCH 01/24] Enable sound only on OpenAL --- src/engine/audio/defines.cpp | 4 ++- src/engine/audio/music.cpp | 3 ++ src/engine/audio/sound.cpp | 58 +++++++++------------------------ src/engine/audio/sound.hpp | 50 ++++++++++++++++++++++++++-- src/engine/audio/sound_game.cpp | 37 ++++++++++++++++----- src/init_game.cpp | 5 +++ src/mod_tools.cpp | 8 ++--- src/ui/MainMenu.cpp | 30 ++++++++++------- 8 files changed, 126 insertions(+), 69 deletions(-) diff --git a/src/engine/audio/defines.cpp b/src/engine/audio/defines.cpp index 56b41a71c..b6bdd6f0f 100644 --- a/src/engine/audio/defines.cpp +++ b/src/engine/audio/defines.cpp @@ -78,4 +78,6 @@ bool sfxUseDynamicAmbientVolume = true; bool sfxUseDynamicEnvironmentVolume = true; void* fmod_extraDriverData = nullptr; -#endif //USE_FMOD +#elif defined OPENAL_ENABLED +OPENAL_BUFFER** intromusic = nullptr; +#endif diff --git a/src/engine/audio/music.cpp b/src/engine/audio/music.cpp index 3acd502df..ad10179ca 100644 --- a/src/engine/audio/music.cpp +++ b/src/engine/audio/music.cpp @@ -75,6 +75,9 @@ bool loadMusic() intromusic = (FMOD::Sound**)malloc(sizeof(FMOD::Sound*) * NUMINTROMUSIC); memset(intromusic, 0, sizeof(FMOD::Sound*) * NUMINTROMUSIC); } +#elif defined USE_OPENAL + // TODO: load intro music + #endif bool introMusicChanged; diff --git a/src/engine/audio/sound.cpp b/src/engine/audio/sound.cpp index b591c3b9c..32f88e4ae 100644 --- a/src/engine/audio/sound.cpp +++ b/src/engine/audio/sound.cpp @@ -29,18 +29,21 @@ #endif #endif + +void setGlobalVolume(real_t master, real_t music, real_t gameplay, real_t ambient, real_t environment, real_t notification) +{ #ifdef USE_FMOD #elif defined USE_OPENAL #else -void setGlobalVolume(real_t master, real_t music, real_t gameplay, real_t ambient, real_t environment, real_t notification) -{ - return; +#endif } void setAudioDevice(const std::string& device) { - return; -} +#ifdef USE_FMOD +#elif defined USE_OPENAL +#else #endif +} #ifdef USE_FMOD @@ -328,36 +331,6 @@ void sound_update(int player, int index, int numplayers) #elif defined USE_OPENAL -struct OPENAL_BUFFER { - ALuint id; - bool stream; - char oggfile[64]; -}; -struct OPENAL_SOUND { - ALuint id; - OPENAL_CHANNELGROUP *group; - float volume; - OPENAL_BUFFER *buffer; - bool active; - char* oggdata; - int oggdata_length; - int ogg_seekoffset; - OggVorbis_File oggStream; - vorbis_info* vorbisInfo; - vorbis_comment* vorbisComment; - ALuint streambuff[4]; - bool loop; - bool stream_active; - int indice; -}; - -struct OPENAL_CHANNELGROUP { - float volume; - int num; - int cap; - OPENAL_SOUND **sounds; -}; - SDL_mutex *openal_mutex; static size_t openal_oggread(void* ptr, size_t size, size_t nmemb, void* datasource) { @@ -513,14 +486,12 @@ ALCdevice *openal_device = nullptr; //#define openal_maxchannels 100 OPENAL_BUFFER** sounds = nullptr; -Uint32 numsounds = 0; OPENAL_BUFFER** minesmusic = NULL; OPENAL_BUFFER** swampmusic = NULL; OPENAL_BUFFER** labyrinthmusic = NULL; OPENAL_BUFFER** ruinsmusic = NULL; OPENAL_BUFFER** underworldmusic = NULL; OPENAL_BUFFER** hellmusic = NULL; -OPENAL_BUFFER** intromusic = NULL; OPENAL_BUFFER* intermissionmusic = NULL; OPENAL_BUFFER* minetownmusic = NULL; OPENAL_BUFFER* splashmusic = NULL; @@ -1266,7 +1237,7 @@ void physfsReloadMusic(bool &introMusicChanged, bool reloadAll) //TODO: This sho { return; } -#ifdef SOUND +#ifdef SOUNDsdfdsf std::vector themeMusic; themeMusic.push_back("music/introduction.ogg"); @@ -1714,13 +1685,13 @@ void physfsReloadMusic(bool &introMusicChanged, bool reloadAll) //TODO: This sho #endif // SOUND } +/** + * Free custom music slots, not used by official music assets. + */ void gamemodsUnloadCustomThemeMusic() { #ifdef SOUND -#ifdef USE_OPENAL -#define FMOD_Sound_Release OPENAL_Sound_Release -#endif - // free custom music slots, not used by official music assets. +#ifdef FMOD_ENABLED if ( gnomishminesmusic ) { gnomishminesmusic->release(); @@ -1751,8 +1722,9 @@ void gamemodsUnloadCustomThemeMusic() hamletmusic->release(); hamletmusic = nullptr; } +#endif #ifdef USE_OPENAL -#undef FMOD_Sound_Release + #endif #endif // !SOUND } diff --git a/src/engine/audio/sound.hpp b/src/engine/audio/sound.hpp index 80c00b332..1ce9e3411 100644 --- a/src/engine/audio/sound.hpp +++ b/src/engine/audio/sound.hpp @@ -27,6 +27,18 @@ #endif #endif +#ifdef USE_FMOD +#include "fmod_errors.h" +#elif defined USE_OPENAL +#ifdef USE_TREMOR +#include +#else +#include +#include +#include +#endif +#endif + extern Uint32 numsounds; bool initSoundEngine(); //If it fails to initialize the sound engine, it'll just disable audio. void exitSoundEngine(); @@ -127,7 +139,38 @@ extern bool sfxUseDynamicAmbientVolume, sfxUseDynamicEnvironmentVolume; #elif defined USE_OPENAL #define SOUND -#define MUSIC +//#definMUSIC + +struct OPENAL_BUFFER { + ALuint id; + bool stream; + char oggfile[64]; +}; +struct OPENAL_CHANNELGROUP; +struct OPENAL_SOUND { + ALuint id; + OPENAL_CHANNELGROUP *group; + float volume; + OPENAL_BUFFER *buffer; + bool active; + char* oggdata; + int oggdata_length; + int ogg_seekoffset; + OggVorbis_File oggStream; + vorbis_info* vorbisInfo; + vorbis_comment* vorbisComment; + ALuint streambuff[4]; + bool loop; + bool stream_active; + int indice; +}; + +struct OPENAL_CHANNELGROUP { + float volume; + int num; + int cap; + OPENAL_SOUND **sounds; +}; extern ALCcontext *openal_context; extern ALCdevice *openal_device; @@ -194,14 +237,17 @@ int closeOPENAL(); void sound_update(int player, int index, int numplayers); OPENAL_SOUND* playSoundPlayer(int player, Uint16 snd, Uint8 vol); +OPENAL_SOUND* playSoundNotificationPlayer(int player, Uint16 snd, Uint8 vol); //TODO: Write. OPENAL_SOUND* playSoundPos(real_t x, real_t y, Uint16 snd, Uint8 vol); OPENAL_SOUND* playSoundPosLocal(real_t x, real_t y, Uint16 snd, Uint8 vol); OPENAL_SOUND* playSoundEntity(Entity* entity, Uint16 snd, Uint8 vol); OPENAL_SOUND* playSoundEntityLocal(Entity* entity, Uint16 snd, Uint8 vol); OPENAL_SOUND* playSound(Uint16 snd, Uint8 vol); +OPENAL_SOUND* playSoundNotification(Uint16 snd, Uint8 vol); //TODO: Write. OPENAL_SOUND* playSoundVelocity(); //TODO: Write. -void playmusic(OPENAL_BUFFER* sound, bool loop, bool crossfade, bool resume); //Automatically crossfades. NOTE: Resets fadein and fadeout increments to the defaults every time it is called. You'll have to change the fadein and fadeout increments AFTER calling this function. +void stopMusic(); +void playMusic(OPENAL_BUFFER* sound, bool loop, bool crossfade, bool resume); //Automatically crossfades. NOTE: Resets fadein and fadeout increments to the defaults every time it is called. You'll have to change the fadein and fadeout increments AFTER calling this function. void handleLevelMusic(); //Manages and updates the level music. diff --git a/src/engine/audio/sound_game.cpp b/src/engine/audio/sound_game.cpp index 726e95fc0..b7ab22477 100644 --- a/src/engine/audio/sound_game.cpp +++ b/src/engine/audio/sound_game.cpp @@ -397,6 +397,17 @@ OPENAL_SOUND* playSoundPlayer(int player, Uint16 snd, Uint8 vol) return NULL; } +OPENAL_SOUND* playSoundNotificationPlayer(int player, Uint16 snd, Uint8 vol) +{ + if (no_sound) + { + return NULL; + } + + //TODO: Implement playSoundNotificationPlayer for OpenAL. + return NULL; +} + /*------------------------------------------------------------------------------- playSoundPos @@ -575,6 +586,16 @@ OPENAL_SOUND* playSound(Uint16 snd, Uint8 vol) return channel; } +OPENAL_SOUND* playSoundNotification(Uint16 snd, Uint8 vol) +{ + if (no_sound) + { + return NULL; + } + // TODO: Implement playSoundNotification for OpenAL + return NULL; +} + void playMusic(OPENAL_BUFFER* sound, bool loop, bool crossfade, bool resume) { if (no_sound) @@ -636,15 +657,15 @@ void playMusic(OPENAL_BUFFER* sound, bool loop, bool crossfade, bool resume) OPENAL_Channel_Play(music_channel); } -bool shopmusicplaying = false; -bool combatmusicplaying = false; -bool minotaurmusicplaying = false; -bool herxmusicplaying = false; -bool devilmusicplaying = false; -bool olddarkmap = false; -bool sanctummusicplaying = false; +extern bool shopmusicplaying; +extern bool combatmusicplaying; +extern bool minotaurmusicplaying; +extern bool herxmusicplaying; +extern bool devilmusicplaying; +extern bool olddarkmap; +extern bool sanctummusicplaying; -int currenttrack = -1; +extern int currenttrack; void handleLevelMusic() { diff --git a/src/init_game.cpp b/src/init_game.cpp index 5e8d0011c..5e39b5641 100644 --- a/src/init_game.cpp +++ b/src/init_game.cpp @@ -551,6 +551,7 @@ void deinitGame() #endif if ( !no_sound ) { +#ifdef USE_FMOD music_channel->stop(); music_channel2->stop(); introductionmusic->release(); @@ -655,7 +656,11 @@ void deinitGame() { free(intromusic); } +#elif defined OPENAL_ENABLED + // TODO: unload OpenAL resources +#endif } + #ifdef USE_OPENAL #undef FMOD_Channel_Stop #undef FMOD_Sound_Release diff --git a/src/mod_tools.cpp b/src/mod_tools.cpp index e2f417feb..bfbe4e2b6 100644 --- a/src/mod_tools.cpp +++ b/src/mod_tools.cpp @@ -9277,7 +9277,7 @@ void Mods::unloadMods(bool force) physfsReloadMusic(reloadIntroMusic, true); if (reloadIntroMusic) { -#ifdef SOUND +#ifdef MUSIC playMusic(intromusic[local_rng.rand() % (NUMINTROMUSIC - 1)], false, true, true); #endif } @@ -9403,7 +9403,7 @@ void Mods::loadMods() physfsReloadMusic(reloadIntroMusic, false); if ( reloadIntroMusic ) { -#ifdef SOUND +#ifdef MUSIC playMusic(intromusic[local_rng.rand() % (NUMINTROMUSIC - 1)], false, true, true); #endif } @@ -9416,7 +9416,7 @@ void Mods::loadMods() physfsReloadMusic(reloadIntroMusic, true); if ( reloadIntroMusic ) { -#ifdef SOUND +#ifdef MUSIC playMusic(intromusic[local_rng.rand() % (NUMINTROMUSIC - 1)], false, true, true); #endif } @@ -9426,7 +9426,7 @@ void Mods::loadMods() updateLoadingScreen(70); doLoadingScreen(); - std::string langDirectory = PHYSFS_getRealDir("lang/en.txt"); + std::string langDirectory = PHYSFS_getRealDir("lang/fr.txt"); if ( langDirectory.compare("./") != 0 ) { if ( Language::reloadLanguage() != 0 ) diff --git a/src/ui/MainMenu.cpp b/src/ui/MainMenu.cpp index d17b3f4dc..79e80db70 100644 --- a/src/ui/MainMenu.cpp +++ b/src/ui/MainMenu.cpp @@ -2856,12 +2856,14 @@ namespace MainMenu { fpsLimit = std::min(std::max(MIN_FPS, *cvar_desiredFps), MAX_FPS); } current_audio_device = audio_device; +#if FMOD_ENABLED if (fmod_speakermode != speaker_mode) { fmod_speakermode = (FMOD_SPEAKERMODE)speaker_mode; if (initialized) { restartPromptRequired = true; } } +#endif MainMenu::master_volume = std::min(std::max(0.f, master_volume / 100.f), 1.f); sfxvolume = std::min(std::max(0.f, gameplay_volume / 100.f), 1.f); sfxAmbientVolume = std::min(std::max(0.f, ambient_volume / 100.f), 1.f); @@ -2960,7 +2962,9 @@ namespace MainMenu { settings.fov = ::fov; settings.fps = *cvar_desiredFps; settings.audio_device = current_audio_device; +#ifdef FMOD_ENABLED settings.speaker_mode = (int)fmod_speakermode; +#endif settings.master_volume = MainMenu::master_volume * 100.f; settings.gameplay_volume = (float)sfxvolume * 100.f; settings.ambient_volume = (float)sfxAmbientVolume * 100.f; @@ -6313,9 +6317,9 @@ namespace MainMenu { } int y = 0; + int num_drivers = 0; #if !defined(NINTENDO) && defined(USE_FMOD) int selected_device = 0; - int num_drivers = 0; (void)fmod_system->getNumDrivers(&num_drivers); audio_drivers.clear(); audio_drivers.reserve(num_drivers); @@ -24690,9 +24694,10 @@ namespace MainMenu { // return to title screen destroyMainMenu(); -#ifdef SOUND +#ifdef MUSIC const int music = RNG.uniform(0, NUMINTROMUSIC - 2); - playMusic(intromusic[music], true, false, false); + printlog("before play.\n"); + //playMusic(intromusic[music], true, false, false); #endif createTitleScreen(); @@ -24723,7 +24728,7 @@ namespace MainMenu { // return to menu destroyMainMenu(); -#ifdef SOUND +#ifdef MUSIC const int music = RNG.uniform(0, NUMINTROMUSIC - 2); playMusic(intromusic[music], true, false, false); #endif @@ -24758,7 +24763,7 @@ namespace MainMenu { // create a highscore as token of remembrance. doEndgame(true); } -#ifdef SOUND +#ifdef MUSIC const int music = RNG.uniform(0, NUMINTROMUSIC - 2); playMusic(intromusic[music], true, false, false); #endif @@ -24790,7 +24795,7 @@ namespace MainMenu { destroyMainMenu(); createDummyMainMenu(); createCreditsScreen(true); -#ifdef SOUND +#ifdef MUSIC playMusic(intromusic[0], true, false, false); #endif @@ -24981,9 +24986,11 @@ namespace MainMenu { } void doMainMenu(bool ingame) { + printlog("mmenu 1\n"); if (video_refresh) { Frame::guiResize(0, 0); // resize gui for new aspect ratio createMainMenu(!intro); + printlog("mmenu 2\n"); #if defined(VIDEO_RESTART_NEEDED) // return to settings button @@ -25073,7 +25080,7 @@ namespace MainMenu { // at the end so that old_video is not overwritten video_refresh = VideoRefresh::None; } - + printlog("mmenu 3\n"); if (!main_menu_frame) { if (ingame) { if (movie || fadeout) { @@ -25086,7 +25093,7 @@ namespace MainMenu { } assert(main_menu_frame); } - + printlog("mmenu 4\n"); // update a few things every tick #ifdef NINTENDO enabledDLCPack1 = nxCheckDLC(0); @@ -25144,22 +25151,23 @@ namespace MainMenu { } #endif } - + printlog("mmenu 4\n"); // if no controller is connected, you can always connect one just for the main menu. if (!ingame && currentLobbyType == LobbyType::None) { if (!inputs.hasController(getMenuOwner())) { Input::waitingToBindControllerForPlayer = getMenuOwner(); } } - + printlog("mmenu 5\n"); // hide mouse if we're driving around with a controller auto cmouse = inputs.getVirtualMouse(inputs.getPlayerIDAllowedKeyboard()); cmouse->draw_cursor = isMouseVisible(); - + printlog("mmenu 6\n"); static ConsoleVariable cvar_disableFadeFinished("/test_disable_fade_finished", false); if (fadeout && fadealpha >= 255 && !*cvar_disableFadeFinished) { handleFadeFinished(ingame); } + printlog("mmenu 7\n"); } static std::string getVersionString() { From 57c6a264960382428f0af02e647151638694f7c4 Mon Sep 17 00:00:00 2001 From: damiencarol Date: Mon, 4 Mar 2024 13:54:00 +0100 Subject: [PATCH 02/24] Remove usless debug --- .gitignore | 8 +++++++- src/ui/MainMenu.cpp | 8 -------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index e60e55eda..8c36c4a9c 100644 --- a/.gitignore +++ b/.gitignore @@ -75,4 +75,10 @@ steam_appid.txt xcode/Barony/Barony.xcodeproj/project.xcworkspace/* xcode/Barony/Barony.xcodeproj/xcuserdata/* *.ps1 -!LICENSE.nativefiledialog.txt \ No newline at end of file +!LICENSE.nativefiledialog.txt +CMakeCache.txt +CMakeFiles/* +Makefile +cmake_install.cmake +CMakeDirectoryInformation.cmake +progress.marks diff --git a/src/ui/MainMenu.cpp b/src/ui/MainMenu.cpp index 79e80db70..2e75b0e02 100644 --- a/src/ui/MainMenu.cpp +++ b/src/ui/MainMenu.cpp @@ -24986,11 +24986,9 @@ namespace MainMenu { } void doMainMenu(bool ingame) { - printlog("mmenu 1\n"); if (video_refresh) { Frame::guiResize(0, 0); // resize gui for new aspect ratio createMainMenu(!intro); - printlog("mmenu 2\n"); #if defined(VIDEO_RESTART_NEEDED) // return to settings button @@ -25080,7 +25078,6 @@ namespace MainMenu { // at the end so that old_video is not overwritten video_refresh = VideoRefresh::None; } - printlog("mmenu 3\n"); if (!main_menu_frame) { if (ingame) { if (movie || fadeout) { @@ -25093,7 +25090,6 @@ namespace MainMenu { } assert(main_menu_frame); } - printlog("mmenu 4\n"); // update a few things every tick #ifdef NINTENDO enabledDLCPack1 = nxCheckDLC(0); @@ -25151,23 +25147,19 @@ namespace MainMenu { } #endif } - printlog("mmenu 4\n"); // if no controller is connected, you can always connect one just for the main menu. if (!ingame && currentLobbyType == LobbyType::None) { if (!inputs.hasController(getMenuOwner())) { Input::waitingToBindControllerForPlayer = getMenuOwner(); } } - printlog("mmenu 5\n"); // hide mouse if we're driving around with a controller auto cmouse = inputs.getVirtualMouse(inputs.getPlayerIDAllowedKeyboard()); cmouse->draw_cursor = isMouseVisible(); - printlog("mmenu 6\n"); static ConsoleVariable cvar_disableFadeFinished("/test_disable_fade_finished", false); if (fadeout && fadealpha >= 255 && !*cvar_disableFadeFinished) { handleFadeFinished(ingame); } - printlog("mmenu 7\n"); } static std::string getVersionString() { From 9f2e1c2cf11b10c10d8255b4957e9ca105333b11 Mon Sep 17 00:00:00 2001 From: damiencarol Date: Mon, 4 Mar 2024 14:03:08 +0100 Subject: [PATCH 03/24] Refactor again some definitions to be more common between OpenAL and FMod libs --- src/engine/audio/defines.cpp | 13 +++++++++++-- src/engine/audio/sound.cpp | 10 ++-------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/engine/audio/defines.cpp b/src/engine/audio/defines.cpp index b6bdd6f0f..f8d143251 100644 --- a/src/engine/audio/defines.cpp +++ b/src/engine/audio/defines.cpp @@ -14,6 +14,8 @@ Uint32 numsounds = 0; +bool levelmusicplaying = false; // seems to be common to all sound libraries + #ifdef USE_FMOD FMOD::System* fmod_system = nullptr; @@ -55,7 +57,6 @@ FMOD::Sound* hamletmusic = nullptr; FMOD::Sound* tutorialmusic = nullptr; FMOD::Sound* gameovermusic = nullptr; FMOD::Sound* introstorymusic = nullptr; -bool levelmusicplaying = false; FMOD::Channel* music_channel = nullptr; FMOD::Channel* music_channel2 = nullptr; @@ -78,6 +79,14 @@ bool sfxUseDynamicAmbientVolume = true; bool sfxUseDynamicEnvironmentVolume = true; void* fmod_extraDriverData = nullptr; -#elif defined OPENAL_ENABLED +#elif defined USE_OPENAL + OPENAL_BUFFER** intromusic = nullptr; +OPENAL_BUFFER** minesmusic = NULL; +OPENAL_BUFFER** swampmusic = NULL; +OPENAL_BUFFER** labyrinthmusic = NULL; +OPENAL_BUFFER** ruinsmusic = NULL; +OPENAL_BUFFER** underworldmusic = NULL; +OPENAL_BUFFER** hellmusic = NULL; + #endif diff --git a/src/engine/audio/sound.cpp b/src/engine/audio/sound.cpp index 32f88e4ae..39e4b7525 100644 --- a/src/engine/audio/sound.cpp +++ b/src/engine/audio/sound.cpp @@ -486,12 +486,7 @@ ALCdevice *openal_device = nullptr; //#define openal_maxchannels 100 OPENAL_BUFFER** sounds = nullptr; -OPENAL_BUFFER** minesmusic = NULL; -OPENAL_BUFFER** swampmusic = NULL; -OPENAL_BUFFER** labyrinthmusic = NULL; -OPENAL_BUFFER** ruinsmusic = NULL; -OPENAL_BUFFER** underworldmusic = NULL; -OPENAL_BUFFER** hellmusic = NULL; + OPENAL_BUFFER* intermissionmusic = NULL; OPENAL_BUFFER* minetownmusic = NULL; OPENAL_BUFFER* splashmusic = NULL; @@ -517,7 +512,6 @@ OPENAL_BUFFER* hamletmusic = NULL; OPENAL_BUFFER* tutorialmusic = nullptr; OPENAL_BUFFER* gameovermusic = nullptr; OPENAL_BUFFER* introstorymusic = nullptr; -bool levelmusicplaying = false; OPENAL_SOUND* music_channel = nullptr; OPENAL_SOUND* music_channel2 = nullptr; @@ -1237,7 +1231,7 @@ void physfsReloadMusic(bool &introMusicChanged, bool reloadAll) //TODO: This sho { return; } -#ifdef SOUNDsdfdsf +#ifdef MUSIC std::vector themeMusic; themeMusic.push_back("music/introduction.ogg"); From bf405df4184b665e4b7f6d4d1d023f3b437de6b2 Mon Sep 17 00:00:00 2001 From: damiencarol Date: Mon, 4 Mar 2024 15:44:40 +0100 Subject: [PATCH 04/24] Fix setGlobalVolume and setAudioDevice generic function --- src/engine/audio/sound.cpp | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/engine/audio/sound.cpp b/src/engine/audio/sound.cpp index 39e4b7525..a29dc1dda 100644 --- a/src/engine/audio/sound.cpp +++ b/src/engine/audio/sound.cpp @@ -30,21 +30,6 @@ #endif -void setGlobalVolume(real_t master, real_t music, real_t gameplay, real_t ambient, real_t environment, real_t notification) -{ -#ifdef USE_FMOD -#elif defined USE_OPENAL -#else -#endif -} -void setAudioDevice(const std::string& device) -{ -#ifdef USE_FMOD -#elif defined USE_OPENAL -#else -#endif -} - #ifdef USE_FMOD bool FMODErrorCheck() @@ -699,7 +684,8 @@ static int get_firstfreechannel() return i; } -void setGlobalVolume(real_t master, real_t music, real_t gameplay, real_t ambient, real_t environment) { +void setGlobalVolume(real_t master, real_t music, real_t gameplay, real_t ambient, real_t environment, real_t notification) +{ master = std::min(std::max(0.0, master), 1.0); music = std::min(std::max(0.0, music / 4.0), 1.0); // music volume cut in half because the music is loud... gameplay = std::min(std::max(0.0, gameplay), 1.0); @@ -710,7 +696,11 @@ void setGlobalVolume(real_t master, real_t music, real_t gameplay, real_t ambien OPENAL_ChannelGroup_SetVolume(sound_group, master * gameplay); OPENAL_ChannelGroup_SetVolume(soundAmbient_group, master * ambient); OPENAL_ChannelGroup_SetVolume(soundEnvironment_group, master * environment); - OPENAL_ChannelGroup_SetVolume(music_notification_group, master * gameplay); + OPENAL_ChannelGroup_SetVolume(music_notification_group, master * notification); +} + +void setAudioDevice(const std::string& device){ + // TODO: implement device selection for OpenAL } void sound_update(int player, int index, int numplayers) @@ -1083,6 +1073,16 @@ void OPENAL_Sound_Release(OPENAL_BUFFER* buffer) { free(buffer); } +#else // No FMOD or OpenAL + +void setGlobalVolume(real_t master, real_t music, real_t gameplay, real_t ambient, real_t environment, real_t notification) +{ +} + +void setAudioDevice(const std::string& device) +{ +} + #endif bool physfsSearchMusicToUpdate_helper_findModifiedMusic(uint32_t numMusic, const char* filenameTemplate) From 10f1d2e4f2f79617fabee52b4285cc9f3f99d587 Mon Sep 17 00:00:00 2001 From: damiencarol Date: Tue, 5 Mar 2024 11:31:48 +0100 Subject: [PATCH 05/24] Fix a wrong pragma --- src/init_game.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/init_game.cpp b/src/init_game.cpp index 5e39b5641..1146d7dfb 100644 --- a/src/init_game.cpp +++ b/src/init_game.cpp @@ -656,7 +656,7 @@ void deinitGame() { free(intromusic); } -#elif defined OPENAL_ENABLED +#elif defined USE_OPENAL // TODO: unload OpenAL resources #endif } From e39685ff5709138b490f2b40f5b7b4f00c77aa63 Mon Sep 17 00:00:00 2001 From: damiencarol Date: Tue, 5 Mar 2024 11:32:24 +0100 Subject: [PATCH 06/24] Add helper for OpenAL --- src/engine/audio/sound.cpp | 20 ++++++++++++++++++++ src/engine/audio/sound.hpp | 4 +++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/engine/audio/sound.cpp b/src/engine/audio/sound.cpp index a29dc1dda..91a206f23 100644 --- a/src/engine/audio/sound.cpp +++ b/src/engine/audio/sound.cpp @@ -664,6 +664,26 @@ int closeOPENAL() return 1; } +/** + * taken from offical doc but not very "CPP" way + */ +int openalGetNumberOfDevices(const ALCchar *devices) +{ + const ALCchar *device = devices, *next = devices + 1; + size_t len = 0; + int num = 0; + + while (device && *device != '\0' && next && *next != '\0') { + //printlog("device detected: %s", device); + num += 1; + //fprintf(stdout, "%s\n", device); + len = strlen(device); + device += (len + 1); + next += (len + 2); + } + + return num; +} static int get_firstfreechannel() { diff --git a/src/engine/audio/sound.hpp b/src/engine/audio/sound.hpp index 1ce9e3411..f2ccbe1a4 100644 --- a/src/engine/audio/sound.hpp +++ b/src/engine/audio/sound.hpp @@ -139,7 +139,8 @@ extern bool sfxUseDynamicAmbientVolume, sfxUseDynamicEnvironmentVolume; #elif defined USE_OPENAL #define SOUND -//#definMUSIC +// for now we disable music +//#define MUSIC struct OPENAL_BUFFER { ALuint id; @@ -233,6 +234,7 @@ extern OPENAL_CHANNELGROUP *soundAmbient_group, *soundEnvironment_group, *music_ int initOPENAL(); int closeOPENAL(); +int openalGetNumberOfDevices(const ALCchar *devices); void sound_update(int player, int index, int numplayers); From fe746bc855455b7b5f0870b852a4c20d48f2a766 Mon Sep 17 00:00:00 2001 From: damiencarol Date: Tue, 5 Mar 2024 11:34:47 +0100 Subject: [PATCH 07/24] Revert bck modifications for gitignore --- .gitignore | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 8c36c4a9c..e60e55eda 100644 --- a/.gitignore +++ b/.gitignore @@ -75,10 +75,4 @@ steam_appid.txt xcode/Barony/Barony.xcodeproj/project.xcworkspace/* xcode/Barony/Barony.xcodeproj/xcuserdata/* *.ps1 -!LICENSE.nativefiledialog.txt -CMakeCache.txt -CMakeFiles/* -Makefile -cmake_install.cmake -CMakeDirectoryInformation.cmake -progress.marks +!LICENSE.nativefiledialog.txt \ No newline at end of file From 93ae0c882f47a0209250a66518f962b2cc9b7c36 Mon Sep 17 00:00:00 2001 From: damiencarol Date: Tue, 5 Mar 2024 11:52:04 +0100 Subject: [PATCH 08/24] Revert a useless change --- src/mod_tools.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mod_tools.cpp b/src/mod_tools.cpp index bfbe4e2b6..b9ec68517 100644 --- a/src/mod_tools.cpp +++ b/src/mod_tools.cpp @@ -9426,7 +9426,7 @@ void Mods::loadMods() updateLoadingScreen(70); doLoadingScreen(); - std::string langDirectory = PHYSFS_getRealDir("lang/fr.txt"); + std::string langDirectory = PHYSFS_getRealDir("lang/en.txt"); if ( langDirectory.compare("./") != 0 ) { if ( Language::reloadLanguage() != 0 ) From 9d69e099225fef12900564691b7a4eec1a1c70d7 Mon Sep 17 00:00:00 2001 From: damiencarol Date: Tue, 5 Mar 2024 12:00:39 +0100 Subject: [PATCH 09/24] Fix USE_FMOD/FMOD_ENABLED pragmas --- src/engine/audio/sound.cpp | 2 +- src/ui/MainMenu.cpp | 94 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 92 insertions(+), 4 deletions(-) diff --git a/src/engine/audio/sound.cpp b/src/engine/audio/sound.cpp index 91a206f23..a6ab30306 100644 --- a/src/engine/audio/sound.cpp +++ b/src/engine/audio/sound.cpp @@ -1705,7 +1705,7 @@ void physfsReloadMusic(bool &introMusicChanged, bool reloadAll) //TODO: This sho void gamemodsUnloadCustomThemeMusic() { #ifdef SOUND -#ifdef FMOD_ENABLED +#ifdef USE_FMOD if ( gnomishminesmusic ) { gnomishminesmusic->release(); diff --git a/src/ui/MainMenu.cpp b/src/ui/MainMenu.cpp index 2e75b0e02..2f193c9c9 100644 --- a/src/ui/MainMenu.cpp +++ b/src/ui/MainMenu.cpp @@ -2856,7 +2856,7 @@ namespace MainMenu { fpsLimit = std::min(std::max(MIN_FPS, *cvar_desiredFps), MAX_FPS); } current_audio_device = audio_device; -#if FMOD_ENABLED +#ifdef USE_FMOD if (fmod_speakermode != speaker_mode) { fmod_speakermode = (FMOD_SPEAKERMODE)speaker_mode; if (initialized) { @@ -2962,7 +2962,7 @@ namespace MainMenu { settings.fov = ::fov; settings.fps = *cvar_desiredFps; settings.audio_device = current_audio_device; -#ifdef FMOD_ENABLED +#ifdef USE_FMOD settings.speaker_mode = (int)fmod_speakermode; #endif settings.master_volume = MainMenu::master_volume * 100.f; @@ -4453,16 +4453,20 @@ namespace MainMenu { }); } -#if defined(USE_FMOD) struct AudioDriver { char name[64]; +#if defined(USE_FMOD) FMOD_GUID guid; int system_rate; FMOD_SPEAKERMODE speaker_mode; int speaker_mode_channels; +#endif +#if defined(USE_OPENAL) +#endif }; static std::vector audio_drivers; +#if defined(USE_FMOD) static void settingsAudioDevice(Button& button) { settingsOpenDropdown(button, "device", DropdownType::Wide, [](Frame::entry_t& entry){ soundActivate(); @@ -4511,6 +4515,35 @@ namespace MainMenu { }); } #endif +#ifdef USE_OPENAL + static void settingsAudioDevice(Button& button) { + settingsOpenDropdown(button, "device", DropdownType::Wide, [](Frame::entry_t& entry){ + soundActivate(); + + // store driver + /* + unsigned int index; memcpy(&index, &entry.data, sizeof(index)); + if (index < audio_drivers.size()) { + const auto& driver = audio_drivers[index]; + uint32_t _1; memcpy(&_1, &driver.guid.Data1, sizeof(_1)); + uint64_t _2; memcpy(&_2, &driver.guid.Data4, sizeof(_2)); + char guid_string[25]; + snprintf(guid_string, sizeof(guid_string), FMOD_AUDIO_GUID_FMT, _1, _2); + allSettings.audio_device = guid_string; + fmod_system->setDriver(index); + } + */ + + auto settings = main_menu_frame->findFrame("settings"); assert(settings); + auto settings_subwindow = settings->findFrame("settings_subwindow"); assert(settings_subwindow); + auto button = settings_subwindow->findButton("setting_device_dropdown_button"); assert(button); + auto dropdown = settings_subwindow->findFrame("setting_device_dropdown"); assert(dropdown); + button->setText(entry.name.c_str()); + dropdown->removeSelf(); + button->select(); + }); + } +#endif static void settingsMkbHotbarLayout(Button& button) { // deprecated @@ -6359,6 +6392,61 @@ namespace MainMenu { y += settingsAddDropdown(*settings_subwindow, y, "speaker_mode", Language::get(6140), Language::get(6150), true, modes_ptrs, modes_ptrs[allSettings.speaker_mode], settingsAudioSpeakerMode); } +#else + audio_drivers.clear(); + + + if ((error = alGetError()) != AL_NO_ERROR) + { + DisplayALError("alGenBuffers :", error); + return; + } + + + + if (alcIsExtensionPresent(NULL, "ALC_ENUMERATION_EXT") == AL_TRUE) { // Enumeration Extension Found + printlog("OpenAL support ALC_ENUMERATION_EXT extention.\n"); + const ALCchar *devices_raw = alcGetString(NULL, ALC_DEVICE_SPECIFIER); + num_drivers = openalGetNumberOfDevices(devices_raw); + printlog("number of device detected: %d", num_drivers); + + audio_drivers.reserve(num_drivers); + + // this is good, taken from offical doc but not very "CPP" way + const ALCchar *device = devices_raw, *next = devices_raw + 1; + size_t len = 0; + + while (device && *device != '\0' && next && *next != '\0') { + len = strlen(device); + printlog("device detected: %s", device); + + AudioDriver d; + memcpy(d.name, device, len); + audio_drivers.push_back(d); + + //fprintf(stdout, "%s\n", device); + device += (len + 1); + next += (len + 2); + } + + std::vector drivers_formatted_ptrs; + drivers_formatted_ptrs.reserve(num_drivers); + for (auto& d : audio_drivers) { + drivers_formatted_ptrs.push_back(d.name); + } + + // debug + drivers_formatted_ptrs.push_back("Test"); + + // add section "output" + y += settingsAddSubHeader(*settings_subwindow, y, "output", Language::get(5182)); + if ( num_drivers > 0 ) + { + y += settingsAddDropdown(*settings_subwindow, y, "device", Language::get(5183), Language::get(5184), + true, drivers_formatted_ptrs, drivers_formatted_ptrs[0], //selected_device], + settingsAudioDevice); + } + } #endif y += settingsAddSubHeader(*settings_subwindow, y, "volume", Language::get(5185)); From a7f9122a731c18e79a1b759e2a9a5bc131908228 Mon Sep 17 00:00:00 2001 From: Damien Carol Date: Wed, 6 Mar 2024 13:13:10 +0100 Subject: [PATCH 10/24] Reverst useless changes --- src/ui/MainMenu.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/ui/MainMenu.cpp b/src/ui/MainMenu.cpp index 2f193c9c9..9e9c9ddbd 100644 --- a/src/ui/MainMenu.cpp +++ b/src/ui/MainMenu.cpp @@ -24784,8 +24784,7 @@ namespace MainMenu { destroyMainMenu(); #ifdef MUSIC const int music = RNG.uniform(0, NUMINTROMUSIC - 2); - printlog("before play.\n"); - //playMusic(intromusic[music], true, false, false); + playMusic(intromusic[music], true, false, false); #endif createTitleScreen(); @@ -25166,6 +25165,7 @@ namespace MainMenu { // at the end so that old_video is not overwritten video_refresh = VideoRefresh::None; } + if (!main_menu_frame) { if (ingame) { if (movie || fadeout) { @@ -25235,6 +25235,7 @@ namespace MainMenu { } #endif } + // if no controller is connected, you can always connect one just for the main menu. if (!ingame && currentLobbyType == LobbyType::None) { if (!inputs.hasController(getMenuOwner())) { @@ -25244,6 +25245,7 @@ namespace MainMenu { // hide mouse if we're driving around with a controller auto cmouse = inputs.getVirtualMouse(inputs.getPlayerIDAllowedKeyboard()); cmouse->draw_cursor = isMouseVisible(); + static ConsoleVariable cvar_disableFadeFinished("/test_disable_fade_finished", false); if (fadeout && fadealpha >= 255 && !*cvar_disableFadeFinished) { handleFadeFinished(ingame); From e76c52b0fd64a3d568422a8af9c0927f5f4c5c49 Mon Sep 17 00:00:00 2001 From: Damien Carol Date: Wed, 6 Mar 2024 13:14:44 +0100 Subject: [PATCH 11/24] Revert useless changes --- src/ui/MainMenu.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/ui/MainMenu.cpp b/src/ui/MainMenu.cpp index 9e9c9ddbd..25fa8cc23 100644 --- a/src/ui/MainMenu.cpp +++ b/src/ui/MainMenu.cpp @@ -25178,6 +25178,7 @@ namespace MainMenu { } assert(main_menu_frame); } + // update a few things every tick #ifdef NINTENDO enabledDLCPack1 = nxCheckDLC(0); @@ -25242,6 +25243,7 @@ namespace MainMenu { Input::waitingToBindControllerForPlayer = getMenuOwner(); } } + // hide mouse if we're driving around with a controller auto cmouse = inputs.getVirtualMouse(inputs.getPlayerIDAllowedKeyboard()); cmouse->draw_cursor = isMouseVisible(); From 03a56a2ba25608a59ff940889a82286a8f94206c Mon Sep 17 00:00:00 2001 From: Damien Carol Date: Wed, 6 Mar 2024 13:35:39 +0100 Subject: [PATCH 12/24] Add missing implementation --- src/engine/audio/sound_game.cpp | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/engine/audio/sound_game.cpp b/src/engine/audio/sound_game.cpp index b7ab22477..957514b51 100644 --- a/src/engine/audio/sound_game.cpp +++ b/src/engine/audio/sound_game.cpp @@ -404,8 +404,31 @@ OPENAL_SOUND* playSoundNotificationPlayer(int player, Uint16 snd, Uint8 vol) return NULL; } - //TODO: Implement playSoundNotificationPlayer for OpenAL. - return NULL; + if ( player < 0 || player >= MAXPLAYERS ) //Perhaps this can be reprogrammed to remove MAXPLAYERS, and use a pointer to the player instead of an int? + { + return nullptr; + } + if ( players[player]->isLocalPlayer() ) + { + return playSoundNotification(snd, vol); + } + else if ( multiplayer == SERVER ) + { + if ( client_disconnected[player] || player <= 0 ) + { + return nullptr; + } + memcpy(net_packet->data, "SNDN", 4); + SDLNet_Write16(snd, &net_packet->data[4]); + net_packet->data[6] = vol; + net_packet->address.host = net_clients[player - 1].host; + net_packet->address.port = net_clients[player - 1].port; + net_packet->len = 7; + sendPacketSafe(net_sock, -1, net_packet, player - 1); + return nullptr; + } + + return nullptr; } /*------------------------------------------------------------------------------- From 792f13cc4d70c00692ec420d8e19c698defe5a7d Mon Sep 17 00:00:00 2001 From: damiencarol Date: Wed, 6 Mar 2024 17:32:18 +0100 Subject: [PATCH 13/24] Remove useless check --- src/ui/MainMenu.cpp | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/ui/MainMenu.cpp b/src/ui/MainMenu.cpp index 25fa8cc23..41403e8ef 100644 --- a/src/ui/MainMenu.cpp +++ b/src/ui/MainMenu.cpp @@ -6395,15 +6395,6 @@ namespace MainMenu { #else audio_drivers.clear(); - - if ((error = alGetError()) != AL_NO_ERROR) - { - DisplayALError("alGenBuffers :", error); - return; - } - - - if (alcIsExtensionPresent(NULL, "ALC_ENUMERATION_EXT") == AL_TRUE) { // Enumeration Extension Found printlog("OpenAL support ALC_ENUMERATION_EXT extention.\n"); const ALCchar *devices_raw = alcGetString(NULL, ALC_DEVICE_SPECIFIER); From 2731f9fe430491692ae8608788396cf36254bcbf Mon Sep 17 00:00:00 2001 From: damiencarol Date: Wed, 6 Mar 2024 18:28:01 +0100 Subject: [PATCH 14/24] Implement notification sound --- src/engine/audio/defines.cpp | 10 ++++++++++ src/engine/audio/sound.cpp | 15 +++++---------- src/engine/audio/sound_game.cpp | 19 ++++++++++++++++++- 3 files changed, 33 insertions(+), 11 deletions(-) diff --git a/src/engine/audio/defines.cpp b/src/engine/audio/defines.cpp index f8d143251..f42547fa0 100644 --- a/src/engine/audio/defines.cpp +++ b/src/engine/audio/defines.cpp @@ -89,4 +89,14 @@ OPENAL_BUFFER** ruinsmusic = NULL; OPENAL_BUFFER** underworldmusic = NULL; OPENAL_BUFFER** hellmusic = NULL; +OPENAL_SOUND* music_channel = nullptr; +OPENAL_SOUND* music_channel2 = nullptr; +OPENAL_SOUND* music_resume = nullptr; + +OPENAL_CHANNELGROUP *sound_group = NULL; +OPENAL_CHANNELGROUP *soundAmbient_group = NULL; +OPENAL_CHANNELGROUP *soundEnvironment_group = NULL; +OPENAL_CHANNELGROUP *music_group = NULL; +OPENAL_CHANNELGROUP *music_notification_group = NULL; + #endif diff --git a/src/engine/audio/sound.cpp b/src/engine/audio/sound.cpp index a6ab30306..ff4a74f4b 100644 --- a/src/engine/audio/sound.cpp +++ b/src/engine/audio/sound.cpp @@ -498,16 +498,6 @@ OPENAL_BUFFER* tutorialmusic = nullptr; OPENAL_BUFFER* gameovermusic = nullptr; OPENAL_BUFFER* introstorymusic = nullptr; -OPENAL_SOUND* music_channel = nullptr; -OPENAL_SOUND* music_channel2 = nullptr; -OPENAL_SOUND* music_resume = nullptr; - -OPENAL_CHANNELGROUP *sound_group = NULL; -OPENAL_CHANNELGROUP *soundAmbient_group = NULL; -OPENAL_CHANNELGROUP *soundEnvironment_group = NULL; -OPENAL_CHANNELGROUP *music_group = NULL; -OPENAL_CHANNELGROUP *music_notification_group = NULL; - float fadein_increment = 0.002f; float default_fadein_increment = 0.002f; float fadeout_increment = 0.005f; @@ -571,6 +561,11 @@ int OPENAL_ThreadFunction(void* data) { return 1; } +/** + * Initialize OpenAL library + * + * - Channel groups are initialized here + */ int initOPENAL() { static int initialized = 0; diff --git a/src/engine/audio/sound_game.cpp b/src/engine/audio/sound_game.cpp index 957514b51..571e773af 100644 --- a/src/engine/audio/sound_game.cpp +++ b/src/engine/audio/sound_game.cpp @@ -615,8 +615,25 @@ OPENAL_SOUND* playSoundNotification(Uint16 snd, Uint8 vol) { return NULL; } - // TODO: Implement playSoundNotification for OpenAL +#ifndef SOUND return NULL; +#endif + if (!openal_context || snd < 0 || snd >= numsounds || !music_notification_group ) + { + return NULL; + } + if (sounds[snd] == NULL || vol == 0) + { + return NULL; + } + OPENAL_SOUND* channel = OPENAL_CreateChannel(sounds[snd]); + OPENAL_Channel_SetVolume(channel, vol / 255.f); + + OPENAL_Channel_SetChannelGroup(channel, music_notification_group); + + OPENAL_Channel_Play(channel); + + return channel; } void playMusic(OPENAL_BUFFER* sound, bool loop, bool crossfade, bool resume) From 6f0a97901021ac5257bfe8d91a5667af2ea25cdd Mon Sep 17 00:00:00 2001 From: damiencarol Date: Wed, 6 Mar 2024 18:34:40 +0100 Subject: [PATCH 15/24] Add comments --- src/engine/audio/sound.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/engine/audio/sound.cpp b/src/engine/audio/sound.cpp index ff4a74f4b..4b11cb231 100644 --- a/src/engine/audio/sound.cpp +++ b/src/engine/audio/sound.cpp @@ -572,10 +572,13 @@ int initOPENAL() if(initialized) return 1; + printlog("[OpenAL]: initializing...\n"); + printlog("[OpenAL]: opening device...\n"); openal_device = alcOpenDevice(NULL); // preferred device if(!openal_device) return 0; + printlog("[OpenAL]: opening context...\n"); openal_context = alcCreateContext(openal_device,NULL); if(!openal_context) return 0; @@ -628,13 +631,15 @@ int initOPENAL() int closeOPENAL() { - if(OpenALSoundON) return 0; - + if(OpenALSoundON) + return 0; OpenALSoundON = false; + + printlog("[OpenAL]: closing...\n"); int i = 0; SDL_WaitThread(openal_soundthread, &i); if(i!=1) { - printlog("Warning, unable to stop Openal thread\n"); + printlog("[OpenAL]: unable to stop openal_soundthread thread\n"); } if(openal_mutex) { From f7e74caf0bb7a20664f17d59b81a776b0e1a6e69 Mon Sep 17 00:00:00 2001 From: damiencarol Date: Fri, 8 Mar 2024 17:11:12 +0100 Subject: [PATCH 16/24] Unblock more musics --- src/engine/audio/defines.cpp | 28 ++- src/engine/audio/music.cpp | 410 +++++++++++++++++++++++++++++++- src/engine/audio/sound.cpp | 163 ++++++++----- src/engine/audio/sound.hpp | 8 +- src/engine/audio/sound_game.cpp | 383 ----------------------------- src/game.cpp | 4 + src/init_game.cpp | 14 ++ src/menu.cpp | 12 + 8 files changed, 557 insertions(+), 465 deletions(-) diff --git a/src/engine/audio/defines.cpp b/src/engine/audio/defines.cpp index f42547fa0..f6eed9739 100644 --- a/src/engine/audio/defines.cpp +++ b/src/engine/audio/defines.cpp @@ -9,7 +9,7 @@ -------------------------------------------------------------------------------*/ -#include "../../main.hpp" +#include #include "sound.hpp" Uint32 numsounds = 0; @@ -81,22 +81,26 @@ bool sfxUseDynamicEnvironmentVolume = true; void* fmod_extraDriverData = nullptr; #elif defined USE_OPENAL + +OPENAL_BUFFER* introductionmusic = nullptr; + OPENAL_BUFFER** intromusic = nullptr; -OPENAL_BUFFER** minesmusic = NULL; -OPENAL_BUFFER** swampmusic = NULL; -OPENAL_BUFFER** labyrinthmusic = NULL; -OPENAL_BUFFER** ruinsmusic = NULL; -OPENAL_BUFFER** underworldmusic = NULL; -OPENAL_BUFFER** hellmusic = NULL; +OPENAL_BUFFER** minesmusic = nullptr; +OPENAL_BUFFER** swampmusic = nullptr; +OPENAL_BUFFER** labyrinthmusic = nullptr; +OPENAL_BUFFER** ruinsmusic = nullptr; +OPENAL_BUFFER** underworldmusic = nullptr; +OPENAL_BUFFER** hellmusic = nullptr; OPENAL_SOUND* music_channel = nullptr; OPENAL_SOUND* music_channel2 = nullptr; OPENAL_SOUND* music_resume = nullptr; -OPENAL_CHANNELGROUP *sound_group = NULL; -OPENAL_CHANNELGROUP *soundAmbient_group = NULL; -OPENAL_CHANNELGROUP *soundEnvironment_group = NULL; -OPENAL_CHANNELGROUP *music_group = NULL; -OPENAL_CHANNELGROUP *music_notification_group = NULL; +OPENAL_CHANNELGROUP *sound_group = nullptr; +OPENAL_CHANNELGROUP *soundAmbient_group = nullptr; +OPENAL_CHANNELGROUP *soundEnvironment_group = nullptr; +OPENAL_CHANNELGROUP *soundNotification_group = nullptr; +OPENAL_CHANNELGROUP *music_group = nullptr; +OPENAL_CHANNELGROUP *music_notification_group = nullptr; #endif diff --git a/src/engine/audio/music.cpp b/src/engine/audio/music.cpp index ad10179ca..579359fdc 100644 --- a/src/engine/audio/music.cpp +++ b/src/engine/audio/music.cpp @@ -76,8 +76,27 @@ bool loadMusic() memset(intromusic, 0, sizeof(FMOD::Sound*) * NUMINTROMUSIC); } #elif defined USE_OPENAL - // TODO: load intro music - + minesmusic = (OPENAL_BUFFER**)malloc(sizeof(OPENAL_BUFFER*) * NUMMINESMUSIC); + memset(minesmusic, 0, sizeof(OPENAL_BUFFER*) * NUMMINESMUSIC); + swampmusic = (OPENAL_BUFFER**)malloc(sizeof(OPENAL_BUFFER*) * NUMMINESMUSIC); + memset(swampmusic, 0, sizeof(OPENAL_BUFFER*) * NUMMINESMUSIC); + labyrinthmusic = (OPENAL_BUFFER**)malloc(sizeof(OPENAL_BUFFER*) * NUMMINESMUSIC); + memset(labyrinthmusic, 0, sizeof(OPENAL_BUFFER*) * NUMMINESMUSIC); + ruinsmusic = (OPENAL_BUFFER**)malloc(sizeof(OPENAL_BUFFER*) * NUMMINESMUSIC); + memset(ruinsmusic, 0, sizeof(OPENAL_BUFFER*) * NUMMINESMUSIC); + underworldmusic = (OPENAL_BUFFER**)malloc(sizeof(OPENAL_BUFFER*) * NUMMINESMUSIC); + memset(underworldmusic, 0, sizeof(OPENAL_BUFFER*) * NUMMINESMUSIC); + hellmusic = (OPENAL_BUFFER**)malloc(sizeof(OPENAL_BUFFER*) * NUMMINESMUSIC); + memset(hellmusic, 0, sizeof(OPENAL_BUFFER*) * NUMMINESMUSIC); + minotaurmusic = (OPENAL_BUFFER**)malloc(sizeof(OPENAL_BUFFER*) * NUMMINESMUSIC); + memset(minotaurmusic, 0, sizeof(OPENAL_BUFFER*) * NUMMINESMUSIC); + cavesmusic = (OPENAL_BUFFER**)malloc(sizeof(OPENAL_BUFFER*) * NUMMINESMUSIC); + memset(cavesmusic, 0, sizeof(OPENAL_BUFFER*) * NUMMINESMUSIC); + citadelmusic = (OPENAL_BUFFER**)malloc(sizeof(OPENAL_BUFFER*) * NUMMINESMUSIC); + memset(citadelmusic, 0, sizeof(OPENAL_BUFFER*) * NUMMINESMUSIC); + intromusic = (OPENAL_BUFFER**)malloc(sizeof(OPENAL_BUFFER*) * NUMMINESMUSIC); + memset(intromusic, 0, sizeof(OPENAL_BUFFER*) * NUMMINESMUSIC); + #endif bool introMusicChanged; @@ -445,6 +464,392 @@ void handleLevelMusic() playMusic(tutorialmusic, true, true, true); } else + { + playMusic(intermissionmusic, true, true, true); + } + olddarkmap = darkmap; + levelmusicplaying = true; + devilmusicplaying = false; + herxmusicplaying = false; + minotaurmusicplaying = false; + combatmusicplaying = false; + shopmusicplaying = false; + fadein_increment = default_fadein_increment; + fadeout_increment = default_fadeout_increment; + } + else if ( (!devilmusicplaying || !playing) && devilaround ) + { + playMusic(devilmusic, true, true, true); + levelmusicplaying = false; + devilmusicplaying = true; + herxmusicplaying = false; + minotaurmusicplaying = false; + combatmusicplaying = false; + shopmusicplaying = false; + fadein_increment = default_fadein_increment * 2; + fadeout_increment = default_fadeout_increment * 2; + } + else if ( (!herxmusicplaying || !playing) && !devilaround && herxaround ) + { + playMusic(herxmusic, true, true, true); + levelmusicplaying = false; + devilmusicplaying = false; + herxmusicplaying = true; + minotaurmusicplaying = false; + combatmusicplaying = false; + shopmusicplaying = false; + fadein_increment = default_fadein_increment * 2; + fadeout_increment = default_fadeout_increment * 2; + } + else if ( (!minotaurmusicplaying || !playing) && !herxaround && activeminotaur && strcmp(map.name, "Hell Boss") ) + { + playMusic(minotaurmusic[0], true, true, true); + levelmusicplaying = false; + devilmusicplaying = false; + herxmusicplaying = false; + minotaurmusicplaying = true; + combatmusicplaying = false; + shopmusicplaying = false; + fadein_increment = default_fadein_increment * 5; + fadeout_increment = default_fadeout_increment * 5; + } + else if ( (!sanctummusicplaying || !playing) && magisteraround ) + { + playMusic(sanctummusic, true, true, true); + levelmusicplaying = false; + devilmusicplaying = false; + herxmusicplaying = false; + minotaurmusicplaying = false; + combatmusicplaying = false; + sanctummusicplaying = true; + shopmusicplaying = false; + fadein_increment = default_fadein_increment * 2; + fadeout_increment = default_fadeout_increment * 2; + } + else if ( (!combatmusicplaying || !playing) + && !herxaround + && !activeminotaur + && combat + && strcmp(map.name, "Hell Boss") + && strcmp(map.name, "Sanctum") ) + { + if ( !strncmp(map.name, "The Swamp", 9) || !strncmp(map.name, "The Temple", 10) ) // the swamp + { + playMusic(swampmusic[0], true, true, true); + } + else if ( !strncmp(map.name, "The Labyrinth", 13) || strstr(map.name, "Minotaur") ) // the labyrinth + { + playMusic(labyrinthmusic[0], true, true, true); + } + else if ( !strncmp(map.name, "The Ruins", 9) ) // the ruins + { + playMusic(ruinsmusic[0], true, true, true); + } + else if ( !strncmp(map.name, "Underworld", 10) ) // the underworld + { + playMusic(underworldmusic[0], true, true, true); + } + else if ( !strncmp(map.name, "Hell", 4) ) // hell + { + playMusic(hellmusic[0], true, true, true); + } + else if ( !strncmp(map.name, "Caves", 5) || !strcmp(map.name, "Cockatrice Lair") ) + { + playMusic(cavesmusic[0], true, true, true); + } + else if ( !strncmp(map.name, "Citadel", 7) || !strcmp(map.name, "Bram's Castle") ) + { + playMusic(citadelmusic[0], true, true, true); + } + else + { + playMusic(minesmusic[0], true, true, true); + } + levelmusicplaying = false; + devilmusicplaying = false; + herxmusicplaying = false; + combatmusicplaying = true; + shopmusicplaying = false; + minotaurmusicplaying = false; + fadein_increment = default_fadein_increment * 4; + fadeout_increment = default_fadeout_increment; + } + else if ( (!shopmusicplaying || !playing) && !herxaround && !activeminotaur && !combat && inshop ) + { + playMusic(shopmusic, true, true, true); + levelmusicplaying = false; + devilmusicplaying = false; + herxmusicplaying = false; + minotaurmusicplaying = false; + combatmusicplaying = false; + shopmusicplaying = true; + fadein_increment = default_fadein_increment * 4; + fadeout_increment = default_fadeout_increment; + } +} + +#elif defined USE_OPENAL + +void handleLevelMusic() +{ + if (no_sound) + { + return; + } +#ifndef SOUND + return; +#endif +#ifndef MUSIC + return; +#endif + bool inshop = false; + if (players[clientnum] && players[clientnum]->entity) + { + int x = (int)players[clientnum]->entity->x / 16; + int y = (int)players[clientnum]->entity->y / 16; + if ( x >= 0 && x < map.width && y >= 0 && y < map.height ) + if ( shoparea[y + x * map.height] ) + { + inshop = true; + } + } + + bool devilaround = false; + bool activeminotaur = false; + bool herxaround = false; + bool magisteraround = false; + node_t* node; + for ( node = map.creatures->first; node != NULL; node = node->next ) + { + Entity* entity = (Entity*)node->element; + if ( entity->sprite == 274 ) // herx head + { + herxaround = true; + break; + } + else if ( entity->sprite == 304 ) // devil body + { + devilaround = true; + break; + } + else if ( entity->sprite == 239 ) // minotaur head + { + activeminotaur = true; + break; + } + else if ( entity->sprite == 646 || entity->sprite == 650 ) // magister body + { + magisteraround = true; + break; + } + } + + ALboolean playing = true; + if (music_channel) + OPENAL_Channel_IsPlaying(music_channel, &playing); + + + if ( currenttrack == -1 ) + { + currenttrack = local_rng.rand(); + } + + if ( (!levelmusicplaying || !playing || olddarkmap != darkmap) + && (!combat || !strcmp(map.name, "Hell Boss")) + && !inshop + && (!activeminotaur || !strcmp(map.name, "Hell Boss")) && !herxaround && !devilaround && !magisteraround ) + { + if ( !strncmp(map.name, "The Mines", 9) ) // the mines + { + if ( !playing ) + { + currenttrack = 1 + local_rng.rand() % (NUMMINESMUSIC - 1); + } + currenttrack = currenttrack % NUMMINESMUSIC; + if ( currenttrack == 0 ) + { + currenttrack = 1; + } + playMusic(minesmusic[currenttrack], false, true, true); + } + else if ( !strncmp(map.name, "The Swamp", 9) ) // the swamp + { + if ( !playing ) + { + currenttrack = 1 + local_rng.rand() % (NUMSWAMPMUSIC - 1); + } + currenttrack = currenttrack % NUMSWAMPMUSIC; + if ( currenttrack == 0 ) + { + currenttrack = 1; + } + playMusic(swampmusic[currenttrack], false, true, true); + } + else if ( !strncmp(map.name, "The Labyrinth", 13) ) // the labyrinth + { + if ( !playing ) + { + currenttrack = 1 + local_rng.rand() % (NUMLABYRINTHMUSIC - 1); + } + currenttrack = currenttrack % NUMLABYRINTHMUSIC; + if ( currenttrack == 0 ) + { + currenttrack = 1; + } + playMusic(labyrinthmusic[currenttrack], false, true, true); + } + else if ( !strncmp(map.name, "The Ruins", 9) ) // the ruins + { + if ( !playing ) + { + currenttrack = 1 + local_rng.rand() % (NUMRUINSMUSIC - 1); + } + currenttrack = currenttrack % NUMRUINSMUSIC; + if ( currenttrack == 0 ) + { + currenttrack = 1; + } + playMusic(ruinsmusic[currenttrack], false, true, true); + } + else if ( !strncmp(map.name, "Underworld", 10) ) // the underworld + { + if ( !playing ) + { + currenttrack = 1 + local_rng.rand() % (NUMUNDERWORLDMUSIC - 1); + } + currenttrack = currenttrack % NUMUNDERWORLDMUSIC; + if ( currenttrack == 0 ) + { + currenttrack = 1; + } + playMusic(underworldmusic[currenttrack], false, true, true); + } + else if ( !strcmp(map.name, "Minetown") ) // minetown + { + playMusic(minetownmusic, true, true, true); + } + else if ( !strcmp(map.name, "The Gnomish Mines") ) + { + if ( gnomishminesmusic ) + { + playMusic(gnomishminesmusic, true, true, true); + } + else + { + playMusic(minetownmusic, true, true, true); + } + } + else if ( !strcmp(map.name, "The Haunted Castle") ) + { + if ( greatcastlemusic ) + { + playMusic(greatcastlemusic, true, true, true); + } + else + { + playMusic(intermissionmusic, true, true, true); + } + } + else if ( !strcmp(map.name, "Sokoban") ) + { + if ( sokobanmusic ) + { + playMusic(sokobanmusic, true, true, true); + } + else + { + playMusic(intermissionmusic, true, true, true); + } + } + else if ( !strcmp(map.name, "Cockatrice Lair") ) + { + if ( caveslairmusic ) + { + playMusic(caveslairmusic, true, true, true); + } + else + { + playMusic(cavesmusic[2], true, true, true); + } + } + else if ( !strcmp(map.name, "Bram's Castle") ) + { + if ( bramscastlemusic ) + { + playMusic(bramscastlemusic, true, true, true); + } + else + { + playMusic(citadelmusic[2], true, true, true); + } + } + else if ( !strcmp(map.name, "The Mystic Library") ) // mystic library + { + playMusic(librarymusic, true, true, true); + } + else if ( !strcmp(map.name, "The Minotaur Maze") ) // minotaur maze + { + playMusic(minotaurmusic[1], true, true, true); + } + else if ( !strcmp(map.name, "The Temple") ) // the temple + { + playMusic(templemusic, true, true, true); + } + else if ( !strcmp(map.name, "Hell Boss") ) // escape theme + { + playMusic(escapemusic, true, true, true); + } + else if ( !strncmp(map.name, "Hell", 4) ) // hell + { + if ( !playing ) + { + currenttrack = 1 + local_rng.rand() % (NUMHELLMUSIC - 1); + } + currenttrack = currenttrack % NUMHELLMUSIC; + if ( currenttrack == 0 ) + { + currenttrack = 1; + } + playMusic(hellmusic[currenttrack], false, true, true); + } + else if ( !strncmp(map.name, "Caves", 5) ) + { + if ( !playing ) + { + currenttrack = 1 + local_rng.rand() % (NUMCAVESMUSIC - 1); + } + currenttrack = currenttrack % NUMCAVESMUSIC; + if ( currenttrack == 0 ) + { + currenttrack = 1; + } + playMusic(cavesmusic[currenttrack], false, true, true); + } + else if ( !strncmp(map.name, "Citadel", 7) || !strncmp(map.name, "Sanctum", 7) ) + { + if ( !playing ) + { + currenttrack = 1 + local_rng.rand() % (NUMCITADELMUSIC - 1); + } + currenttrack = currenttrack % NUMCITADELMUSIC; + if ( currenttrack == 0 ) + { + currenttrack = 1; + } + playMusic(citadelmusic[currenttrack], false, true, true); + } + else if ( !strcmp(map.name, "Mages Guild") ) + { + if ( hamletmusic ) + { + playMusic(hamletmusic, true, true, true); + } + else + { + playMusic(minesmusic[4], true, true, true); + } + } + else { playMusic(intermissionmusic, true, true, true); } @@ -568,4 +973,5 @@ void handleLevelMusic() fadeout_increment = default_fadeout_increment; } } + #endif diff --git a/src/engine/audio/sound.cpp b/src/engine/audio/sound.cpp index 4b11cb231..4727710a2 100644 --- a/src/engine/audio/sound.cpp +++ b/src/engine/audio/sound.cpp @@ -485,7 +485,6 @@ OPENAL_BUFFER* endgamemusic = NULL; OPENAL_BUFFER* devilmusic = NULL; OPENAL_BUFFER* escapemusic = NULL; OPENAL_BUFFER* sanctummusic = NULL; -OPENAL_BUFFER* introductionmusic = NULL; OPENAL_BUFFER** cavesmusic = NULL; OPENAL_BUFFER** citadelmusic = NULL; OPENAL_BUFFER* gnomishminesmusic = NULL; @@ -952,7 +951,15 @@ int OPENAL_CreateSound(const char* name, bool b3D, OPENAL_BUFFER **buffer) { ov_clear(&oggFile); alGenBuffers(1, &(*buffer)->id); + ALenum al_error = alGetError(); + if (al_error != AL_NO_ERROR) { + printlog("OpenAL error: %d\n", al_error); + } alBufferData((*buffer)->id, (channels==1)?AL_FORMAT_MONO16:AL_FORMAT_STEREO16, data2, sz, freq); + ALenum al_error2 = alGetError(); + if (al_error2 != AL_NO_ERROR) { + printlog("OpenAL error: %d\n", al_error2); + } if(data2!=data) free(data2); free(data); @@ -1088,9 +1095,14 @@ void OPENAL_Sound_GetLength(OPENAL_BUFFER* buffer, unsigned int *length) { void OPENAL_Sound_Release(OPENAL_BUFFER* buffer) { if(!buffer) return; - if(!buffer->stream) + if(!buffer->stream) { alDeleteBuffers( 1, &buffer->id ); - free(buffer); + ALenum error = alGetError(); + if (error != AL_NO_ERROR) { + printlog("[OpenAL] error in alDeleteBuffers %d\n", error); + } + } + //free(buffer); } #else // No FMOD or OpenAL @@ -1243,6 +1255,42 @@ FMOD_RESULT physfsReloadMusic_helper_reloadMusicArray(uint32_t numMusic, const c return FMOD_OK; } +#elif defined USE_OPENAL +void physfsReloadMusic_helper_reloadMusicArray(uint32_t numMusic, const char* filenameTemplate, OPENAL_BUFFER** musicArray, bool reloadAll) +{ + for ( int c = 0; c < numMusic; c++ ) + { + snprintf(tempstr, 1000, filenameTemplate, c); + if ( PHYSFS_exists(tempstr) ) + { + printlog("[PhysFS]: Loading music file %s...", tempstr); + if ( musicArray ) + { + OPENAL_Sound_Release(musicArray[c]); + //musicArray[c]->release(); + } + if ( musicPreload ) + { + OPENAL_CreateSound(tempstr, false, &musicArray[c]); + //fmod_result = fmod_system->createSound(musicDir.c_str(), FMOD_2D, nullptr, &musicArray[c]); //TODO: Any other FMOD_MODEs should be used here? FMOD_SOFTWARE -> what now? FMOD_2D? LOOP? + } + else + { + OPENAL_CreateStreamSound(tempstr, &musicArray[c]); + //fmod_result = fmod_system->createStream(musicDir.c_str(), FMOD_2D, nullptr, &musicArray[c]); //TODO: Any other FMOD_MODEs should be used here? FMOD_SOFTWARE -> what now? FMOD_2D? LOOP? + } + ALenum al_error2 = alGetError(); + /*if (fmod_result != FMOD_OK) + { + printlog("[PhysFS]: ERROR: Failed reloading music file \"%s\"."); + return; + }*/ + + } else { + printlog("[PhysFS]: fail to load music file %s...", tempstr); + } + } +} #endif void physfsReloadMusic(bool &introMusicChanged, bool reloadAll) //TODO: This should probably return an error. @@ -1277,14 +1325,7 @@ void physfsReloadMusic(bool &introMusicChanged, bool reloadAll) //TODO: This sho themeMusic.push_back("sound/ui/StoryMusicV3.ogg"); int index = 0; -#ifdef USE_OPENAL -#define FMOD_System_CreateStream(A, B, C, D, E) OPENAL_CreateStreamSound(B, E) //TODO: If this is still needed, it's probably now broke! -#define FMOD_SOUND OPENAL_BUFFER -#define fmod_system 0 -#define FMOD_SOFTWARE 0 -#define FMOD_Sound_Release OPENAL_Sound_Release int fmod_result; -#endif for ( std::vector::iterator it = themeMusic.begin(); it != themeMusic.end(); ++it ) { std::string filename = *it; @@ -1300,8 +1341,13 @@ void physfsReloadMusic(bool &introMusicChanged, bool reloadAll) //TODO: This sho case 0: if ( introductionmusic ) { +#ifdef USE_FMOD introductionmusic->release(); +#else + OPENAL_Sound_Release(introductionmusic); +#endif } +#ifdef USE_FMOD if ( musicPreload ) { fmod_result = fmod_system->createSound(musicDir.c_str(), FMOD_2D, nullptr, &introductionmusic); //TODO: FMOD_SOFTWARE -> what now? FMOD_2D? FMOD_LOOP_NORMAL? More things? Something else? @@ -1310,7 +1356,11 @@ void physfsReloadMusic(bool &introMusicChanged, bool reloadAll) //TODO: This sho { fmod_result = fmod_system->createStream(musicDir.c_str(), FMOD_2D, nullptr, &introductionmusic); //TODO: FMOD_SOFTWARE -> what now? FMOD_2D? FMOD_LOOP_NORMAL? More things? Something else? } +#elif defined USE_OPENAL + OPENAL_CreateStreamSound(musicDir.c_str(), &introductionmusic); +#endif break; +/* case 1: if ( intermissionmusic ) { @@ -1338,8 +1388,9 @@ void physfsReloadMusic(bool &introMusicChanged, bool reloadAll) //TODO: This sho { fmod_result = fmod_system->createStream(musicDir.c_str(), FMOD_2D, nullptr, &minetownmusic); } - break; + break;*/ case 3: +#ifdef USE_FMOD if ( splashmusic ) { splashmusic->release(); @@ -1352,7 +1403,14 @@ void physfsReloadMusic(bool &introMusicChanged, bool reloadAll) //TODO: This sho { fmod_result = fmod_system->createStream(musicDir.c_str(), FMOD_2D, nullptr, &splashmusic); } +#elif defined USE_OPENAL + if ( splashmusic ) { + OPENAL_Sound_Release(splashmusic); + } + OPENAL_CreateStreamSound(musicDir.c_str(), &splashmusic); +#endif break; + /* case 4: if ( librarymusic ) { @@ -1591,63 +1649,39 @@ void physfsReloadMusic(bool &introMusicChanged, bool reloadAll) //TODO: This sho fmod_result = fmod_system->createStream(musicDir.c_str(), FMOD_DEFAULT, nullptr, &introstorymusic); } break; +*/ default: break; } +#ifdef USE_FMOD if ( FMODErrorCheck() ) { printlog("[PhysFS]: ERROR: Failed reloading music file \"%s\".", filename.c_str()); //TODO: Handle error? Abort? Fling pies at people? } +#endif } } ++index; } - int c; - FMOD::Sound** music = nullptr; - - if (FMOD_OK != (fmod_result = physfsReloadMusic_helper_reloadMusicArray(NUMMINESMUSIC, "music/mines%02d.ogg", minesmusic, reloadAll)) ) - { - printlog("[PhysFS]: Failed to reload mines music array."); - //TODO: Handle error? Abort? Fling pies at people? - } - if (FMOD_OK != (fmod_result = physfsReloadMusic_helper_reloadMusicArray(NUMSWAMPMUSIC, "music/swamp%02d.ogg", swampmusic, reloadAll)) ) - { - printlog("[PhysFS]: Failed to reload swamp music array."); - } - if (FMOD_OK != (fmod_result = physfsReloadMusic_helper_reloadMusicArray(NUMLABYRINTHMUSIC, "music/labyrinth%02d.ogg", labyrinthmusic, reloadAll)) ) - { - printlog("[PhysFS]: Failed to reload labyrinth music array."); - } - if (FMOD_OK != (fmod_result = physfsReloadMusic_helper_reloadMusicArray(NUMRUINSMUSIC, "music/ruins%02d.ogg", ruinsmusic, reloadAll)) ) - { - printlog("[PhysFS]: Failed to reload ruins music array."); - } - if (FMOD_OK != (fmod_result = physfsReloadMusic_helper_reloadMusicArray(NUMUNDERWORLDMUSIC, "music/underworld%02d.ogg", underworldmusic, reloadAll)) ) - { - printlog("[PhysFS]: Failed to reload underworld music array."); - } - if (FMOD_OK != (fmod_result = physfsReloadMusic_helper_reloadMusicArray(NUMHELLMUSIC, "music/hell%02d.ogg", hellmusic, reloadAll)) ) - { - printlog("[PhysFS]: Failed to reload hell music array."); - } - if (FMOD_OK != (fmod_result = physfsReloadMusic_helper_reloadMusicArray(NUMMINOTAURMUSIC, "music/minotaur%02d.ogg", minotaurmusic, reloadAll)) ) - { - printlog("[PhysFS]: Failed to reload minotaur music array."); - } - if (FMOD_OK != (fmod_result = physfsReloadMusic_helper_reloadMusicArray(NUMCAVESMUSIC, "music/caves%02d.ogg", cavesmusic, reloadAll)) ) - { - printlog("[PhysFS]: Failed to reload caves music array."); - } - if (FMOD_OK != (fmod_result = physfsReloadMusic_helper_reloadMusicArray(NUMCITADELMUSIC, "music/citadel%02d.ogg", citadelmusic, reloadAll)) ) - { - printlog("[PhysFS]: Failed to reload citadel music array."); - } + physfsReloadMusic_helper_reloadMusicArray(NUMMINESMUSIC, "music/mines%02d.ogg", minesmusic, reloadAll); + physfsReloadMusic_helper_reloadMusicArray(NUMSWAMPMUSIC, "music/swamp%02d.ogg", swampmusic, reloadAll); + physfsReloadMusic_helper_reloadMusicArray(NUMLABYRINTHMUSIC, "music/labyrinth%02d.ogg", labyrinthmusic, reloadAll); + physfsReloadMusic_helper_reloadMusicArray(NUMRUINSMUSIC, "music/ruins%02d.ogg", ruinsmusic, reloadAll); + physfsReloadMusic_helper_reloadMusicArray(NUMUNDERWORLDMUSIC, "music/underworld%02d.ogg", underworldmusic, reloadAll); + physfsReloadMusic_helper_reloadMusicArray(NUMHELLMUSIC, "music/hell%02d.ogg", hellmusic, reloadAll); + physfsReloadMusic_helper_reloadMusicArray(NUMMINOTAURMUSIC, "music/minotaur%02d.ogg", minotaurmusic, reloadAll); + physfsReloadMusic_helper_reloadMusicArray(NUMCAVESMUSIC, "music/caves%02d.ogg", cavesmusic, reloadAll); + physfsReloadMusic_helper_reloadMusicArray(NUMCITADELMUSIC, "music/citadel%02d.ogg", citadelmusic, reloadAll); bool introChanged = false; - - for ( c = 0; c < NUMINTROMUSIC; c++ ) +#ifdef USE_FMOD + FMOD::Sound** music = nullptr; +#else + OPENAL_BUFFER** music = nullptr; +#endif + for ( int c = 0; c < NUMINTROMUSIC; c++ ) { if ( c == 0 ) { @@ -1667,36 +1701,35 @@ void physfsReloadMusic(bool &introMusicChanged, bool reloadAll) //TODO: This sho music = intromusic; if ( music ) { +#ifdef USE_FMOD music[c]->release(); +#elif defined USE_OPENAL + OPENAL_Sound_Release(music[c]); +#endif } if ( musicPreload ) { - fmod_result = fmod_system->createSound(musicDir.c_str(), FMOD_2D, nullptr, &music[c]); + //fmod_result = fmod_system->createSound(musicDir.c_str(), FMOD_2D, nullptr, &music[c]); + physfsReloadMusic_helper_reloadMusicArray(NUMINTROMUSIC, "music/intro%02d.ogg", music, reloadAll); } else { - fmod_result = fmod_system->createStream(musicDir.c_str(), FMOD_2D, nullptr, &music[c]); + //fmod_result = fmod_system->createStream(musicDir.c_str(), FMOD_2D, nullptr, &music[c]); + physfsReloadMusic_helper_reloadMusicArray(NUMINTROMUSIC, "music/intro%02d.ogg", music, reloadAll); } introChanged = true; - if (fmod_result != FMOD_OK) + /*if (fmod_result != FMOD_OK) { printlog("[PhysFS]: ERROR: Failed reloading music file \"%s\"."); break; //TODO: Handle the error? - } + }*/ } } } introMusicChanged = introChanged; // use this variable outside of this function to start playing a new fresh list of tracks in the main menu. -#ifdef USE_OPENAL -#undef FMOD_System_CreateStream -#undef FMOD_SOUND -#undef fmod_system -#undef FMOD_SOFTWARE -#undef FMOD_Sound_Release -#endif -#endif // SOUND +#endif // MUSIC } /** diff --git a/src/engine/audio/sound.hpp b/src/engine/audio/sound.hpp index f2ccbe1a4..c511927df 100644 --- a/src/engine/audio/sound.hpp +++ b/src/engine/audio/sound.hpp @@ -139,8 +139,7 @@ extern bool sfxUseDynamicAmbientVolume, sfxUseDynamicEnvironmentVolume; #elif defined USE_OPENAL #define SOUND -// for now we disable music -//#define MUSIC +#define MUSIC struct OPENAL_BUFFER { ALuint id; @@ -230,7 +229,10 @@ extern OPENAL_BUFFER* hamletmusic; extern OPENAL_SOUND* music_channel, *music_channel2, *music_resume; //TODO: List of music, play first one, fade out all the others? Eh, maybe some other day. //music_resume is the music to resume after, say, combat or shops. //TODO: Clear music_resume every biome change. Or otherwise validate it for that level set. extern OPENAL_CHANNELGROUP *sound_group, *music_group; -extern OPENAL_CHANNELGROUP *soundAmbient_group, *soundEnvironment_group, *music_notification_group; +extern OPENAL_CHANNELGROUP *soundAmbient_group; +extern OPENAL_CHANNELGROUP *soundEnvironment_group; +extern OPENAL_CHANNELGROUP *soundNotification_group; +extern OPENAL_CHANNELGROUP *music_notification_group; int initOPENAL(); int closeOPENAL(); diff --git a/src/engine/audio/sound_game.cpp b/src/engine/audio/sound_game.cpp index 571e773af..a6682320e 100644 --- a/src/engine/audio/sound_game.cpp +++ b/src/engine/audio/sound_game.cpp @@ -707,389 +707,6 @@ extern bool sanctummusicplaying; extern int currenttrack; -void handleLevelMusic() -{ - if (no_sound) - { - return; - } -#ifndef SOUND - return; -#endif -#ifndef MUSIC - return; -#endif - bool inshop = false; - if (players[clientnum] && players[clientnum]->entity) - { - int x = (int)players[clientnum]->entity->x / 16; - int y = (int)players[clientnum]->entity->y / 16; - if ( x >= 0 && x < map.width && y >= 0 && y < map.height ) - if ( shoparea[y + x * map.height] ) - { - inshop = true; - } - } - - bool devilaround = false; - bool activeminotaur = false; - bool herxaround = false; - bool magisteraround = false; - node_t* node; - for ( node = map.creatures->first; node != NULL; node = node->next ) - { - Entity* entity = (Entity*)node->element; - if ( entity->sprite == 274 ) // herx head - { - herxaround = true; - break; - } - else if ( entity->sprite == 304 ) // devil body - { - devilaround = true; - break; - } - else if ( entity->sprite == 239 ) // minotaur head - { - activeminotaur = true; - break; - } - else if ( entity->sprite == 646 || entity->sprite == 650 ) // magister body - { - magisteraround = true; - break; - } - } - - ALboolean playing = true; - OPENAL_Channel_IsPlaying(music_channel, &playing); - - if ( currenttrack == -1 ) - { - currenttrack = local_rng.rand(); - } - - if ( (!levelmusicplaying || !playing || olddarkmap != darkmap) - && (!combat || !strcmp(map.name, "Hell Boss")) - && !inshop - && (!activeminotaur || !strcmp(map.name, "Hell Boss")) && !herxaround && !devilaround && !magisteraround ) - { - if ( !strncmp(map.name, "The Mines", 9) ) // the mines - { - if ( !playing ) - { - currenttrack = 1 + local_rng.rand() % (NUMMINESMUSIC - 1); - } - currenttrack = currenttrack % NUMMINESMUSIC; - if ( currenttrack == 0 ) - { - currenttrack = 1; - } - playMusic(minesmusic[currenttrack], false, true, true); - } - else if ( !strncmp(map.name, "The Swamp", 9) ) // the swamp - { - if ( !playing ) - { - currenttrack = 1 + local_rng.rand() % (NUMSWAMPMUSIC - 1); - } - currenttrack = currenttrack % NUMSWAMPMUSIC; - if ( currenttrack == 0 ) - { - currenttrack = 1; - } - playMusic(swampmusic[currenttrack], false, true, true); - } - else if ( !strncmp(map.name, "The Labyrinth", 13) ) // the labyrinth - { - if ( !playing ) - { - currenttrack = 1 + local_rng.rand() % (NUMLABYRINTHMUSIC - 1); - } - currenttrack = currenttrack % NUMLABYRINTHMUSIC; - if ( currenttrack == 0 ) - { - currenttrack = 1; - } - playMusic(labyrinthmusic[currenttrack], false, true, true); - } - else if ( !strncmp(map.name, "The Ruins", 9) ) // the ruins - { - if ( !playing ) - { - currenttrack = 1 + local_rng.rand() % (NUMRUINSMUSIC - 1); - } - currenttrack = currenttrack % NUMRUINSMUSIC; - if ( currenttrack == 0 ) - { - currenttrack = 1; - } - playMusic(ruinsmusic[currenttrack], false, true, true); - } - else if ( !strncmp(map.name, "Underworld", 10) ) // the underworld - { - if ( !playing ) - { - currenttrack = 1 + local_rng.rand() % (NUMUNDERWORLDMUSIC - 1); - } - currenttrack = currenttrack % NUMUNDERWORLDMUSIC; - if ( currenttrack == 0 ) - { - currenttrack = 1; - } - playMusic(underworldmusic[currenttrack], false, true, true); - } - else if ( !strcmp(map.name, "Minetown") ) // minetown - { - playMusic(minetownmusic, true, true, true); - } - else if ( !strcmp(map.name, "The Gnomish Mines") ) - { - if ( gnomishminesmusic ) - { - playMusic(gnomishminesmusic, true, true, true); - } - else - { - playMusic(minetownmusic, true, true, true); - } - } - else if ( !strcmp(map.name, "The Haunted Castle") ) - { - if ( greatcastlemusic ) - { - playMusic(greatcastlemusic, true, true, true); - } - else - { - playMusic(intermissionmusic, true, true, true); - } - } - else if ( !strcmp(map.name, "Sokoban") ) - { - if ( sokobanmusic ) - { - playMusic(sokobanmusic, true, true, true); - } - else - { - playMusic(intermissionmusic, true, true, true); - } - } - else if ( !strcmp(map.name, "Cockatrice Lair") ) - { - if ( caveslairmusic ) - { - playMusic(caveslairmusic, true, true, true); - } - else - { - playMusic(cavesmusic[2], true, true, true); - } - } - else if ( !strcmp(map.name, "Bram's Castle") ) - { - if ( bramscastlemusic ) - { - playMusic(bramscastlemusic, true, true, true); - } - else - { - playMusic(citadelmusic[2], true, true, true); - } - } - else if ( !strcmp(map.name, "The Mystic Library") ) // mystic library - { - playMusic(librarymusic, true, true, true); - } - else if ( !strcmp(map.name, "The Minotaur Maze") ) // minotaur maze - { - playMusic(minotaurmusic[1], true, true, true); - } - else if ( !strcmp(map.name, "The Temple") ) // the temple - { - playMusic(templemusic, true, true, true); - } - else if ( !strcmp(map.name, "Hell Boss") ) // escape theme - { - playMusic(escapemusic, true, true, true); - } - else if ( !strncmp(map.name, "Hell", 4) ) // hell - { - if ( !playing ) - { - currenttrack = 1 + local_rng.rand() % (NUMHELLMUSIC - 1); - } - currenttrack = currenttrack % NUMHELLMUSIC; - if ( currenttrack == 0 ) - { - currenttrack = 1; - } - playMusic(hellmusic[currenttrack], false, true, true); - } - else if ( !strncmp(map.name, "Caves", 5) ) - { - if ( !playing ) - { - currenttrack = 1 + local_rng.rand() % (NUMCAVESMUSIC - 1); - } - currenttrack = currenttrack % NUMCAVESMUSIC; - if ( currenttrack == 0 ) - { - currenttrack = 1; - } - playMusic(cavesmusic[currenttrack], false, true, true); - } - else if ( !strncmp(map.name, "Citadel", 7) || !strncmp(map.name, "Sanctum", 7) ) - { - if ( !playing ) - { - currenttrack = 1 + local_rng.rand() % (NUMCITADELMUSIC - 1); - } - currenttrack = currenttrack % NUMCITADELMUSIC; - if ( currenttrack == 0 ) - { - currenttrack = 1; - } - playMusic(citadelmusic[currenttrack], false, true, true); - } - else if ( !strcmp(map.name, "Mages Guild") ) - { - if ( hamletmusic ) - { - playMusic(hamletmusic, true, true, true); - } - else - { - playMusic(minesmusic[4], true, true, true); - } - } - else - { - playMusic(intermissionmusic, true, true, true); - } - olddarkmap = darkmap; - levelmusicplaying = true; - devilmusicplaying = false; - herxmusicplaying = false; - minotaurmusicplaying = false; - combatmusicplaying = false; - shopmusicplaying = false; - fadein_increment = default_fadein_increment; - fadeout_increment = default_fadeout_increment; - } - else if ( (!devilmusicplaying || !playing) && devilaround ) - { - playMusic(devilmusic, true, true, true); - levelmusicplaying = false; - devilmusicplaying = true; - herxmusicplaying = false; - minotaurmusicplaying = false; - combatmusicplaying = false; - shopmusicplaying = false; - fadein_increment = default_fadein_increment * 2; - fadeout_increment = default_fadeout_increment * 2; - } - else if ( (!herxmusicplaying || !playing) && !devilaround && herxaround ) - { - playMusic(herxmusic, true, true, true); - levelmusicplaying = false; - devilmusicplaying = false; - herxmusicplaying = true; - minotaurmusicplaying = false; - combatmusicplaying = false; - shopmusicplaying = false; - fadein_increment = default_fadein_increment * 2; - fadeout_increment = default_fadeout_increment * 2; - } - else if ( (!minotaurmusicplaying || !playing) && !herxaround && activeminotaur && strcmp(map.name, "Hell Boss") ) - { - playMusic(minotaurmusic[0], true, true, true); - levelmusicplaying = false; - devilmusicplaying = false; - herxmusicplaying = false; - minotaurmusicplaying = true; - combatmusicplaying = false; - shopmusicplaying = false; - fadein_increment = default_fadein_increment * 5; - fadeout_increment = default_fadeout_increment * 5; - } - else if ( (!sanctummusicplaying || !playing) && magisteraround ) - { - playMusic(sanctummusic, true, true, true); - levelmusicplaying = false; - devilmusicplaying = false; - herxmusicplaying = false; - minotaurmusicplaying = false; - combatmusicplaying = false; - sanctummusicplaying = true; - shopmusicplaying = false; - fadein_increment = default_fadein_increment * 2; - fadeout_increment = default_fadeout_increment * 2; - } - else if ( (!combatmusicplaying || !playing) - && !herxaround - && !activeminotaur - && combat - && strcmp(map.name, "Hell Boss") - && strcmp(map.name, "Sanctum") ) - { - if ( !strncmp(map.name, "The Swamp", 9) || !strncmp(map.name, "The Temple", 10) ) // the swamp - { - playMusic(swampmusic[0], true, true, true); - } - else if ( !strncmp(map.name, "The Labyrinth", 13) || strstr(map.name, "Minotaur") ) // the labyrinth - { - playMusic(labyrinthmusic[0], true, true, true); - } - else if ( !strncmp(map.name, "The Ruins", 9) ) // the ruins - { - playMusic(ruinsmusic[0], true, true, true); - } - else if ( !strncmp(map.name, "Underworld", 10) ) // the underworld - { - playMusic(underworldmusic[0], true, true, true); - } - else if ( !strncmp(map.name, "Hell", 4) ) // hell - { - playMusic(hellmusic[0], true, true, true); - } - else if ( !strncmp(map.name, "Caves", 5) || !strcmp(map.name, "Cockatrice Lair") ) - { - playMusic(cavesmusic[0], true, true, true); - } - else if ( !strncmp(map.name, "Citadel", 7) || !strcmp(map.name, "Bram's Castle") ) - { - playMusic(citadelmusic[0], true, true, true); - } - else - { - playMusic(minesmusic[0], true, true, true); - } - levelmusicplaying = false; - devilmusicplaying = false; - herxmusicplaying = false; - combatmusicplaying = true; - shopmusicplaying = false; - minotaurmusicplaying = false; - fadein_increment = default_fadein_increment * 4; - fadeout_increment = default_fadeout_increment; - } - else if ( (!shopmusicplaying || !playing) && !herxaround && !activeminotaur && !combat && inshop ) - { - playMusic(shopmusic, true, true, true); - levelmusicplaying = false; - devilmusicplaying = false; - herxmusicplaying = false; - minotaurmusicplaying = false; - combatmusicplaying = false; - shopmusicplaying = true; - fadein_increment = default_fadein_increment * 4; - fadeout_increment = default_fadeout_increment; - } -} - - #else /*------------------------------------------------------------------------------- diff --git a/src/game.cpp b/src/game.cpp index 97cc80579..e78a514d5 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -1906,6 +1906,10 @@ void gameLogic(void) { OPENAL_ChannelGroup_Stop(soundEnvironment_group); } + if ( soundNotification_group ) + { + OPENAL_ChannelGroup_Stop(soundNotification_group); + } #endif // stop combat music // close chests diff --git a/src/init_game.cpp b/src/init_game.cpp index 1146d7dfb..f9e3058c1 100644 --- a/src/init_game.cpp +++ b/src/init_game.cpp @@ -658,6 +658,20 @@ void deinitGame() } #elif defined USE_OPENAL // TODO: unload OpenAL resources + OPENAL_Channel_Stop(sound_group); + OPENAL_Channel_Stop(soundAmbient_group); + OPENAL_Channel_Stop(soundEnvironment_group); + OPENAL_Channel_Stop(soundNotification_group); + OPENAL_Channel_Stop(music_group); + OPENAL_Channel_Stop(music_notification_group); + for ( int c = 0; c < NUMINTROMUSIC; c++ ) + { + OPENAL_Sound_Release(intromusic[c]); + } + if ( intromusic ) + { + free(intromusic); + } #endif } diff --git a/src/menu.cpp b/src/menu.cpp index c9d4c276e..4cea53ee4 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -8751,6 +8751,10 @@ void doNewGame(bool makeHighscore) { { OPENAL_ChannelGroup_Stop(soundEnvironment_group); } + if ( soundNotification_group ) + { + OPENAL_ChannelGroup_Stop(soundNotification_group); + } #endif if ( !loadingsavegame ) @@ -9211,6 +9215,10 @@ void doNewGame(bool makeHighscore) { { OPENAL_ChannelGroup_Stop(soundEnvironment_group); } + if ( soundNotification_group ) + { + OPENAL_ChannelGroup_Stop(soundNotification_group); + } #endif // load next level entity_uids = 1; @@ -9610,6 +9618,10 @@ void doEndgame(bool saveHighscore) { { OPENAL_ChannelGroup_Stop(soundEnvironment_group); } + if ( soundNotification_group ) + { + OPENAL_ChannelGroup_Stop(soundNotification_group); + } #endif // send disconnect messages From 56814500632da597085e98e0db2c14fba8c3ace8 Mon Sep 17 00:00:00 2001 From: damiencarol Date: Fri, 8 Mar 2024 18:12:35 +0100 Subject: [PATCH 17/24] Fix silly required include --- src/engine/audio/defines.cpp | 2 +- src/engine/audio/sound.hpp | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/engine/audio/defines.cpp b/src/engine/audio/defines.cpp index f6eed9739..4b6a2e3b6 100644 --- a/src/engine/audio/defines.cpp +++ b/src/engine/audio/defines.cpp @@ -9,7 +9,7 @@ -------------------------------------------------------------------------------*/ -#include +#include "../../main.hpp" #include "sound.hpp" Uint32 numsounds = 0; diff --git a/src/engine/audio/sound.hpp b/src/engine/audio/sound.hpp index c511927df..aa051cf6e 100644 --- a/src/engine/audio/sound.hpp +++ b/src/engine/audio/sound.hpp @@ -11,6 +11,8 @@ #pragma once +#include "../../main.hpp" + #define FMOD_AUDIO_GUID_FMT "%.8x%.16llx" #include From ba6e5bcea1a04865965487f39c2236ab99065dc5 Mon Sep 17 00:00:00 2001 From: damiencarol Date: Sat, 9 Mar 2024 18:11:35 +0100 Subject: [PATCH 18/24] Add more musics --- src/engine/audio/sound.cpp | 18 ++++++++++++++++-- src/init_game.cpp | 18 ++++++++++++------ 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/src/engine/audio/sound.cpp b/src/engine/audio/sound.cpp index 4727710a2..0fc6d9e0e 100644 --- a/src/engine/audio/sound.cpp +++ b/src/engine/audio/sound.cpp @@ -1360,8 +1360,9 @@ void physfsReloadMusic(bool &introMusicChanged, bool reloadAll) //TODO: This sho OPENAL_CreateStreamSound(musicDir.c_str(), &introductionmusic); #endif break; -/* + case 1: +#ifdef USE_FMOD if ( intermissionmusic ) { intermissionmusic->release(); @@ -1374,8 +1375,15 @@ void physfsReloadMusic(bool &introMusicChanged, bool reloadAll) //TODO: This sho { fmod_result = fmod_system->createStream(musicDir.c_str(), FMOD_2D, nullptr, &intermissionmusic); } +#elif defined USE_OPENAL + if ( intermissionmusic ) { + OPENAL_Sound_Release(intermissionmusic); + } + OPENAL_CreateStreamSound(musicDir.c_str(), &intermissionmusic); +#endif break; case 2: +#ifdef USE_FMOD if ( minetownmusic ) { minetownmusic->release(); @@ -1388,7 +1396,13 @@ void physfsReloadMusic(bool &introMusicChanged, bool reloadAll) //TODO: This sho { fmod_result = fmod_system->createStream(musicDir.c_str(), FMOD_2D, nullptr, &minetownmusic); } - break;*/ +#elif defined USE_OPENAL + if ( minetownmusic ) { + OPENAL_Sound_Release(minetownmusic); + } + OPENAL_CreateStreamSound(musicDir.c_str(), &minetownmusic); +#endif + break; case 3: #ifdef USE_FMOD if ( splashmusic ) diff --git a/src/init_game.cpp b/src/init_game.cpp index f9e3058c1..2da6e5ce6 100644 --- a/src/init_game.cpp +++ b/src/init_game.cpp @@ -658,12 +658,18 @@ void deinitGame() } #elif defined USE_OPENAL // TODO: unload OpenAL resources - OPENAL_Channel_Stop(sound_group); - OPENAL_Channel_Stop(soundAmbient_group); - OPENAL_Channel_Stop(soundEnvironment_group); - OPENAL_Channel_Stop(soundNotification_group); - OPENAL_Channel_Stop(music_group); - OPENAL_Channel_Stop(music_notification_group); + OPENAL_Channel_Stop(music_channel); + OPENAL_Channel_Stop(music_channel2); + OPENAL_Sound_Release(introductionmusic); + OPENAL_Sound_Release(intermissionmusic); + for ( int c = 0; c < NUMCITADELMUSIC; c++ ) + { + OPENAL_Sound_Release(citadelmusic[c]); + } + if ( citadelmusic ) + { + free(citadelmusic); + } for ( int c = 0; c < NUMINTROMUSIC; c++ ) { OPENAL_Sound_Release(intromusic[c]); From c934ed6c6a2ede8293195520eeb16132ec82aede Mon Sep 17 00:00:00 2001 From: damiencarol Date: Sat, 9 Mar 2024 22:22:54 +0100 Subject: [PATCH 19/24] Fix compilation error when no sound --- src/engine/audio/sound.cpp | 28 +++++++++++++++++++++------- src/ui/MainMenu.cpp | 8 +++++--- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/src/engine/audio/sound.cpp b/src/engine/audio/sound.cpp index 0fc6d9e0e..515d517cd 100644 --- a/src/engine/audio/sound.cpp +++ b/src/engine/audio/sound.cpp @@ -1102,7 +1102,7 @@ void OPENAL_Sound_Release(OPENAL_BUFFER* buffer) { printlog("[OpenAL] error in alDeleteBuffers %d\n", error); } } - //free(buffer); + free(buffer); } #else // No FMOD or OpenAL @@ -1339,15 +1339,12 @@ void physfsReloadMusic(bool &introMusicChanged, bool reloadAll) //TODO: This sho switch ( index ) { case 0: +#ifdef USE_FMOD if ( introductionmusic ) { -#ifdef USE_FMOD introductionmusic->release(); -#else - OPENAL_Sound_Release(introductionmusic); -#endif + } -#ifdef USE_FMOD if ( musicPreload ) { fmod_result = fmod_system->createSound(musicDir.c_str(), FMOD_2D, nullptr, &introductionmusic); //TODO: FMOD_SOFTWARE -> what now? FMOD_2D? FMOD_LOOP_NORMAL? More things? Something else? @@ -1357,6 +1354,9 @@ void physfsReloadMusic(bool &introMusicChanged, bool reloadAll) //TODO: This sho fmod_result = fmod_system->createStream(musicDir.c_str(), FMOD_2D, nullptr, &introductionmusic); //TODO: FMOD_SOFTWARE -> what now? FMOD_2D? FMOD_LOOP_NORMAL? More things? Something else? } #elif defined USE_OPENAL + if ( introductionmusic ) { + OPENAL_Sound_Release(introductionmusic); + } OPENAL_CreateStreamSound(musicDir.c_str(), &introductionmusic); #endif break; @@ -1424,8 +1424,8 @@ void physfsReloadMusic(bool &introMusicChanged, bool reloadAll) //TODO: This sho OPENAL_CreateStreamSound(musicDir.c_str(), &splashmusic); #endif break; - /* case 4: +#ifdef USE_FMOD if ( librarymusic ) { librarymusic->release(); @@ -1438,8 +1438,15 @@ void physfsReloadMusic(bool &introMusicChanged, bool reloadAll) //TODO: This sho { fmod_result = fmod_system->createStream(musicDir.c_str(), FMOD_2D, nullptr, &librarymusic); } +#elif defined USE_OPENAL + if ( librarymusic ) { + OPENAL_Sound_Release(librarymusic); + } + OPENAL_CreateStreamSound(musicDir.c_str(), &librarymusic); +#endif break; case 5: +#ifdef USE_FMOD if ( shopmusic ) { shopmusic->release(); @@ -1452,7 +1459,14 @@ void physfsReloadMusic(bool &introMusicChanged, bool reloadAll) //TODO: This sho { fmod_result = fmod_system->createStream(musicDir.c_str(), FMOD_2D, nullptr, &shopmusic); } +#elif defined USE_OPENAL + if ( shopmusic ) { + OPENAL_Sound_Release(shopmusic); + } + OPENAL_CreateStreamSound(musicDir.c_str(), &shopmusic); +#endif break; +/* case 6: if ( herxmusic ) { diff --git a/src/ui/MainMenu.cpp b/src/ui/MainMenu.cpp index 41403e8ef..a70688c57 100644 --- a/src/ui/MainMenu.cpp +++ b/src/ui/MainMenu.cpp @@ -6392,7 +6392,7 @@ namespace MainMenu { y += settingsAddDropdown(*settings_subwindow, y, "speaker_mode", Language::get(6140), Language::get(6150), true, modes_ptrs, modes_ptrs[allSettings.speaker_mode], settingsAudioSpeakerMode); } -#else +#elif defined USE_OPENAL audio_drivers.clear(); if (alcIsExtensionPresent(NULL, "ALC_ENUMERATION_EXT") == AL_TRUE) { // Enumeration Extension Found @@ -6412,7 +6412,7 @@ namespace MainMenu { printlog("device detected: %s", device); AudioDriver d; - memcpy(d.name, device, len); + memcpy(d.name, device, len+1); audio_drivers.push_back(d); //fprintf(stdout, "%s\n", device); @@ -6427,7 +6427,9 @@ namespace MainMenu { } // debug - drivers_formatted_ptrs.push_back("Test"); + drivers_formatted_ptrs.push_back(alGetString(AL_VENDOR)); + drivers_formatted_ptrs.push_back(alGetString(AL_RENDERER)); + drivers_formatted_ptrs.push_back(alGetString(AL_VERSION)); // add section "output" y += settingsAddSubHeader(*settings_subwindow, y, "output", Language::get(5182)); From 90e2f4c5f0c71af1c3f5aefdf7c046783315cd34 Mon Sep 17 00:00:00 2001 From: damiencarol Date: Sat, 9 Mar 2024 22:36:38 +0100 Subject: [PATCH 20/24] more fixes --- src/engine/audio/defines.cpp | 1 + src/engine/audio/sound.cpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/engine/audio/defines.cpp b/src/engine/audio/defines.cpp index 4b6a2e3b6..20f273faa 100644 --- a/src/engine/audio/defines.cpp +++ b/src/engine/audio/defines.cpp @@ -79,6 +79,7 @@ bool sfxUseDynamicAmbientVolume = true; bool sfxUseDynamicEnvironmentVolume = true; void* fmod_extraDriverData = nullptr; + #elif defined USE_OPENAL diff --git a/src/engine/audio/sound.cpp b/src/engine/audio/sound.cpp index 515d517cd..95b3fff81 100644 --- a/src/engine/audio/sound.cpp +++ b/src/engine/audio/sound.cpp @@ -1102,7 +1102,7 @@ void OPENAL_Sound_Release(OPENAL_BUFFER* buffer) { printlog("[OpenAL] error in alDeleteBuffers %d\n", error); } } - free(buffer); + //free(buffer); } #else // No FMOD or OpenAL From fe6ebc4b3ac085d6ac02d922a90dee1f446d9f08 Mon Sep 17 00:00:00 2001 From: damiencarol Date: Tue, 12 Mar 2024 09:04:49 +0100 Subject: [PATCH 21/24] Add missing musics --- src/engine/audio/sound.cpp | 109 ++++++++++++++++++++++++++++++++++++- 1 file changed, 106 insertions(+), 3 deletions(-) diff --git a/src/engine/audio/sound.cpp b/src/engine/audio/sound.cpp index 95b3fff81..08fb1373e 100644 --- a/src/engine/audio/sound.cpp +++ b/src/engine/audio/sound.cpp @@ -1102,7 +1102,7 @@ void OPENAL_Sound_Release(OPENAL_BUFFER* buffer) { printlog("[OpenAL] error in alDeleteBuffers %d\n", error); } } - //free(buffer); + free(buffer); } #else // No FMOD or OpenAL @@ -1466,8 +1466,8 @@ void physfsReloadMusic(bool &introMusicChanged, bool reloadAll) //TODO: This sho OPENAL_CreateStreamSound(musicDir.c_str(), &shopmusic); #endif break; -/* case 6: +#ifdef USE_FMOD if ( herxmusic ) { herxmusic->release(); @@ -1480,8 +1480,15 @@ void physfsReloadMusic(bool &introMusicChanged, bool reloadAll) //TODO: This sho { fmod_result = fmod_system->createStream(musicDir.c_str(), FMOD_2D, nullptr, &herxmusic); } +#elif defined USE_OPENAL + if ( herxmusic ) { + OPENAL_Sound_Release(herxmusic); + } + OPENAL_CreateStreamSound(musicDir.c_str(), &herxmusic); +#endif break; case 7: +#ifdef USE_FMOD if ( templemusic ) { templemusic->release(); @@ -1494,8 +1501,15 @@ void physfsReloadMusic(bool &introMusicChanged, bool reloadAll) //TODO: This sho { fmod_result = fmod_system->createStream(musicDir.c_str(), FMOD_2D, nullptr, &templemusic); } +#elif defined USE_OPENAL + if ( templemusic ) { + OPENAL_Sound_Release(templemusic); + } + OPENAL_CreateStreamSound(musicDir.c_str(), &templemusic); +#endif break; case 8: +#ifdef USE_FMOD if ( endgamemusic ) { endgamemusic->release(); @@ -1508,8 +1522,15 @@ void physfsReloadMusic(bool &introMusicChanged, bool reloadAll) //TODO: This sho { fmod_result = fmod_system->createStream(musicDir.c_str(), FMOD_2D, nullptr, &endgamemusic); } +#elif defined USE_OPENAL + if ( endgamemusic ) { + OPENAL_Sound_Release(endgamemusic); + } + OPENAL_CreateStreamSound(musicDir.c_str(), &endgamemusic); +#endif break; case 9: +#ifdef USE_FMOD if ( escapemusic ) { escapemusic->release(); @@ -1522,8 +1543,15 @@ void physfsReloadMusic(bool &introMusicChanged, bool reloadAll) //TODO: This sho { fmod_result = fmod_system->createStream(musicDir.c_str(), FMOD_2D, nullptr, &escapemusic); } +#elif defined USE_OPENAL + if ( escapemusic ) { + OPENAL_Sound_Release(escapemusic); + } + OPENAL_CreateStreamSound(musicDir.c_str(), &escapemusic); +#endif break; case 10: +#ifdef USE_FMOD if ( devilmusic ) { devilmusic->release(); @@ -1536,8 +1564,15 @@ void physfsReloadMusic(bool &introMusicChanged, bool reloadAll) //TODO: This sho { fmod_result = fmod_system->createStream(musicDir.c_str(), FMOD_2D, nullptr, &devilmusic); } +#elif defined USE_OPENAL + if ( devilmusic ) { + OPENAL_Sound_Release(devilmusic); + } + OPENAL_CreateStreamSound(musicDir.c_str(), &devilmusic); +#endif break; case 11: +#ifdef USE_FMOD if ( sanctummusic ) { sanctummusic->release(); @@ -1550,8 +1585,15 @@ void physfsReloadMusic(bool &introMusicChanged, bool reloadAll) //TODO: This sho { fmod_result = fmod_system->createStream(musicDir.c_str(), FMOD_2D, nullptr, &sanctummusic); } +#elif defined USE_OPENAL + if ( sanctummusic ) { + OPENAL_Sound_Release(sanctummusic); + } + OPENAL_CreateStreamSound(musicDir.c_str(), &sanctummusic); +#endif break; case 12: +#ifdef USE_FMOD if ( gnomishminesmusic ) { gnomishminesmusic->release(); @@ -1564,8 +1606,15 @@ void physfsReloadMusic(bool &introMusicChanged, bool reloadAll) //TODO: This sho { fmod_result = fmod_system->createStream(musicDir.c_str(), FMOD_2D, nullptr, &gnomishminesmusic); } +#elif defined USE_OPENAL + if ( gnomishminesmusic ) { + OPENAL_Sound_Release(gnomishminesmusic); + } + OPENAL_CreateStreamSound(musicDir.c_str(), &gnomishminesmusic); +#endif break; case 13: +#ifdef USE_FMOD if ( greatcastlemusic ) { greatcastlemusic->release(); @@ -1578,8 +1627,15 @@ void physfsReloadMusic(bool &introMusicChanged, bool reloadAll) //TODO: This sho { fmod_result = fmod_system->createStream(musicDir.c_str(), FMOD_2D, nullptr, &greatcastlemusic); } +#elif defined USE_OPENAL + if ( greatcastlemusic ) { + OPENAL_Sound_Release(greatcastlemusic); + } + OPENAL_CreateStreamSound(musicDir.c_str(), &greatcastlemusic); +#endif break; case 14: +#ifdef USE_FMOD if ( sokobanmusic ) { sokobanmusic->release(); @@ -1592,8 +1648,15 @@ void physfsReloadMusic(bool &introMusicChanged, bool reloadAll) //TODO: This sho { fmod_result = fmod_system->createStream(musicDir.c_str(), FMOD_2D, nullptr, &sokobanmusic); } +#elif defined USE_OPENAL + if ( sokobanmusic ) { + OPENAL_Sound_Release(sokobanmusic); + } + OPENAL_CreateStreamSound(musicDir.c_str(), &sokobanmusic); +#endif break; case 15: +#ifdef USE_FMOD if ( caveslairmusic ) { caveslairmusic->release(); @@ -1606,8 +1669,15 @@ void physfsReloadMusic(bool &introMusicChanged, bool reloadAll) //TODO: This sho { fmod_result = fmod_system->createStream(musicDir.c_str(), FMOD_2D, nullptr, &caveslairmusic); } +#elif defined USE_OPENAL + if ( caveslairmusic ) { + OPENAL_Sound_Release(caveslairmusic); + } + OPENAL_CreateStreamSound(musicDir.c_str(), &caveslairmusic); +#endif break; case 16: +#ifdef USE_FMOD if ( bramscastlemusic ) { bramscastlemusic->release(); @@ -1620,8 +1690,15 @@ void physfsReloadMusic(bool &introMusicChanged, bool reloadAll) //TODO: This sho { fmod_result = fmod_system->createStream(musicDir.c_str(), FMOD_2D, nullptr, &bramscastlemusic); } +#elif defined USE_OPENAL + if ( bramscastlemusic ) { + OPENAL_Sound_Release(bramscastlemusic); + } + OPENAL_CreateStreamSound(musicDir.c_str(), &bramscastlemusic); +#endif break; case 17: +#ifdef USE_FMOD if ( hamletmusic ) { hamletmusic->release(); @@ -1634,8 +1711,15 @@ void physfsReloadMusic(bool &introMusicChanged, bool reloadAll) //TODO: This sho { fmod_result = fmod_system->createStream(musicDir.c_str(), FMOD_2D, nullptr, &hamletmusic); } +#elif defined USE_OPENAL + if ( hamletmusic ) { + OPENAL_Sound_Release(hamletmusic); + } + OPENAL_CreateStreamSound(musicDir.c_str(), &hamletmusic); +#endif break; case 18: +#ifdef USE_FMOD if ( tutorialmusic ) { tutorialmusic->release(); @@ -1648,8 +1732,15 @@ void physfsReloadMusic(bool &introMusicChanged, bool reloadAll) //TODO: This sho { fmod_result = fmod_system->createStream(musicDir.c_str(), FMOD_2D, nullptr, &tutorialmusic); } +#elif defined USE_OPENAL + if ( tutorialmusic ) { + OPENAL_Sound_Release(tutorialmusic); + } + OPENAL_CreateStreamSound(musicDir.c_str(), &tutorialmusic); +#endif break; case 19: +#ifdef USE_FMOD if ( gameovermusic ) { gameovermusic->release(); @@ -1662,8 +1753,15 @@ void physfsReloadMusic(bool &introMusicChanged, bool reloadAll) //TODO: This sho { fmod_result = fmod_system->createStream(musicDir.c_str(), FMOD_DEFAULT, nullptr, &gameovermusic); } +#elif defined USE_OPENAL + if ( gameovermusic ) { + OPENAL_Sound_Release(gameovermusic); + } + OPENAL_CreateStreamSound(musicDir.c_str(), &gameovermusic); +#endif break; case 20: +#ifdef USE_FMOD if ( introstorymusic ) { introstorymusic->release(); @@ -1676,8 +1774,13 @@ void physfsReloadMusic(bool &introMusicChanged, bool reloadAll) //TODO: This sho { fmod_result = fmod_system->createStream(musicDir.c_str(), FMOD_DEFAULT, nullptr, &introstorymusic); } +#elif defined USE_OPENAL + if ( introstorymusic ) { + OPENAL_Sound_Release(introstorymusic); + } + OPENAL_CreateStreamSound(musicDir.c_str(), &introstorymusic); +#endif break; -*/ default: break; } From 9aaa8ac6b19f6f6664e45d6d5849d428d07d8536 Mon Sep 17 00:00:00 2001 From: damiencarol Date: Tue, 12 Mar 2024 11:16:10 +0100 Subject: [PATCH 22/24] Fix null pointer exception --- src/engine/audio/sound.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/engine/audio/sound.cpp b/src/engine/audio/sound.cpp index 08fb1373e..7f6fcd5ea 100644 --- a/src/engine/audio/sound.cpp +++ b/src/engine/audio/sound.cpp @@ -1099,7 +1099,8 @@ void OPENAL_Sound_Release(OPENAL_BUFFER* buffer) { alDeleteBuffers( 1, &buffer->id ); ALenum error = alGetError(); if (error != AL_NO_ERROR) { - printlog("[OpenAL] error in alDeleteBuffers %d\n", error); + printlog("[OpenAL] error %d in alDeleteBuffers for buffer '%d' '%s'\n", error, buffer->id, buffer->oggfile); + return; } } free(buffer); From 4bcc86f0134afaf8bb15380eabe5df9076869835 Mon Sep 17 00:00:00 2001 From: damiencarol Date: Wed, 13 Mar 2024 13:24:23 +0100 Subject: [PATCH 23/24] More refactoring --- src/engine/audio/sound.cpp | 8 ++-- src/ui/MainMenu.cpp | 83 +------------------------------------- 2 files changed, 7 insertions(+), 84 deletions(-) diff --git a/src/engine/audio/sound.cpp b/src/engine/audio/sound.cpp index 7f6fcd5ea..089406698 100644 --- a/src/engine/audio/sound.cpp +++ b/src/engine/audio/sound.cpp @@ -1288,7 +1288,7 @@ void physfsReloadMusic_helper_reloadMusicArray(uint32_t numMusic, const char* fi }*/ } else { - printlog("[PhysFS]: fail to load music file %s...", tempstr); + printlog("[OpenAL]: fail to load music file %s...", tempstr); } } } @@ -1850,11 +1850,13 @@ void physfsReloadMusic(bool &introMusicChanged, bool reloadAll) //TODO: This sho physfsReloadMusic_helper_reloadMusicArray(NUMINTROMUSIC, "music/intro%02d.ogg", music, reloadAll); } introChanged = true; - /*if (fmod_result != FMOD_OK) +#ifdef USE_FMOD + if (fmod_result != FMOD_OK) { printlog("[PhysFS]: ERROR: Failed reloading music file \"%s\"."); break; //TODO: Handle the error? - }*/ + } +#endif } } } diff --git a/src/ui/MainMenu.cpp b/src/ui/MainMenu.cpp index a3a590f7c..d180664c1 100644 --- a/src/ui/MainMenu.cpp +++ b/src/ui/MainMenu.cpp @@ -4469,18 +4469,16 @@ namespace MainMenu { struct AudioDriver { char name[64]; -#if defined(USE_FMOD) +#ifdef USE_FMOD FMOD_GUID guid; int system_rate; FMOD_SPEAKERMODE speaker_mode; int speaker_mode_channels; -#endif -#if defined(USE_OPENAL) #endif }; static std::vector audio_drivers; -#if defined(USE_FMOD) +#ifdef USE_FMOD static void settingsAudioDevice(Button& button) { settingsOpenDropdown(button, "device", DropdownType::Wide, [](Frame::entry_t& entry){ soundActivate(); @@ -4529,35 +4527,6 @@ namespace MainMenu { }); } #endif -#ifdef USE_OPENAL - static void settingsAudioDevice(Button& button) { - settingsOpenDropdown(button, "device", DropdownType::Wide, [](Frame::entry_t& entry){ - soundActivate(); - - // store driver - /* - unsigned int index; memcpy(&index, &entry.data, sizeof(index)); - if (index < audio_drivers.size()) { - const auto& driver = audio_drivers[index]; - uint32_t _1; memcpy(&_1, &driver.guid.Data1, sizeof(_1)); - uint64_t _2; memcpy(&_2, &driver.guid.Data4, sizeof(_2)); - char guid_string[25]; - snprintf(guid_string, sizeof(guid_string), FMOD_AUDIO_GUID_FMT, _1, _2); - allSettings.audio_device = guid_string; - fmod_system->setDriver(index); - } - */ - - auto settings = main_menu_frame->findFrame("settings"); assert(settings); - auto settings_subwindow = settings->findFrame("settings_subwindow"); assert(settings_subwindow); - auto button = settings_subwindow->findButton("setting_device_dropdown_button"); assert(button); - auto dropdown = settings_subwindow->findFrame("setting_device_dropdown"); assert(dropdown); - button->setText(entry.name.c_str()); - dropdown->removeSelf(); - button->select(); - }); - } -#endif static void settingsMkbHotbarLayout(Button& button) { // deprecated @@ -6406,54 +6375,6 @@ namespace MainMenu { y += settingsAddDropdown(*settings_subwindow, y, "speaker_mode", Language::get(6140), Language::get(6150), true, modes_ptrs, modes_ptrs[allSettings.speaker_mode], settingsAudioSpeakerMode); } -#elif defined USE_OPENAL - audio_drivers.clear(); - - if (alcIsExtensionPresent(NULL, "ALC_ENUMERATION_EXT") == AL_TRUE) { // Enumeration Extension Found - printlog("OpenAL support ALC_ENUMERATION_EXT extention.\n"); - const ALCchar *devices_raw = alcGetString(NULL, ALC_DEVICE_SPECIFIER); - num_drivers = openalGetNumberOfDevices(devices_raw); - printlog("number of device detected: %d", num_drivers); - - audio_drivers.reserve(num_drivers); - - // this is good, taken from offical doc but not very "CPP" way - const ALCchar *device = devices_raw, *next = devices_raw + 1; - size_t len = 0; - - while (device && *device != '\0' && next && *next != '\0') { - len = strlen(device); - printlog("device detected: %s", device); - - AudioDriver d; - memcpy(d.name, device, len+1); - audio_drivers.push_back(d); - - //fprintf(stdout, "%s\n", device); - device += (len + 1); - next += (len + 2); - } - - std::vector drivers_formatted_ptrs; - drivers_formatted_ptrs.reserve(num_drivers); - for (auto& d : audio_drivers) { - drivers_formatted_ptrs.push_back(d.name); - } - - // debug - drivers_formatted_ptrs.push_back(alGetString(AL_VENDOR)); - drivers_formatted_ptrs.push_back(alGetString(AL_RENDERER)); - drivers_formatted_ptrs.push_back(alGetString(AL_VERSION)); - - // add section "output" - y += settingsAddSubHeader(*settings_subwindow, y, "output", Language::get(5182)); - if ( num_drivers > 0 ) - { - y += settingsAddDropdown(*settings_subwindow, y, "device", Language::get(5183), Language::get(5184), - true, drivers_formatted_ptrs, drivers_formatted_ptrs[0], //selected_device], - settingsAudioDevice); - } - } #endif y += settingsAddSubHeader(*settings_subwindow, y, "volume", Language::get(5185)); From 1ee51e3e7146c7aba4391d397e394f6a4de6567d Mon Sep 17 00:00:00 2001 From: damiencarol Date: Thu, 21 Mar 2024 18:16:44 +0100 Subject: [PATCH 24/24] Complete release of sound/musics --- src/init_game.cpp | 106 ++++++++++++++++++---------------------------- 1 file changed, 42 insertions(+), 64 deletions(-) diff --git a/src/init_game.cpp b/src/init_game.cpp index 749cf858a..389becdff 100644 --- a/src/init_game.cpp +++ b/src/init_game.cpp @@ -552,40 +552,45 @@ void deinitGame() safePacketsReceivedMap[c].clear(); } #ifdef SOUND -#ifdef USE_OPENAL //TODO: OpenAL is now all of the broken... -#define FMOD_Channel_Stop OPENAL_Channel_Stop -#define FMOD_Sound_Release OPENAL_Sound_Release + +#ifdef USE_FMOD +#define RELEASE_CHANNEL( x ) (x->stop()) +#define RELEASE_SOUND( x ) (x->release()) +#elif defined USE_OPENAL +#define RELEASE_CHANNEL( x ) OPENAL_Channel_Stop(x) +#define RELEASE_SOUND( x ) OPENAL_Sound_Release(x) #endif + if ( !no_sound ) { -#ifdef USE_FMOD - music_channel->stop(); - music_channel2->stop(); - introductionmusic->release(); - intermissionmusic->release(); - minetownmusic->release(); - splashmusic->release(); - librarymusic->release(); - shopmusic->release(); - herxmusic->release(); - templemusic->release(); - endgamemusic->release(); - escapemusic->release(); - devilmusic->release(); - sanctummusic->release(); - gnomishminesmusic->release(); - greatcastlemusic->release(); - sokobanmusic->release(); - caveslairmusic->release(); - bramscastlemusic->release(); - hamletmusic->release(); - tutorialmusic->release(); - gameovermusic->release(); - introstorymusic->release(); + RELEASE_CHANNEL( music_channel ); + RELEASE_CHANNEL( music_channel2 ); + + RELEASE_SOUND( introductionmusic ); + RELEASE_SOUND( intermissionmusic ); + RELEASE_SOUND( minetownmusic ); + RELEASE_SOUND( splashmusic ); + RELEASE_SOUND( librarymusic ); + RELEASE_SOUND( shopmusic ); + RELEASE_SOUND( herxmusic ); + RELEASE_SOUND( templemusic ); + RELEASE_SOUND( endgamemusic ); + RELEASE_SOUND( escapemusic ); + RELEASE_SOUND( devilmusic ); + RELEASE_SOUND( sanctummusic ); + RELEASE_SOUND( gnomishminesmusic ); + RELEASE_SOUND( greatcastlemusic ); + RELEASE_SOUND( sokobanmusic ); + RELEASE_SOUND( caveslairmusic ); + RELEASE_SOUND( bramscastlemusic ); + RELEASE_SOUND( hamletmusic ); + RELEASE_SOUND( tutorialmusic ); + RELEASE_SOUND( gameovermusic ); + RELEASE_SOUND( introstorymusic ); for ( int c = 0; c < NUMMINESMUSIC; c++ ) { - minesmusic[c]->release(); + RELEASE_SOUND( minesmusic[c] ); } if ( minesmusic ) { @@ -593,7 +598,7 @@ void deinitGame() } for ( int c = 0; c < NUMSWAMPMUSIC; c++ ) { - swampmusic[c]->release(); + RELEASE_SOUND( swampmusic[c] ); } if ( swampmusic ) { @@ -601,7 +606,7 @@ void deinitGame() } for ( int c = 0; c < NUMLABYRINTHMUSIC; c++ ) { - labyrinthmusic[c]->release(); + RELEASE_SOUND( labyrinthmusic[c] ); } if ( labyrinthmusic ) { @@ -609,7 +614,7 @@ void deinitGame() } for ( int c = 0; c < NUMRUINSMUSIC; c++ ) { - ruinsmusic[c]->release(); + RELEASE_SOUND( ruinsmusic[c] ); } if ( ruinsmusic ) { @@ -617,7 +622,7 @@ void deinitGame() } for ( int c = 0; c < NUMUNDERWORLDMUSIC; c++ ) { - underworldmusic[c]->release(); + RELEASE_SOUND( underworldmusic[c] ); } if ( underworldmusic ) { @@ -625,7 +630,7 @@ void deinitGame() } for ( int c = 0; c < NUMHELLMUSIC; c++ ) { - hellmusic[c]->release(); + RELEASE_SOUND( hellmusic[c] ); } if ( hellmusic ) { @@ -633,7 +638,7 @@ void deinitGame() } for ( int c = 0; c < NUMMINOTAURMUSIC; c++ ) { - minotaurmusic[c]->release(); + RELEASE_SOUND( minotaurmusic[c] ); } if ( minotaurmusic ) { @@ -641,7 +646,7 @@ void deinitGame() } for ( int c = 0; c < NUMCAVESMUSIC; c++ ) { - cavesmusic[c]->release(); + RELEASE_SOUND( cavesmusic[c] ); } if ( cavesmusic ) { @@ -649,7 +654,7 @@ void deinitGame() } for ( int c = 0; c < NUMCITADELMUSIC; c++ ) { - citadelmusic[c]->release(); + RELEASE_SOUND( citadelmusic[c] ); } if ( citadelmusic ) { @@ -657,41 +662,14 @@ void deinitGame() } for ( int c = 0; c < NUMINTROMUSIC; c++ ) { - intromusic[c]->release(); + RELEASE_SOUND( intromusic[c] ); } if ( intromusic ) { free(intromusic); } -#elif defined USE_OPENAL - // TODO: unload OpenAL resources - OPENAL_Channel_Stop(music_channel); - OPENAL_Channel_Stop(music_channel2); - OPENAL_Sound_Release(introductionmusic); - OPENAL_Sound_Release(intermissionmusic); - for ( int c = 0; c < NUMCITADELMUSIC; c++ ) - { - OPENAL_Sound_Release(citadelmusic[c]); - } - if ( citadelmusic ) - { - free(citadelmusic); - } - for ( int c = 0; c < NUMINTROMUSIC; c++ ) - { - OPENAL_Sound_Release(intromusic[c]); - } - if ( intromusic ) - { - free(intromusic); - } -#endif } -#ifdef USE_OPENAL -#undef FMOD_Channel_Stop -#undef FMOD_Sound_Release -#endif #endif // free items