added the base for bank

This commit is contained in:
Glence 2022-09-26 23:27:55 +08:00
parent eeaf86e968
commit 69041980f5
2 changed files with 36 additions and 53 deletions

View File

@ -49,13 +49,6 @@ namespace SHADE
denseListener = &SHComponentManager::GetDense<SHAudioListenerComponent>();
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<SHAudioSystem*>(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<FMOD::Studio::EventDescription*> 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<FMOD::Studio::EventDescription*> 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)

View File

@ -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<EntityID, SHSound> soundList;
//std::unordered_map<ResourceID, SHBank> bankMap;
//std::unordered_map<std::string, SHBank> bankMap;
std::unordered_map<std::string, SHBank> bankMap;
std::unordered_map<std::string, FMOD::Studio::EventDescription*> eventMap;
std::unordered_map<AudioClipID, AudioClip> 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<SHAudioListenerComponent>* denseListener;
AudioClipID clipID = 0;