metaforce/Runtime/Audio/CAudioSys.cpp

96 lines
2.6 KiB
C++
Raw Normal View History

#include "Runtime/Audio/CAudioSys.hpp"
#include <string>
#include <unordered_map>
#include "Runtime/CSimplePool.hpp"
#include "Runtime/Audio/CAudioGroupSet.hpp"
2016-12-14 22:56:59 +00:00
2021-04-10 08:42:06 +00:00
namespace metaforce {
namespace {
std::unordered_map<std::string, TLockedToken<CAudioGroupSet>> mpGroupSetDB;
std::unordered_map<CAssetId, std::string> mpGroupSetResNameDB;
constexpr std::string_view mpDefaultInvalidString = "NULL";
float s_MasterVol = 1.f;
float s_SfxVol = 1.f;
s16 s_VolumeScale = 0x7f;
s16 s_DefaultVolumeScale = 0x7f;
} // Anonymous namespace
2016-12-14 22:56:59 +00:00
CAudioSys* CAudioSys::g_SharedSys = nullptr;
2017-01-20 03:53:32 +00:00
2018-12-08 05:30:43 +00:00
TLockedToken<CAudioGroupSet> CAudioSys::FindGroupSet(std::string_view name) {
2020-04-11 22:51:39 +00:00
// TODO: Heterogeneous lookup when C++20 available
2018-12-08 05:30:43 +00:00
auto search = mpGroupSetDB.find(name.data());
if (search == mpGroupSetDB.cend())
return {};
return search->second;
2017-01-20 03:53:32 +00:00
}
2018-12-08 05:30:43 +00:00
std::string_view CAudioSys::SysGetGroupSetName(CAssetId id) {
auto search = mpGroupSetResNameDB.find(id);
if (search == mpGroupSetResNameDB.cend())
return mpDefaultInvalidString;
return search->second;
2017-01-20 03:53:32 +00:00
}
2018-12-08 05:30:43 +00:00
bool CAudioSys::SysLoadGroupSet(CSimplePool* pool, CAssetId id) {
if (!FindGroupSet(SysGetGroupSetName(id))) {
TLockedToken<CAudioGroupSet> set = pool->GetObj(SObjectTag{FOURCC('AGSC'), id});
mpGroupSetDB.emplace(set->GetName(), set);
mpGroupSetResNameDB.emplace(id, set->GetName());
2018-12-08 05:30:43 +00:00
return false;
} else {
return true;
}
2017-01-20 03:53:32 +00:00
}
2018-12-08 05:30:43 +00:00
bool CAudioSys::SysLoadGroupSet(const TLockedToken<CAudioGroupSet>& set, std::string_view name, CAssetId id) {
if (!FindGroupSet(name)) {
mpGroupSetDB.emplace(set->GetName(), set);
mpGroupSetResNameDB.emplace(id, set->GetName());
2018-12-08 05:30:43 +00:00
return false;
} else {
return true;
}
2017-01-20 03:53:32 +00:00
}
2018-12-08 05:30:43 +00:00
void CAudioSys::SysUnloadAudioGroupSet(std::string_view name) {
auto set = FindGroupSet(name);
if (!set)
return;
2017-01-20 03:53:32 +00:00
2018-12-08 05:30:43 +00:00
mpGroupSetDB.erase(name.data());
mpGroupSetResNameDB.erase(set.GetObjectTag()->id);
2017-01-20 03:53:32 +00:00
}
2018-12-08 05:30:43 +00:00
bool CAudioSys::SysIsGroupSetLoaded(std::string_view name) { return FindGroupSet(name).operator bool(); }
2017-01-20 03:53:32 +00:00
2018-12-08 05:30:43 +00:00
void CAudioSys::SysAddGroupIntoAmuse(std::string_view name) {
2017-01-20 03:53:32 +00:00
}
2018-12-08 05:30:43 +00:00
void CAudioSys::SysRemoveGroupFromAmuse(std::string_view name) {
2017-01-20 03:53:32 +00:00
}
2016-12-14 22:56:59 +00:00
2023-10-22 16:21:20 +00:00
void CAudioSys::_UpdateVolume() { }
2017-02-06 03:21:58 +00:00
2018-12-08 05:30:43 +00:00
void CAudioSys::SysSetVolume(u8 volume) {
s_MasterVol = volume / 127.f;
_UpdateVolume();
2017-02-06 03:21:58 +00:00
}
2018-12-08 05:30:43 +00:00
void CAudioSys::SysSetSfxVolume(u8 volume, u16 time, bool music, bool fx) {
s_SfxVol = volume / 127.f;
_UpdateVolume();
2017-01-23 07:22:17 +00:00
}
2018-12-08 05:30:43 +00:00
s16 CAudioSys::GetDefaultVolumeScale() { return s_DefaultVolumeScale; }
2017-01-23 07:22:17 +00:00
2018-12-08 05:30:43 +00:00
void CAudioSys::SetDefaultVolumeScale(s16 scale) { s_DefaultVolumeScale = scale; }
2017-01-23 07:22:17 +00:00
2018-12-08 05:30:43 +00:00
void CAudioSys::SetVolumeScale(s16 scale) { s_VolumeScale = scale; }
2017-01-23 07:22:17 +00:00
2021-04-10 08:42:06 +00:00
} // namespace metaforce