metaforce/Runtime/Audio/CAudioSys.cpp

123 lines
2.9 KiB
C++
Raw Normal View History

2016-12-14 22:56:59 +00:00
#include "CAudioSys.hpp"
2017-01-20 03:53:32 +00:00
#include "CSimplePool.hpp"
#include "CAudioGroupSet.hpp"
2016-12-14 22:56:59 +00:00
namespace urde
{
CAudioSys* CAudioSys::g_SharedSys = nullptr;
2017-01-20 03:53:32 +00:00
static std::unordered_map<std::string, TLockedToken<CAudioGroupSet>> mpGroupSetDB;
2017-08-13 05:26:14 +00:00
static std::unordered_map<CAssetId, std::string> mpGroupSetResNameDB;
2017-01-20 03:53:32 +00:00
static const std::string mpDefaultInvalidString = "NULL";
TLockedToken<CAudioGroupSet> CAudioSys::FindGroupSet(const std::string& name)
{
auto search = mpGroupSetDB.find(name);
if (search == mpGroupSetDB.cend())
return {};
return search->second;
}
2017-08-13 05:26:14 +00:00
const std::string& CAudioSys::SysGetGroupSetName(CAssetId id)
2017-01-20 03:53:32 +00:00
{
auto search = mpGroupSetResNameDB.find(id);
if (search == mpGroupSetResNameDB.cend())
return mpDefaultInvalidString;
return search->second;
}
2017-08-13 05:26:14 +00:00
bool CAudioSys::SysLoadGroupSet(CSimplePool* pool, CAssetId id)
2017-01-20 03:53:32 +00:00
{
if (!FindGroupSet(SysGetGroupSetName(id)))
{
TLockedToken<CAudioGroupSet> set = pool->GetObj(SObjectTag{FOURCC('AGSC'), id});
mpGroupSetDB.emplace(std::make_pair(set->GetName(), set));
mpGroupSetResNameDB.emplace(std::make_pair(id, set->GetName()));
return false;
}
else
{
return true;
}
}
2017-08-13 05:26:14 +00:00
bool CAudioSys::SysLoadGroupSet(const TLockedToken<CAudioGroupSet>& set, const std::string& name, CAssetId id)
2017-01-20 03:53:32 +00:00
{
if (!FindGroupSet(name))
{
mpGroupSetDB.emplace(std::make_pair(set->GetName(), set));
mpGroupSetResNameDB.emplace(std::make_pair(id, set->GetName()));
return false;
}
else
{
return true;
}
}
void CAudioSys::SysUnloadAudioGroupSet(const std::string& name)
{
auto set = FindGroupSet(name);
if (!set)
return;
mpGroupSetDB.erase(name);
2017-01-22 09:06:03 +00:00
mpGroupSetResNameDB.erase(set.GetObjectTag()->id);
2017-01-20 03:53:32 +00:00
}
bool CAudioSys::SysIsGroupSetLoaded(const std::string& name)
{
return FindGroupSet(name).operator bool();
}
void CAudioSys::SysAddGroupIntoAmuse(const std::string& name)
{
if (auto set = FindGroupSet(name))
AddAudioGroup(set->GetAudioGroupData());
}
void CAudioSys::SysRemoveGroupFromAmuse(const std::string& name)
{
if (auto set = FindGroupSet(name))
RemoveAudioGroup(set->GetAudioGroupData());
}
2016-12-14 22:56:59 +00:00
2017-02-06 03:21:58 +00:00
static float s_MasterVol = 1.f;
static float s_SfxVol = 1.f;
void CAudioSys::_UpdateVolume()
{
GetAmuseEngine().setVolume(s_MasterVol * s_SfxVol);
}
2017-01-23 07:22:17 +00:00
void CAudioSys::SysSetVolume(u8 volume)
{
2017-02-06 03:21:58 +00:00
s_MasterVol = volume / 127.f;
_UpdateVolume();
}
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
}
static s16 s_VolumeScale = 0x7f;
static s16 s_DefaultVolumeScale = 0x7f;
s16 CAudioSys::GetDefaultVolumeScale()
{
return s_DefaultVolumeScale;
}
void CAudioSys::SetDefaultVolumeScale(s16 scale)
{
s_DefaultVolumeScale = scale;
}
void CAudioSys::SetVolumeScale(s16 scale)
{
s_VolumeScale = scale;
}
2016-12-14 22:56:59 +00:00
}