From 69041980f57a022b4f2a9e45fb963bbdbadbc267 Mon Sep 17 00:00:00 2001 From: Glence Date: Mon, 26 Sep 2022 23:27:55 +0800 Subject: [PATCH] added the base for bank --- .../src/AudioSystem/SHAudioSystem.cpp | 83 ++++++++----------- SHADE_Engine/src/AudioSystem/SHAudioSystem.h | 6 +- 2 files changed, 36 insertions(+), 53 deletions(-) diff --git a/SHADE_Engine/src/AudioSystem/SHAudioSystem.cpp b/SHADE_Engine/src/AudioSystem/SHAudioSystem.cpp index 16b047bd..be280753 100644 --- a/SHADE_Engine/src/AudioSystem/SHAudioSystem.cpp +++ b/SHADE_Engine/src/AudioSystem/SHAudioSystem.cpp @@ -49,13 +49,6 @@ namespace SHADE denseListener = &SHComponentManager::GetDense(); fmodStudioSystem->getCoreSystem(&fmodSystem); - //result = coreSystem->getVersion(&version); - //ErrorCheck(); - //if (version < FMOD_VERSION) - //{ - // std::cout << "VERISION" << version << "\n"; - // std::cerr << "FMOD version mismatch." << std::endl; - //} result = fmodStudioSystem->initialize(AUDIO_SYS_MAX_CHANNELS, AUDIO_SYS_MAX_CHANNELS, FMOD_STUDIO_INIT_NORMAL, extraDriverData); ErrorCheck(); @@ -77,26 +70,18 @@ namespace SHADE result = masterGroup->addGroup(sfxChannelGroup); ErrorCheck(); - //TODO: GET VOLUME DATA FROM FILE bgmChannelGroup->setVolume(bgmVolume); sfxChannelGroup->setVolume(sfxVolume); masterGroup->setVolume(masterVolume); //SHResourceManager::LoadAllAudio(system, soundList); - //TODO: Move to SHResourceManager (LoadAllAudio to load all .bank files and store SHBanks in bankMap) - //result = system->loadBankFile("resources/audio/banks/Master.bank", FMOD_STUDIO_LOAD_BANK_NORMAL, &masterBank); - //ErrorCheck(); - //result = system->loadBankFile("resources/audio/banks/Master.strings.bank", FMOD_STUDIO_LOAD_BANK_NORMAL, &stringsBank); - //ErrorCheck(); - //result = system->loadBankFile("resources/audio/banks/Music.bank", FMOD_STUDIO_LOAD_BANK_NORMAL, &musicBank); - //ErrorCheck(); - //result = system->loadBankFile("resources/audio/banks/SFX.bank", FMOD_STUDIO_LOAD_BANK_NORMAL, &sfxBank); - //ErrorCheck(); - //LoadBank("resources/audio/banks/Master.bank"); - //LoadBank("resources/audio/banks/Master.strings.bank"); - //LoadBank("resources/audio/banks/Music.bank"); - //LoadBank("resources/audio/banks/SFX.bank"); + + LoadBank("resources/audio/banks/Master.bank"); + LoadBank("resources/audio/banks/Master.strings.bank"); + LoadBank("resources/audio/banks/Music.bank"); + LoadBank("resources/audio/banks/SFX.bank"); + //auto clip = CreateAudioClip("event:/SFX/Dawn/Dawn_Attack"); //clip->Play(); //PlayEventOnce("event:/SFX/Dawn/Dawn_Attack"); @@ -120,13 +105,11 @@ namespace SHADE fmodSystem->set3DListenerAttributes(0, &pos, nullptr, &forward, &up); } } - //int channels; - //system->getChannelsPlaying(&channels); - //std::cout << "ACTIVE CHANNELS: " << channels << std::endl; } SHAudioSystem::AudioRoutine::AudioRoutine() : SHSystemRoutine("Audio Routine", false) {} + void SHAudioSystem::AudioRoutine::Execute(double dt) noexcept { reinterpret_cast(system)->Run(dt); @@ -140,11 +123,11 @@ namespace SHADE ErrorCheck(); } - /* for (auto& bank : bankMap) + for (auto& bank : bankMap) { result = bank.second->unload(); ErrorCheck(); - }*/ + } for (auto& sound : soundList) { @@ -452,30 +435,30 @@ namespace SHADE return {}; } - //void SHAudioSystem::LoadBank(const char* path) - //{ - // FMOD::Studio::Bank* bank = nullptr; - // result = system->loadBankFile(path, FMOD_STUDIO_LOAD_BANK_NORMAL, &bank); - // ErrorCheck(); - // if (result != FMOD_OK) - // return; - // bankMap.emplace(path, bank); - // bank->loadSampleData(); - // int numOfEvents; - // bank->getEventCount(&numOfEvents); - // if (numOfEvents > 0) - // { - // std::vector events(numOfEvents); - // bank->getEventList(events.data(), numOfEvents, &numOfEvents); - // char eventName[512]; - // for (int i{}; i < numOfEvents; ++i) - // { - // FMOD::Studio::EventDescription* event = events[i]; - // event->getPath(eventName, 512, nullptr); - // eventMap.emplace(eventName, event); - // } - // } - //} + void SHAudioSystem::LoadBank(const char* path) + { + FMOD::Studio::Bank* bank = nullptr; + result = fmodStudioSystem->loadBankFile(path, FMOD_STUDIO_LOAD_BANK_NORMAL, &bank); + ErrorCheck(); + if (result != FMOD_OK) + return; + bankMap.emplace(path, bank); + bank->loadSampleData(); + int numOfEvents; + bank->getEventCount(&numOfEvents); + if (numOfEvents > 0) + { + std::vector events(numOfEvents); + bank->getEventList(events.data(), numOfEvents, &numOfEvents); + char eventName[512]; + for (int i{}; i < numOfEvents; ++i) + { + FMOD::Studio::EventDescription* event = events[i]; + event->getPath(eventName, 512, nullptr); + eventMap.emplace(eventName, event); + } + } + } AudioClip::AudioClip(AudioClipID clipID, FMOD::Studio::EventInstance* inst) :instance(inst), id(clipID) diff --git a/SHADE_Engine/src/AudioSystem/SHAudioSystem.h b/SHADE_Engine/src/AudioSystem/SHAudioSystem.h index 5fc29b7c..04fad1f0 100644 --- a/SHADE_Engine/src/AudioSystem/SHAudioSystem.h +++ b/SHADE_Engine/src/AudioSystem/SHAudioSystem.h @@ -81,7 +81,7 @@ namespace SHADE void SetPaused(bool pause); bool GetPaused() const; SHVec3 GetListenerPosition(); - //void LoadBank(const char* path); + void LoadBank(const char* path); private: FMOD::Studio::System* fmodStudioSystem; FMOD::System* fmodSystem; @@ -91,7 +91,7 @@ namespace SHADE void* extraDriverData; std::unordered_map soundList; //std::unordered_map bankMap; - //std::unordered_map bankMap; + std::unordered_map bankMap; std::unordered_map eventMap; std::unordered_map eventInstances; FMOD::ChannelGroup* bgmChannelGroup, * sfxChannelGroup, * masterGroup; @@ -100,7 +100,7 @@ namespace SHADE float bgmVolume, sfxVolume, masterVolume; unsigned int version; FMOD_SPEAKERMODE speakerMode; - //SHBank masterBank, stringsBank, musicBank, sfxBank; //To do: change to map of banks loaded by resource manager + SHBank masterBank, stringsBank, musicBank, sfxBank; //To do: change to map of banks loaded by resource manager std::vector* denseListener; AudioClipID clipID = 0;