2016-09-01 01:42:12 +00:00
|
|
|
#include "CAudioManager.h"
|
|
|
|
#include "Core/GameProject/CGameProject.h"
|
|
|
|
#include "Core/GameProject/CResourceIterator.h"
|
|
|
|
|
|
|
|
CAudioManager::CAudioManager(CGameProject *pProj)
|
|
|
|
: mpProject(pProj)
|
|
|
|
{
|
|
|
|
ASSERT(mpProject);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CAudioManager::LoadAssets()
|
|
|
|
{
|
|
|
|
// Clear existing assets
|
|
|
|
mAudioGroups.clear();
|
|
|
|
mpAudioLookupTable = nullptr;
|
|
|
|
mpSfxNameList = nullptr;
|
|
|
|
mSfxIdMap.clear();
|
|
|
|
|
|
|
|
// Load/sort all audio groups
|
2018-12-16 21:00:40 +00:00
|
|
|
for (TResourceIterator<EResourceType::AudioGroup> It(mpProject->ResourceStore()); It; ++It)
|
2016-09-01 01:42:12 +00:00
|
|
|
{
|
|
|
|
CAudioGroup *pGroup = (CAudioGroup*) It->Load();
|
|
|
|
if (pGroup) mAudioGroups.push_back(pGroup);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::sort(mAudioGroups.begin(), mAudioGroups.end(), [](CAudioGroup *pLeft, CAudioGroup *pRight) -> bool {
|
|
|
|
return pLeft->GroupID() < pRight->GroupID();
|
|
|
|
});
|
|
|
|
|
|
|
|
// Create SFX Define ID -> AGSC map
|
2018-12-12 05:50:46 +00:00
|
|
|
for (uint iGrp = 0; iGrp < mAudioGroups.size(); iGrp++)
|
2016-09-01 01:42:12 +00:00
|
|
|
{
|
|
|
|
CAudioGroup *pGroup = mAudioGroups[iGrp];
|
|
|
|
|
2018-12-12 05:50:46 +00:00
|
|
|
for (uint iSnd = 0; iSnd < pGroup->NumSoundDefineIDs(); iSnd++)
|
2016-09-01 01:42:12 +00:00
|
|
|
{
|
2018-12-12 05:50:46 +00:00
|
|
|
uint16 DefineID = pGroup->SoundDefineIDByIndex(iSnd);
|
2016-09-01 01:42:12 +00:00
|
|
|
ASSERT(mSfxIdMap.find(DefineID) == mSfxIdMap.end());
|
|
|
|
mSfxIdMap[DefineID] = pGroup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load audio lookup table + sfx name list
|
2018-10-07 23:53:19 +00:00
|
|
|
TString AudioLookupName = (mpProject->Game() < EGame::EchoesDemo ? "sound_lookup" : "sound_lookup_ATBL");
|
2016-09-01 01:42:12 +00:00
|
|
|
CAssetID AudioLookupID = mpProject->FindNamedResource(AudioLookupName);
|
|
|
|
|
|
|
|
if (AudioLookupID.IsValid())
|
2017-05-08 02:29:33 +00:00
|
|
|
mpAudioLookupTable = mpProject->ResourceStore()->LoadResource<CAudioLookupTable>(AudioLookupID);
|
2016-09-01 01:42:12 +00:00
|
|
|
|
2018-10-07 23:53:19 +00:00
|
|
|
if (mpProject->Game() >= EGame::EchoesDemo)
|
2016-09-01 01:42:12 +00:00
|
|
|
{
|
|
|
|
CAssetID SfxNameListID = mpProject->FindNamedResource("audio_name_lookup_STLC");
|
|
|
|
|
|
|
|
if (SfxNameListID.IsValid())
|
2017-05-08 02:29:33 +00:00
|
|
|
mpSfxNameList = mpProject->ResourceStore()->LoadResource<CStringList>(SfxNameListID);
|
2016-09-01 01:42:12 +00:00
|
|
|
}
|
|
|
|
}
|
2017-07-04 10:59:22 +00:00
|
|
|
|
|
|
|
void CAudioManager::ClearAssets()
|
|
|
|
{
|
|
|
|
mAudioGroups.clear();
|
|
|
|
mpAudioLookupTable = nullptr;
|
|
|
|
mpSfxNameList = nullptr;
|
|
|
|
mSfxIdMap.clear();
|
|
|
|
}
|
2016-09-01 01:42:12 +00:00
|
|
|
|
2018-12-12 05:50:46 +00:00
|
|
|
SSoundInfo CAudioManager::GetSoundInfo(uint32 SoundID)
|
2016-09-01 01:42:12 +00:00
|
|
|
{
|
2016-09-02 00:02:26 +00:00
|
|
|
SSoundInfo Out;
|
|
|
|
Out.SoundID = SoundID;
|
|
|
|
Out.DefineID = mpAudioLookupTable->FindSoundDefineID(SoundID);
|
|
|
|
Out.pAudioGroup = nullptr;
|
|
|
|
|
|
|
|
if (Out.DefineID != 0xFFFF)
|
|
|
|
{
|
|
|
|
auto Iter = mSfxIdMap.find(Out.DefineID);
|
|
|
|
if (Iter != mSfxIdMap.end())
|
|
|
|
Out.pAudioGroup = Iter->second;
|
2016-09-01 01:42:12 +00:00
|
|
|
|
2018-10-07 23:53:19 +00:00
|
|
|
if (mpProject->Game() >= EGame::EchoesDemo)
|
2016-09-02 00:02:26 +00:00
|
|
|
Out.Name = mpSfxNameList->StringByIndex(Out.DefineID);
|
|
|
|
}
|
|
|
|
|
|
|
|
return Out;
|
|
|
|
}
|
2016-09-01 01:42:12 +00:00
|
|
|
|
2018-12-12 05:50:46 +00:00
|
|
|
void CAudioManager::LogSoundInfo(uint32 SoundID)
|
2016-09-02 00:02:26 +00:00
|
|
|
{
|
|
|
|
SSoundInfo SoundInfo = GetSoundInfo(SoundID);
|
|
|
|
|
|
|
|
if (SoundInfo.DefineID != 0xFFFF)
|
2016-09-01 01:42:12 +00:00
|
|
|
{
|
2018-10-07 23:53:19 +00:00
|
|
|
if (mpProject->Game() >= EGame::EchoesDemo)
|
2018-12-12 05:50:46 +00:00
|
|
|
debugf("Sound Name: %s", *SoundInfo.Name);
|
2016-09-01 01:42:12 +00:00
|
|
|
|
2018-12-12 05:50:46 +00:00
|
|
|
debugf("Sound ID: 0x%04x", SoundInfo.SoundID);
|
|
|
|
debugf("Define ID: 0x%04x", SoundInfo.DefineID);
|
|
|
|
debugf("Audio Group: %s", *SoundInfo.pAudioGroup->Entry()->Name());
|
|
|
|
debugf("");
|
2016-09-01 01:42:12 +00:00
|
|
|
}
|
|
|
|
}
|