Allocators for audio system file cache (#1485)

* Reinstates an allocator for FileCacheManager

Replaces the allocator that was removed during redcode that is used for
loading banks.  Default schema for now to get things working again.

* Update path functions to AZ::IO::Path

Removes old PathUtil functions in favor of AZ::IO::Path apis.

* Update the audio allocator classes

Cleans up the audio allocator classes a bit.

* Addresses PR feedback

Updates some code to handle nullptr a bit better, and improve log
messages.

* Updates to audio CVars and address feedback

Per feedback, converted more of the audio cvars to AZ_CVAR, but not all
of them could be converted at this time.  Moved audio allocator
initialization to system component ctor/dtor to give RAII.  Updated
location of a PAL file.

* Updates the copyright of the file added in this PR

Merged copyright changes, so need to update new files.
This commit is contained in:
Eric Phister
2021-06-23 16:57:48 -05:00
committed by GitHub
parent 3d0093307f
commit 0a68f23ee0
20 changed files with 342 additions and 283 deletions
@@ -1391,12 +1391,12 @@ namespace Audio
else
{
implFileEntryData->nAKBankID = AK_INVALID_BANK_ID;
g_audioImplLogger_wwise.Log(eALT_ERROR, "Failed to load file %s\n", fileEntryInfo->sFileName);
g_audioImplLogger_wwise.Log(eALT_ERROR, "Wwise failed to load bank '%s'\n", fileEntryInfo->sFileName);
}
}
else
{
g_audioImplLogger_wwise.Log(eALT_ERROR, "Invalid AudioFileEntryData passed to the Wwise implementation of RegisterInMemoryFile");
g_audioImplLogger_wwise.Log(eALT_ERROR, "Invalid AudioFileEntryData passed to RegisterInMemoryFile");
}
}
@@ -1422,12 +1422,12 @@ namespace Audio
}
else
{
g_audioImplLogger_wwise.Log(eALT_ERROR, "Wwise Failed to unregister in memory file %s\n", fileEntryInfo->sFileName);
g_audioImplLogger_wwise.Log(eALT_ERROR, "Wwise failed to unload bank '%s'\n", fileEntryInfo->sFileName);
}
}
else
{
g_audioImplLogger_wwise.Log(eALT_ERROR, "Invalid AudioFileEntryData passed to the Wwise implementation of UnregisterInMemoryFile");
g_audioImplLogger_wwise.Log(eALT_ERROR, "Invalid AudioFileEntryData passed to UnregisterInMemoryFile");
}
}
@@ -18,8 +18,7 @@ namespace Audio
: public AZ::SystemAllocator
{
public:
AZ_CLASS_ALLOCATOR(AudioSystemAllocator, AZ::SystemAllocator, 0)
AZ_TYPE_INFO(AudioSystemAllocator, "{AE15F55D-BD65-4666-B18B-9ED81999A85B}")
AZ_TYPE_INFO(AudioSystemAllocator, "{AE15F55D-BD65-4666-B18B-9ED81999A85B}");
///////////////////////////////////////////////////////////////////////////////////////////
// IAllocator
@@ -30,20 +29,20 @@ namespace Audio
const char* GetDescription() const override
{
return "Generic allocator for use in the Audio System Module.";
return "Generic allocator for use in the Audio System module";
}
///////////////////////////////////////////////////////////////////////////////////////////
};
using AudioSystemStdAllocator = AZ::AZStdAlloc<AZ::SystemAllocator>;
///////////////////////////////////////////////////////////////////////////////////////////////
class AudioImplAllocator final
: public AZ::SystemAllocator
{
public:
AZ_CLASS_ALLOCATOR(AudioImplAllocator, AZ::SystemAllocator, 0)
AZ_TYPE_INFO(AudioImplAllocator, "{197D999F-3093-4F9D-A9A0-BA9E2AAA11DC}")
AZ_TYPE_INFO(AudioImplAllocator, "{197D999F-3093-4F9D-A9A0-BA9E2AAA11DC}");
///////////////////////////////////////////////////////////////////////////////////////////
// IAllocator
@@ -54,13 +53,35 @@ namespace Audio
const char* GetDescription() const override
{
return "Generic allocator for use in the Audio Implementation Module.";
return "Generic allocator for use in the Audio Engine Implementation module";
}
///////////////////////////////////////////////////////////////////////////////////////////
};
using AudioImplStdAllocator = AZ::AZStdAlloc<AZ::SystemAllocator>;
///////////////////////////////////////////////////////////////////////////////////////////////
class AudioBankAllocator final
: public AZ::SystemAllocator
{
public:
AZ_TYPE_INFO(AudioBankAllocator, "{19E89718-400F-42F9-92C3-E7F0DC1CCC1F}");
///////////////////////////////////////////////////////////////////////////////////////////
// IAllocator
const char* GetName() const override
{
return "AudioBankAllocator";
}
const char* GetDescription() const override
{
return "Generic allocator for use by the Audio File Cache Manager for sound banks";
}
///////////////////////////////////////////////////////////////////////////////////////////
};
} // namespace Audio
@@ -8,4 +8,5 @@
set(FILES
AudioSystem_Traits_Platform.h
AudioSystem_Traits_Android.h
../Common/Default/AudioSystemGemSystemComponent_default.cpp
)
@@ -0,0 +1,67 @@
/*
* Copyright (c) Contributors to the Open 3D Engine Project
*
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
#include <AudioAllocators.h>
#include <AudioLogger.h>
#include <SoundCVars.h>
namespace Audio::Platform
{
void InitializeAudioAllocators()
{
// Create audio system memory pool
if (!AZ::AllocatorInstance<AudioSystemAllocator>::IsReady())
{
const size_t heapSize = Audio::CVars::s_ATLMemorySize << 10;
AudioSystemAllocator::Descriptor allocDesc;
// Generic Allocator:
allocDesc.m_allocationRecords = true;
allocDesc.m_heap.m_numFixedMemoryBlocks = 1;
allocDesc.m_heap.m_fixedMemoryBlocksByteSize[0] = heapSize;
allocDesc.m_heap.m_fixedMemoryBlocks[0] = AZ::AllocatorInstance<AZ::OSAllocator>::Get().Allocate(
allocDesc.m_heap.m_fixedMemoryBlocksByteSize[0],
allocDesc.m_heap.m_memoryBlockAlignment
);
AZ::AllocatorInstance<AudioSystemAllocator>::Create(allocDesc);
}
// Create the Bank allocator...
if (!AZ::AllocatorInstance<AudioBankAllocator>::IsReady())
{
const size_t heapSize = Audio::CVars::s_FileCacheManagerMemorySize << 10;
AudioBankAllocator::Descriptor allocDesc;
allocDesc.m_allocationRecords = true;
allocDesc.m_heap.m_numFixedMemoryBlocks = 1;
allocDesc.m_heap.m_fixedMemoryBlocksByteSize[0] = heapSize;
allocDesc.m_heap.m_fixedMemoryBlocks[0] = AZ::AllocatorInstance<AZ::OSAllocator>::Get().Allocate(
allocDesc.m_heap.m_fixedMemoryBlocksByteSize[0],
allocDesc.m_heap.m_memoryBlockAlignment
);
AZ::AllocatorInstance<AudioBankAllocator>::Create(allocDesc);
}
}
void ShutdownAudioAllocators()
{
if (AZ::AllocatorInstance<Audio::AudioBankAllocator>::IsReady())
{
AZ::AllocatorInstance<Audio::AudioBankAllocator>::Destroy();
}
if (AZ::AllocatorInstance<Audio::AudioSystemAllocator>::IsReady())
{
AZ::AllocatorInstance<Audio::AudioSystemAllocator>::Destroy();
}
}
} // namespace Audio::Platform
@@ -8,4 +8,5 @@
set(FILES
AudioSystem_Traits_Platform.h
AudioSystem_Traits_Linux.h
../Common/Default/AudioSystemGemSystemComponent_default.cpp
)
@@ -8,4 +8,5 @@
set(FILES
AudioSystem_Traits_Platform.h
AudioSystem_Traits_Mac.h
../Common/Default/AudioSystemGemSystemComponent_default.cpp
)
@@ -8,4 +8,5 @@
set(FILES
AudioSystem_Traits_Platform.h
AudioSystem_Traits_Windows.h
../Common/Default/AudioSystemGemSystemComponent_default.cpp
)
@@ -8,4 +8,5 @@
set(FILES
AudioSystem_Traits_Platform.h
AudioSystem_Traits_iOS.h
../Common/Default/AudioSystemGemSystemComponent_default.cpp
)
@@ -32,6 +32,12 @@ namespace Audio
CSoundCVars g_audioCVars;
CAudioLogger g_audioLogger;
AZ::EnvironmentVariable<int*> g_audioVerbosityVar;
namespace Platform
{
void InitializeAudioAllocators();
void ShutdownAudioAllocators();
}
} // namespace Audio
namespace AudioSystemGem
@@ -79,6 +85,16 @@ namespace AudioSystemGem
AZ_UNUSED(dependent);
}
AudioSystemGemSystemComponent::AudioSystemGemSystemComponent()
{
Audio::Platform::InitializeAudioAllocators();
}
AudioSystemGemSystemComponent::~AudioSystemGemSystemComponent()
{
Audio::Platform::ShutdownAudioAllocators();
}
void AudioSystemGemSystemComponent::Init()
{
m_loseFocusRequest.nFlags = Audio::eARF_PRIORITY_HIGH;
@@ -110,48 +126,30 @@ namespace AudioSystemGem
bool AudioSystemGemSystemComponent::Initialize(const SSystemInitParams* initParams)
{
using namespace Audio;
// When nullptr is passed, create a NullAudioSystem instead of the real thing.
if (!initParams)
{
return CreateNullAudioSystem();
}
Audio::g_audioCVars.RegisterVariables();
g_audioCVars.RegisterVariables();
#if !defined(AUDIO_RELEASE)
Audio::g_audioVerbosityVar = AZ::Environment::CreateVariable<int*>("AudioLogVerbosity");
Audio::g_audioVerbosityVar.Set(&Audio::g_audioCVars.m_nAudioLoggingOptions);
g_audioVerbosityVar = AZ::Environment::CreateVariable<int*>("AudioLogVerbosity");
g_audioVerbosityVar.Set(&g_audioCVars.m_nAudioLoggingOptions);
#endif // !AUDIO_RELEASE
bool success = false;
// initialize audio system memory pool
if (!AZ::AllocatorInstance<Audio::AudioSystemAllocator>::IsReady())
{
const size_t poolSize = Audio::g_audioCVars.m_nATLPoolSize << 10;
Audio::AudioSystemAllocator::Descriptor allocDesc;
// Generic Allocator:
allocDesc.m_allocationRecords = true;
allocDesc.m_heap.m_numFixedMemoryBlocks = 1;
allocDesc.m_heap.m_fixedMemoryBlocksByteSize[0] = poolSize;
allocDesc.m_heap.m_fixedMemoryBlocks[0] = AZ::AllocatorInstance<AZ::OSAllocator>::Get().Allocate(
allocDesc.m_heap.m_fixedMemoryBlocksByteSize[0],
allocDesc.m_heap.m_memoryBlockAlignment
);
AZ::AllocatorInstance<Audio::AudioSystemAllocator>::Create(allocDesc);
}
if (CreateAudioSystem())
{
Audio::g_audioLogger.Log(Audio::eALT_ALWAYS, "AudioSystem created!");
g_audioLogger.Log(eALT_ALWAYS, "AudioSystem created!");
// Initialize the implementation module...
bool initImplSuccess = false;
Audio::Gem::AudioEngineGemRequestBus::BroadcastResult(initImplSuccess, &Audio::Gem::AudioEngineGemRequestBus::Events::Initialize);
Gem::AudioEngineGemRequestBus::BroadcastResult(initImplSuccess, &Gem::AudioEngineGemRequestBus::Events::Initialize);
if (initImplSuccess)
{
@@ -161,13 +159,13 @@ namespace AudioSystemGem
}
else
{
if (Audio::Gem::AudioEngineGemRequestBus::HasHandlers())
if (Gem::AudioEngineGemRequestBus::HasHandlers())
{
Audio::g_audioLogger.Log(Audio::eALT_ERROR, "The Audio Engine did not initialize correctly!");
g_audioLogger.Log(eALT_ERROR, "The Audio Engine did not initialize correctly!");
}
else
{
Audio::g_audioLogger.Log(Audio::eALT_WARNING, "Running without any AudioEngine!");
g_audioLogger.Log(eALT_WARNING, "Running without any AudioEngine!");
}
}
@@ -185,20 +183,16 @@ namespace AudioSystemGem
void AudioSystemGemSystemComponent::Release()
{
Audio::AudioSystemRequestBus::Broadcast(&Audio::AudioSystemRequestBus::Events::Release);
Audio::Gem::AudioEngineGemRequestBus::Broadcast(&Audio::Gem::AudioEngineGemRequestBus::Events::Release);
using namespace Audio;
AudioSystemRequestBus::Broadcast(&AudioSystemRequestBus::Events::Release);
Gem::AudioEngineGemRequestBus::Broadcast(&Gem::AudioEngineGemRequestBus::Events::Release);
// Delete the Audio System
// It should be the last object that is freed from the audio system memory pool before the allocator is destroyed.
m_audioSystem.reset();
if (AZ::AllocatorInstance<Audio::AudioSystemAllocator>::IsReady())
{
AZ::AllocatorInstance<Audio::AudioSystemAllocator>::Destroy();
}
Audio::g_audioVerbosityVar.Reset();
Audio::g_audioCVars.UnregisterVariables();
g_audioVerbosityVar.Reset();
g_audioCVars.UnregisterVariables();
GetISystem()->GetISystemEventDispatcher()->RemoveListener(this);
}
@@ -32,7 +32,6 @@ namespace AudioSystemGem
{
public:
AZ_COMPONENT(AudioSystemGemSystemComponent, "{55095EE9-38E6-485F-8314-DF35CDFECC6B}", AZ::Component);
static void Reflect(AZ::ReflectContext* context);
static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided);
@@ -40,6 +39,9 @@ namespace AudioSystemGem
static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required);
static void GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent);
AudioSystemGemSystemComponent();
~AudioSystemGemSystemComponent() override;
protected:
////////////////////////////////////////////////////////////////////////
// AZ::Component interface implementation
+2 -2
View File
@@ -505,7 +505,7 @@ namespace Audio
case eAMRT_LOSE_FOCUS:
{
#if !defined(AUDIO_RELEASE)
if (g_audioCVars.m_nIgnoreWindowFocus == 0 && (m_nFlags & eAIS_IS_MUTED) == 0)
if (!Audio::CVars::s_IgnoreWindowFocus && (m_nFlags & eAIS_IS_MUTED) == 0)
#endif // !AUDIO_RELEASE
{
auto it = m_cTriggers.find(ATLInternalControlIDs::LoseFocusTriggerID);
@@ -525,7 +525,7 @@ namespace Audio
case eAMRT_GET_FOCUS:
{
#if !defined(AUDIO_RELEASE)
if (g_audioCVars.m_nIgnoreWindowFocus == 0 && (m_nFlags & eAIS_IS_MUTED) == 0)
if (!Audio::CVars::s_IgnoreWindowFocus && (m_nFlags & eAIS_IS_MUTED) == 0)
#endif // !AUDIO_RELEASE
{
AudioSystemImplementationNotificationBus::Broadcast(&AudioSystemImplementationNotificationBus::Events::OnAudioSystemGetFocus);
@@ -383,7 +383,7 @@ namespace Audio
const AZ::Vector3 cPositionDelta = m_oPosition.GetPositionVec() - m_oPreviousPosition.GetPositionVec();
const float fCurrentVelocity = (1000.0f * cPositionDelta.GetLength()) / fUpdateIntervalMS; // fCurrentVelocity is given in units per second
if (AZ::GetAbs(fCurrentVelocity - m_fPreviousVelocity) > g_audioCVars.m_fVelocityTrackingThreshold)
if (AZ::GetAbs(fCurrentVelocity - m_fPreviousVelocity) > Audio::CVars::s_VelocityTrackingThreshold)
{
m_fPreviousVelocity = fCurrentVelocity;
SAudioRequest oRequest;
@@ -427,8 +427,8 @@ namespace Audio
///////////////////////////////////////////////////////////////////////////////////////////////////
bool CATLAudioObject::CanRunRaycasts() const
{
return Audio::s_EnableRaycasts // This is the CVar to enable/disable audio raycasts.
&& Audio::s_RaycastMinDistance < Audio::s_RaycastMaxDistance
return Audio::CVars::s_EnableRaycasts // This is the CVar to enable/disable audio raycasts.
&& Audio::CVars::s_RaycastMinDistance < Audio::CVars::s_RaycastMaxDistance
&& m_raycastProcessor.CanRun();
}
@@ -470,7 +470,7 @@ namespace Audio
info.UpdateContribution();
info.m_cached = true;
info.m_cacheTimerMs = Audio::s_RaycastCacheTimeMs;
info.m_cacheTimerMs = Audio::CVars::s_RaycastCacheTimeMs;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -495,7 +495,7 @@ namespace Audio
// Max extent is the s_RaycastMaxDistance, and use the distance embedded in the raycast request as a percent (inverse).
// Objects closer to the listener will have greater contribution amounts.
// Objects farther away will contribute less obstruction/occlusion, but distance attenuation will be the larger contributing factor.
const float maxDistance = static_cast<float>(s_RaycastMaxDistance);
const float maxDistance = static_cast<float>(Audio::CVars::s_RaycastMaxDistance);
float clampedDistance = AZ::GetClamp(m_raycastRequest.m_distance, 0.f, maxDistance);
float distanceScale = 1.f - (clampedDistance / maxDistance);
@@ -523,8 +523,8 @@ namespace Audio
RaycastProcessor::RaycastProcessor(const TAudioObjectID objectId, const SATLWorldPosition& objectPosition)
: m_rayInfos(s_maxRaysPerObject, RaycastInfo())
, m_position(objectPosition)
, m_obstructionValue(s_RaycastSmoothFactor, s_epsilon)
, m_occlusionValue(s_RaycastSmoothFactor, s_epsilon)
, m_obstructionValue(Audio::CVars::s_RaycastSmoothFactor, s_epsilon)
, m_occlusionValue(Audio::CVars::s_RaycastSmoothFactor, s_epsilon)
, m_audioObjectId(objectId)
, m_obstOccType(eAOOCT_IGNORE)
{
@@ -563,8 +563,8 @@ namespace Audio
}
}
m_obstructionValue.Update(s_RaycastSmoothFactor);
m_occlusionValue.Update(s_RaycastSmoothFactor);
m_obstructionValue.Update(Audio::CVars::s_RaycastSmoothFactor);
m_occlusionValue.Update(Audio::CVars::s_RaycastSmoothFactor);
}
///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -623,7 +623,7 @@ namespace Audio
const float distance = ray.GetLength();
// Prevent raycast when individual sources are not within the allowed distance range...
if (Audio::s_RaycastMinDistance >= distance || distance >= Audio::s_RaycastMaxDistance)
if (Audio::CVars::s_RaycastMinDistance >= distance || distance >= Audio::CVars::s_RaycastMaxDistance)
{
Reset();
return;
@@ -639,7 +639,7 @@ namespace Audio
constexpr float spreadDistanceMaxExtent = 10.f;
constexpr float spreadDistanceDelta = spreadDistanceMaxExtent - spreadDistanceMinExtent;
const float rayDistancePercent = (distance / Audio::s_RaycastMaxDistance);
const float rayDistancePercent = (distance / Audio::CVars::s_RaycastMaxDistance);
const float spreadDist = spreadDistanceMinExtent + rayDistancePercent * spreadDistanceDelta;
@@ -695,7 +695,7 @@ namespace Audio
// Set the pending flag to true, so the results aren't discarded.
m_rayInfos[rayIndex].m_pending = true;
// Set the distance in the request structure so it doesn't have the default.
m_rayInfos[rayIndex].m_raycastRequest.m_distance = (s_RaycastMaxDistance / 4.f);
m_rayInfos[rayIndex].m_raycastRequest.m_distance = (Audio::CVars::s_RaycastMaxDistance / 4.f);
}
}
@@ -809,7 +809,7 @@ namespace Audio
// Inspect triggers and apply filter (if set)...
TTriggerCountMap cTriggerCounts;
AZStd::string triggerFilter(g_audioCVars.m_pAudioTriggersDebugFilter->GetString());
auto triggerFilter = static_cast<AZ::CVarFixedString>(Audio::CVars::s_AudioTriggersDebugFilter);
AZStd::to_lower(triggerFilter.begin(), triggerFilter.end());
for (auto& trigger : m_cTriggers)
@@ -59,7 +59,7 @@ namespace Audio
///////////////////////////////////////////////////////////////////////////////////////////////////
CAudioEventManager::CAudioEventManager()
: m_oAudioEventPool(g_audioCVars.m_nAudioEventPoolSize, 1)
: m_oAudioEventPool(Audio::CVars::s_AudioEventPoolSize, 1)
#if !defined(AUDIO_RELEASE)
, m_pDebugNameStore(nullptr)
#endif // !AUDIO_RELEASE
@@ -284,7 +284,7 @@ namespace Audio
///////////////////////////////////////////////////////////////////////////////////////////////////
CAudioObjectManager::CAudioObjectManager(CAudioEventManager& refAudioEventManager)
: m_cObjectPool(g_audioCVars.m_nAudioObjectPoolSize, AudioObjectIDFactory::s_minValidAudioObjectID)
: m_cObjectPool(Audio::CVars::s_AudioObjectPoolSize, AudioObjectIDFactory::s_minValidAudioObjectID)
, m_fTimeSinceLastVelocityUpdateMS(0.0f)
, m_refAudioEventManager(refAudioEventManager)
#if !defined(AUDIO_RELEASE)
@@ -1782,7 +1782,7 @@ namespace Audio
fPosX += 20.0f;
fPosY += 17.0f;
AZStd::string triggerFilter(g_audioCVars.m_pAudioTriggersDebugFilter->GetString());
auto triggerFilter = static_cast<AZ::CVarFixedString>(Audio::CVars::s_AudioTriggersDebugFilter);
AZStd::to_lower(triggerFilter.begin(), triggerFilter.end());
for (auto& audioEventPair : m_cActiveAudioEvents)
@@ -1882,7 +1882,7 @@ namespace Audio
///////////////////////////////////////////////////////////////////////////////////////////////////
void CAudioObjectManager::DrawPerObjectDebugInfo(IRenderAuxGeom& rAuxGeom, const AZ::Vector3& rListenerPos) const
{
AZStd::string audioObjectFilter(g_audioCVars.m_pAudioObjectsDebugFilter->GetString());
auto audioObjectFilter = static_cast<AZ::CVarFixedString>(Audio::CVars::s_AudioObjectsDebugFilter);
AZStd::to_lower(audioObjectFilter.begin(), audioObjectFilter.end());
for (auto& audioObjectPair : m_cAudioObjects)
@@ -1894,7 +1894,7 @@ namespace Audio
bool bDraw = AudioDebugDrawFilter(audioObjectName, audioObjectFilter);
bDraw = bDraw && (g_audioCVars.m_nShowActiveAudioObjectsOnly == 0 || audioObject->HasActiveEvents());
bDraw = bDraw && (!Audio::CVars::s_ShowActiveAudioObjectsOnly || audioObject->HasActiveEvents());
if (bDraw)
{
@@ -1919,7 +1919,7 @@ namespace Audio
fPosX += 20.0f;
fPosY += 17.0f;
AZStd::string audioObjectFilter(g_audioCVars.m_pAudioObjectsDebugFilter->GetString());
auto audioObjectFilter = static_cast<AZ::CVarFixedString>(Audio::CVars::s_AudioObjectsDebugFilter);
AZStd::to_lower(audioObjectFilter.begin(), audioObjectFilter.end());
for (auto& audioObjectPair : m_cAudioObjects)
@@ -1931,7 +1931,7 @@ namespace Audio
bool bDraw = AudioDebugDrawFilter(audioObjectName, audioObjectFilter);
bool hasActiveEvents = audioObject->HasActiveEvents();
bDraw = bDraw && (g_audioCVars.m_nShowActiveAudioObjectsOnly == 0 || hasActiveEvents);
bDraw = bDraw && (!Audio::CVars::s_ShowActiveAudioObjectsOnly || hasActiveEvents);
if (bDraw)
{
@@ -385,7 +385,7 @@ namespace Audio
, m_memoryBlockAlignment(AUDIO_MEMORY_ALIGNMENT)
, m_flags(eAFF_NOTFOUND)
, m_dataScope(eADS_ALL)
// , m_memoryBlock(nullptr) // ToDo: Update to use non-legacy memory: LYN-3792
, m_memoryBlock(nullptr)
, m_implData(implData)
{
}
@@ -398,7 +398,7 @@ namespace Audio
size_t m_memoryBlockAlignment;
Flags<TATLEnumFlagsType> m_flags;
EATLDataScope m_dataScope;
// AZStd::unique_ptr<???> m_memoryBlock; // ToDo: Update to use non-legacy memory: LYN-3792
void* m_memoryBlock;
AZ::IO::FileRequestPtr m_asyncStreamRequest;
@@ -40,7 +40,8 @@ namespace Audio
///////////////////////////////////////////////////////////////////////////////////////////////////
void CAudioProxy::Initialize(const char* const sObjectName, const bool bInitAsync /* = true */)
{
if ((bInitAsync && g_audioCVars.m_nAudioProxiesInitType == 0) || g_audioCVars.m_nAudioProxiesInitType == 2)
auto audioProxiesInitType = static_cast<AZ::u32>(Audio::CVars::s_AudioProxiesInitType);
if ((bInitAsync && audioProxiesInitType == 0) || audioProxiesInitType == 2)
{
if ((m_nFlags & eAPF_WAITING_FOR_ID) == 0)
{
@@ -255,8 +256,8 @@ namespace Audio
if ((m_nFlags & eAPF_WAITING_FOR_ID) == 0)
{
// Update position only if the delta exceeds a given value.
if (g_audioCVars.m_fPositionUpdateThreshold <= 0.f // <-- no gating
|| !refPosition.GetPositionVec().IsClose(m_oPosition.GetPositionVec(), g_audioCVars.m_fPositionUpdateThreshold))
if (Audio::CVars::s_PositionUpdateThreshold <= 0.f // <-- no gating
|| !refPosition.GetPositionVec().IsClose(m_oPosition.GetPositionVec(), Audio::CVars::s_PositionUpdateThreshold))
{
m_oPosition = refPosition;
@@ -75,7 +75,7 @@ namespace Audio
CAudioSystem::CAudioSystem()
: m_bSystemInitialized(false)
{
m_apAudioProxies.reserve(g_audioCVars.m_nAudioObjectPoolSize);
m_apAudioProxies.reserve(Audio::CVars::s_AudioObjectPoolSize);
m_apAudioProxiesToBeFreed.reserve(16);
AudioSystemRequestBus::Handler::BusConnect();
@@ -247,7 +247,7 @@ namespace Audio
m_oATL.Initialize();
m_audioSystemThread.Activate(this);
for (int i = 0; i < g_audioCVars.m_nAudioObjectPoolSize; ++i)
for (AZ::u64 i = 0; i < Audio::CVars::s_AudioObjectPoolSize; ++i)
{
auto audioProxy = azcreate(CAudioProxy, (), Audio::AudioSystemAllocator, "AudioProxy");
m_apAudioProxies.push_back(audioProxy);
@@ -437,7 +437,7 @@ namespace Audio
return;
}
if (m_apAudioProxies.size() < g_audioCVars.m_nAudioObjectPoolSize)
if (m_apAudioProxies.size() < Audio::CVars::s_AudioObjectPoolSize)
{
m_apAudioProxies.push_back(audioProxy);
}
@@ -9,18 +9,19 @@
#include <FileCacheManager.h>
#include <AzCore/IO/IStreamer.h>
#include <AzCore/IO/Path/Path.h>
#include <AzCore/std/string/conversions.h>
#include <AzCore/std/parallel/binary_semaphore.h>
#include <AzCore/StringFunc/StringFunc.h>
#include <AzFramework/Archive/IArchive.h>
#include <AudioAllocators.h>
#include <AudioInternalInterfaces.h>
#include <IAudioSystemImplementation.h>
#include <SoundCVars.h>
#include <AudioSystem_Traits_Platform.h>
#include <IRenderAuxGeom.h>
#include <CryPath.h>
namespace Audio
{
@@ -42,7 +43,7 @@ namespace Audio
///////////////////////////////////////////////////////////////////////////////////////////////
void CFileCacheManager::Initialize()
{
AllocateHeap(static_cast<size_t>(g_audioCVars.m_nFileCacheManagerSize), "AudioFileCacheManager");
AllocateHeap(static_cast<size_t>(Audio::CVars::s_FileCacheManagerMemorySize), "AudioFileCacheManager");
AudioFileCacheManagerNotficationBus::Handler::BusConnect();
}
@@ -70,13 +71,7 @@ namespace Audio
{
if (size > 0)
{
// ToDo: Update to use non-legacy memory: LYN-3792
/*m_memoryHeap.reset(???);
if (m_memoryHeap.get())
{
m_maxByteTotal = size << 10;
}*/
m_maxByteTotal = size << 10;
}
}
@@ -536,7 +531,7 @@ namespace Audio
CATLAudioFileEntry* audioFileEntry = fileEntryIter->second;
AZ_Assert(audioFileEntry, "FileCacheManager - Audio file entry is null!");
// AZ_Assert(buffer == audioFileEntry->m_memoryBlock->GetData(), "FileCacheManager - The memory buffer doesn't match the file entry memory block!"); // ToDo: Update to use non-legacy memory: LYN-3792
AZ_Assert(buffer == audioFileEntry->m_memoryBlock, "FileCacheManager - The memory buffer doesn't match the file entry memory block!");
FinishCachingFileInternal(audioFileEntry, numBytesRead, streamer->GetRequestStatus(request));
}
}
@@ -563,16 +558,17 @@ namespace Audio
audioFileEntry->m_flags.AddFlags(eAFF_CACHED);
audioFileEntry->m_flags.ClearFlags(eAFF_LOADING);
#if !defined(AUDIO_RELEASE)
#if !defined(AUDIO_RELEASE)
audioFileEntry->m_timeCached = AZStd::chrono::system_clock::now();
#endif // !AUDIO_RELEASE
#endif // !AUDIO_RELEASE
SATLAudioFileEntryInfo fileEntryInfo;
fileEntryInfo.nMemoryBlockAlignment = audioFileEntry->m_memoryBlockAlignment;
// fileEntryInfo.pFileData = audioFileEntry->m_memoryBlock->GetData(); // ToDo: Update to use non-legacy memory: LYN-3792
fileEntryInfo.pFileData = audioFileEntry->m_memoryBlock;
fileEntryInfo.nSize = audioFileEntry->m_fileSize;
fileEntryInfo.pImplData = audioFileEntry->m_implData;
fileEntryInfo.sFileName = PathUtil::GetFile(audioFileEntry->m_filePath.c_str());
AZ::IO::PathView filePath{ audioFileEntry->m_filePath };
fileEntryInfo.sFileName = filePath.Filename().Native().data();
AudioSystemImplementationRequestBus::Broadcast(&AudioSystemImplementationRequestBus::Events::RegisterInMemoryFile, &fileEntryInfo);
success = true;
@@ -644,41 +640,40 @@ namespace Audio
}
///////////////////////////////////////////////////////////////////////////////////////////////
bool CFileCacheManager::AllocateMemoryBlockInternal([[maybe_unused]]CATLAudioFileEntry* const audioFileEntry)
bool CFileCacheManager::AllocateMemoryBlockInternal(CATLAudioFileEntry* const audioFileEntry)
{
// ToDo: Update to use non-legacy memory: LYN-3792
return false;
/*AZ_PROFILE_FUNCTION(AZ::Debug::ProfileCategory::Audio);
AZ_PROFILE_FUNCTION(AZ::Debug::ProfileCategory::Audio);
// Must not have valid memory yet.
AZ_Assert(!audioFileEntry->m_memoryBlock, "FileCacheManager AllocateMemoryBlockInternal - Memory appears to be set already!");
if (m_memoryHeap)
{
audioFileEntry->m_memoryBlock.reset(m_memoryHeap->AllocateBlock(audioFileEntry->m_fileSize, audioFileEntry->m_filePath.c_str(), audioFileEntry->m_memoryBlockAlignment));
}
audioFileEntry->m_memoryBlock = AZ::AllocatorInstance<AudioBankAllocator>::Get().Allocate(
audioFileEntry->m_fileSize,
audioFileEntry->m_memoryBlockAlignment,
0,
audioFileEntry->m_filePath.c_str(),
__FILE__, __LINE__);
if (!audioFileEntry->m_memoryBlock)
{
// Memory block is either full or too fragmented, let's try to throw everything out that can be removed and allocate again.
TryToUncacheFiles();
// And try again!
if (m_memoryHeap)
{
audioFileEntry->m_memoryBlock.reset(m_memoryHeap->AllocateBlock(audioFileEntry->m_fileSize, audioFileEntry->m_filePath.c_str(), audioFileEntry->m_memoryBlockAlignment));
}
// And try again
audioFileEntry->m_memoryBlock = AZ::AllocatorInstance<AudioBankAllocator>::Get().Allocate(
audioFileEntry->m_fileSize,
audioFileEntry->m_memoryBlockAlignment,
0,
audioFileEntry->m_filePath.c_str(),
__FILE__, __LINE__);
}
return (audioFileEntry->m_memoryBlock != nullptr);*/
return (audioFileEntry->m_memoryBlock != nullptr);
}
///////////////////////////////////////////////////////////////////////////////////////////////
void CFileCacheManager::UncacheFile(CATLAudioFileEntry* const audioFileEntry)
{
m_currentByteTotal -= audioFileEntry->m_fileSize;
if (audioFileEntry->m_asyncStreamRequest)
{
auto streamer = AZ::Interface<AZ::IO::IStreamer>::Get();
@@ -698,22 +693,36 @@ namespace Audio
audioFileEntry->m_asyncStreamRequest.reset();
}
// ToDo: Update to use non-legacy memory heap: LYN-3792
/*if (audioFileEntry->m_memoryBlock && audioFileEntry->m_memoryBlock->GetData())
if (audioFileEntry->m_memoryBlock)
{
SATLAudioFileEntryInfo fileEntryInfo;
fileEntryInfo.nMemoryBlockAlignment = audioFileEntry->m_memoryBlockAlignment;
fileEntryInfo.pFileData = audioFileEntry->m_memoryBlock->GetData();
fileEntryInfo.pFileData = audioFileEntry->m_memoryBlock;
fileEntryInfo.nSize = audioFileEntry->m_fileSize;
fileEntryInfo.pImplData = audioFileEntry->m_implData;
fileEntryInfo.sFileName = PathUtil::GetFile(audioFileEntry->m_filePath.c_str());
AZ::IO::PathView filePath{ audioFileEntry->m_filePath };
fileEntryInfo.sFileName = filePath.Filename().Native().data();
AudioSystemImplementationRequestBus::Broadcast(&AudioSystemImplementationRequestBus::Events::UnregisterInMemoryFile, &fileEntryInfo);
g_audioLogger.Log(eALT_COMMENT, "FileCacheManager - File Uncached: '%s'\n", fileEntryInfo.sFileName);
EAudioRequestStatus result = eARS_SUCCESS;
AudioSystemImplementationRequestBus::BroadcastResult(result, &AudioSystemImplementationRequestBus::Events::UnregisterInMemoryFile, &fileEntryInfo);
if (result == eARS_SUCCESS)
{
g_audioLogger.Log(eALT_COMMENT, "FileCacheManager - File Uncached: '%s'\n", fileEntryInfo.sFileName);
}
else
{
g_audioLogger.Log(eALT_COMMENT, "FileCacheManager - Unable to uncache file '%s'\n", fileEntryInfo.sFileName);
return;
}
}
audioFileEntry->m_memoryBlock.reset();*/
AZ::AllocatorInstance<AudioBankAllocator>::Get().DeAllocate(
audioFileEntry->m_memoryBlock,
audioFileEntry->m_fileSize,
audioFileEntry->m_memoryBlockAlignment
);
audioFileEntry->m_flags.ClearFlags(eAFF_CACHED | eAFF_REMOVABLE);
m_currentByteTotal -= audioFileEntry->m_fileSize;
AZ_Warning("FileCacheManager", audioFileEntry->m_useCount == 0, "Use-count of file '%s' is non-zero while uncaching it! Use Count: %d", audioFileEntry->m_filePath.c_str(), audioFileEntry->m_useCount);
audioFileEntry->m_useCount = 0;
@@ -745,19 +754,27 @@ namespace Audio
fileEntryInfo.pFileData = nullptr;
fileEntryInfo.nMemoryBlockAlignment = 0;
AZStd::string fileName(PathUtil::GetFile(audioFileEntry->m_filePath.c_str()));
AZ::IO::FixedMaxPath filePath{ audioFileEntry->m_filePath };
AZStd::string_view fileName{ filePath.Filename().Native() };
fileEntryInfo.pImplData = audioFileEntry->m_implData;
fileEntryInfo.sFileName = fileName.c_str();
fileEntryInfo.sFileName = fileName.data();
const char* fileLocation = nullptr;
AudioSystemImplementationRequestBus::BroadcastResult(fileLocation, &AudioSystemImplementationRequestBus::Events::GetAudioFileLocation, &fileEntryInfo);
audioFileEntry->m_filePath = fileLocation;
audioFileEntry->m_filePath += fileName.c_str();
if (fileLocation && fileLocation[0] != '\0')
{
audioFileEntry->m_filePath.assign(fileLocation);
audioFileEntry->m_filePath.append(fileName.data(), fileName.size());
}
else
{
AZ_WarningOnce("FileCacheManager", fileLocation != nullptr, "GetAudioFileLocation returned null when getting a localized file path! Path will not be changed.");
}
AZStd::to_lower(audioFileEntry->m_filePath.begin(), audioFileEntry->m_filePath.end());
audioFileEntry->m_fileSize = gEnv->pCryPak->FGetSize(audioFileEntry->m_filePath.c_str());
AZ_Assert(audioFileEntry->m_fileSize > 0, "FileCacheManager UpdateLocalizedFileEntryData - Expected file size to be greater than zero!");
AZ_Assert(audioFileEntry->m_fileSize > 0, "FileCacheManager - UpdateLocalizedFileEntryData expected file size to be greater than zero!");
}
///////////////////////////////////////////////////////////////////////////////////////////////
@@ -774,8 +791,7 @@ namespace Audio
if (!audioFileEntry->m_filePath.empty() && !audioFileEntry->m_flags.AreAnyFlagsActive(eAFF_CACHED | eAFF_LOADING))
{
// ToDo: Update to use non-legacy memory heap: LYN-3792
/*if (DoesRequestFitInternal(audioFileEntry->m_fileSize) && AllocateMemoryBlockInternal(audioFileEntry))
if (DoesRequestFitInternal(audioFileEntry->m_fileSize) && AllocateMemoryBlockInternal(audioFileEntry))
{
auto streamer = AZ::Interface<AZ::IO::IStreamer>::Get();
AZ_Assert(streamer, "FileCacheManager - Streamer should be ready!");
@@ -786,8 +802,8 @@ namespace Audio
{
AZ::IO::FileRequestPtr request = streamer->Read(
audioFileEntry->m_filePath.c_str(),
audioFileEntry->m_memoryBlock->GetData(),
audioFileEntry->m_memoryBlock->GetSize(),
audioFileEntry->m_memoryBlock,
audioFileEntry->m_fileSize,
audioFileEntry->m_fileSize,
AZ::IO::IStreamerTypes::s_deadlineNow,
AZ::IO::IStreamerTypes::s_priorityHigh);
@@ -815,8 +831,8 @@ namespace Audio
streamer->Read(
audioFileEntry->m_asyncStreamRequest,
audioFileEntry->m_filePath.c_str(),
audioFileEntry->m_memoryBlock->GetData(),
audioFileEntry->m_memoryBlock->GetSize(),
audioFileEntry->m_memoryBlock,
audioFileEntry->m_fileSize,
audioFileEntry->m_fileSize,
AZ::IO::IStreamerTypes::s_noDeadline,
AZ::IO::IStreamerTypes::s_priorityHigh);
@@ -841,24 +857,24 @@ namespace Audio
else
{
// Cannot have a valid memory block!
AZ_Assert(!audioFileEntry->m_memoryBlock || !audioFileEntry->m_memoryBlock->GetData(),
"FileCacheManager TryCacheFileCacheEntryInternal - Cannot have a valid memory block after memory allocation failure!");
AZ_Assert(audioFileEntry->m_memoryBlock == nullptr,
"FileCacheManager - Memory block should be null after memory allocation failure!");
// This unfortunately is a total memory allocation fail.
audioFileEntry->m_flags.AddFlags(eAFF_MEMALLOCFAIL);
// The user should be made aware of it.
g_audioLogger.Log(eALT_ERROR, "FileCacheManager: Could not cache '%s' - out of memory or fragmented memory!", audioFileEntry->m_filePath.c_str());
}*/
g_audioLogger.Log(eALT_ERROR, "FileCacheManager - Could not cache '%s' - out of memory or fragmented memory!", audioFileEntry->m_filePath.c_str());
}
}
else if (audioFileEntry->m_flags.AreAnyFlagsActive(eAFF_CACHED | eAFF_LOADING))
{
g_audioLogger.Log(eALT_COMMENT, "FileCacheManager: Skipping '%s' - it's either already loaded or currently loading!", audioFileEntry->m_filePath.c_str());
g_audioLogger.Log(eALT_COMMENT, "FileCacheManager - Skipping '%s' - it's either already loaded or currently loading!", audioFileEntry->m_filePath.c_str());
success = true;
}
else if (audioFileEntry->m_flags.AreAnyFlagsActive(eAFF_NOTFOUND))
{
g_audioLogger.Log(eALT_ERROR, "FileCacheManager: Could not cache '%s' - file was not found at the target location!", audioFileEntry->m_filePath.c_str());
g_audioLogger.Log(eALT_WARNING, "FileCacheManager - Could not cache '%s' - file was not found at that location!", audioFileEntry->m_filePath.c_str());
}
// Increment the used count on manually-loaded files.
@@ -97,7 +97,6 @@ namespace Audio
TATLPreloadRequestLookup& m_preloadRequests;
TAudioFileEntries m_audioFileEntries;
// AZStd::unique_ptr<???> m_memoryHeap; // ToDo: Update to use non-legacy memory: LYN-3792
size_t m_currentByteTotal;
size_t m_maxByteTotal;
};
@@ -17,11 +17,8 @@
#include <MicrophoneBus.h>
namespace Audio
namespace Audio::CVars
{
extern CAudioLogger g_audioLogger;
// CVar: s_EnableRaycasts
// Usage: s_EnableRaycasts=true (false)
AZ_CVAR(bool, s_EnableRaycasts, true,
@@ -93,7 +90,7 @@ namespace Audio
// CVar: s_RaycastSmoothFactor
// Usage: s_RaycastSmoothFactor=5.0
AZ_CVAR(float, s_RaycastSmoothFactor, 7.f,
[](const float& smoothFactor) ->void
[](const float& smoothFactor) -> void
{
static constexpr float s_absoluteMinRaycastSmoothFactor = 0.f;
static constexpr float s_absoluteMaxRaycastSmoothFactor = 10.f;
@@ -106,104 +103,97 @@ namespace Audio
"How slowly the smoothing of obstruction/occlusion values should smooth to target: delta / (smoothFactor^2 + 1). "
"Low values will smooth faster, high values will smooth slower.");
AZ_CVAR(AZ::u64, s_ATLMemorySize, AZ_TRAIT_AUDIOSYSTEM_ATL_POOL_SIZE,
nullptr, AZ::ConsoleFunctorFlags::Null,
"The size in KiB of memory to be used by the ATL/Audio System.\n"
"Usage: s_ATLMemorySize=" AZ_TRAIT_AUDIOSYSTEM_ATL_POOL_SIZE_DEFAULT_TEXT "\n");
AZ_CVAR(AZ::u64, s_FileCacheManagerMemorySize, AZ_TRAIT_AUDIOSYSTEM_FILE_CACHE_MANAGER_SIZE,
nullptr, AZ::ConsoleFunctorFlags::Null,
"The size in KiB the File Cache Manager will use for banks.\n"
"Usage: s_FileCacheManagerMemorySize=" AZ_TRAIT_AUDIOSYSTEM_FILE_CACHE_MANAGER_SIZE_DEFAULT_TEXT "\n");
AZ_CVAR(AZ::u64, s_AudioEventPoolSize, AZ_TRAIT_AUDIOSYSTEM_AUDIO_EVENT_POOL_SIZE,
nullptr, AZ::ConsoleFunctorFlags::Null,
"The number of audio events to preallocate in a pool.\n"
"Usage: s_AudioEventPoolSize=" AZ_TRAIT_AUDIOSYSTEM_AUDIO_EVENT_POOL_SIZE_DEFAULT_TEXT "\n");
AZ_CVAR(AZ::u64, s_AudioObjectPoolSize, AZ_TRAIT_AUDIOSYSTEM_AUDIO_OBJECT_POOL_SIZE,
nullptr, AZ::ConsoleFunctorFlags::Null,
"The number of audio objects to preallocate in a pool.\n"
"Usage: s_AudioObjectPoolSize=" AZ_TRAIT_AUDIOSYSTEM_AUDIO_OBJECT_POOL_SIZE_DEFAULT_TEXT "\n");
AZ_CVAR(float, s_PositionUpdateThreshold, 0.1f,
nullptr, AZ::ConsoleFunctorFlags::Null,
"An audio object needs to move by this distance in order to issue a position update to the audio system.\n"
"Usage: s_PositionUpdateThreshold=5.0\n");
AZ_CVAR(float, s_VelocityTrackingThreshold, 0.1f,
nullptr, AZ::ConsoleFunctorFlags::Null,
"An audio object needs to have its velocity changed by this amount in order to issue an 'object_speed' Rtpc update to the audio system.\n"
"Usage: s_VelocityTrackingThreshold=0.5\n");
AZ_CVAR(AZ::u32, s_AudioProxiesInitType, 0,
[](const AZ::u32& initType) -> void
{
static constexpr AZ::u32 s_numAudioProxyInitTypes = 3;
if (initType < s_numAudioProxyInitTypes)
{
s_AudioProxiesInitType = initType;
}
},
AZ::ConsoleFunctorFlags::Null,
"Overrides the initialization mode of audio proxies globally.\n"
"0: AudioProxy-specific initiaization (Default).\n"
"1: All AudioProxy's initialize synchronously.\n"
"2: All AudioProxy's initialize asynchronously.\n"
"Usage: s_AudioProxiesInitType=2\n");
#if !defined(AUDIO_RELEASE)
AZ_CVAR(bool, s_IgnoreWindowFocus, false,
nullptr, AZ::ConsoleFunctorFlags::Null,
"Determines whether application focus should issue events to the audio system or not.\n"
"false: Window focus event should be issued (Default).\n"
"true: Ignore window focus events.\n"
"Usage: s_IgnoreWindowFocus=true\n");
AZ_CVAR(bool, s_ShowActiveAudioObjectsOnly, false,
nullptr, AZ::ConsoleFunctorFlags::Null,
"Determines whether active or all audio objects should be drawn when debug drawing is enabled.\n"
"false: Draws all audio objects (Default).\n"
"true: Draws only active audio objects.\n"
"Usage: s_ShowActiveAudioObjectsOnly=true\n");
AZ_CVAR(AZ::CVarFixedString, s_AudioTriggersDebugFilter, "",
nullptr, AZ::ConsoleFunctorFlags::Null,
"Filters debug drawing to only audio triggers that match this filter as sub-string.\n"
"Usage: s_AudioTriggersDebugFilter=impact_hit\n");
AZ_CVAR(AZ::CVarFixedString, s_AudioObjectsDebugFilter, "",
nullptr, AZ::ConsoleFunctorFlags::Null,
"Filters debug drawing to only audio objects whose name matches this filter as a sub-string.\n"
"Usage: s_AudioObjectsDebugFilter=weapon_axe\n");
#endif // !AUDIO_RELEASE
} // namespace Audio::CVars
namespace Audio
{
extern CAudioLogger g_audioLogger;
///////////////////////////////////////////////////////////////////////////////////////////////////
CSoundCVars::CSoundCVars()
: m_nATLPoolSize(0)
, m_nFileCacheManagerSize(0)
, m_nAudioObjectPoolSize(0)
, m_nAudioEventPoolSize(0)
, m_nAudioProxiesInitType(0)
, m_fPositionUpdateThreshold(0.0f)
, m_fVelocityTrackingThreshold(0.0f)
, m_audioListenerTranslationPercentage(0.f)
, m_audioListenerTranslationZOffset(0.f)
#if !defined(AUDIO_RELEASE)
, m_nIgnoreWindowFocus(0)
, m_nDrawAudioDebug(0)
: m_nDrawAudioDebug(0)
, m_nFileCacheManagerDebugFilter(0)
, m_nAudioLoggingOptions(0)
, m_nShowActiveAudioObjectsOnly(0)
, m_pAudioTriggersDebugFilter(nullptr)
, m_pAudioObjectsDebugFilter(nullptr)
#endif // !AUDIO_RELEASE
{
}
///////////////////////////////////////////////////////////////////////////////////////////////////
CSoundCVars::~CSoundCVars()
{
}
///////////////////////////////////////////////////////////////////////////////////////////////////
void CSoundCVars::RegisterVariables()
{
m_nATLPoolSize = AZ_TRAIT_AUDIOSYSTEM_ATL_POOL_SIZE;
m_nAudioEventPoolSize = AZ_TRAIT_AUDIOSYSTEM_AUDIO_EVENT_POOL_SIZE;
m_nAudioObjectPoolSize = AZ_TRAIT_AUDIOSYSTEM_AUDIO_OBJECT_POOL_SIZE;
m_nFileCacheManagerSize = AZ_TRAIT_AUDIOSYSTEM_FILE_CACHE_MANAGER_SIZE;
// Common Cross-Platform Defaults
m_nAudioProxiesInitType = 0;
m_fPositionUpdateThreshold = 0.1f;
m_fVelocityTrackingThreshold = 0.1f;
REGISTER_CVAR2("s_ATLPoolSize", &m_nATLPoolSize, m_nATLPoolSize, VF_REQUIRE_APP_RESTART,
"Specifies the size (in KiB) of the memory pool to be used by the ATL.\n"
"Usage: s_ATLPoolSize [0/...]\n"
"Default: " AZ_TRAIT_AUDIOSYSTEM_ATL_POOL_SIZE_DEFAULT_TEXT "\n");
REGISTER_CVAR2("s_AudioEventPoolSize", &m_nAudioEventPoolSize, m_nAudioEventPoolSize, VF_REQUIRE_APP_RESTART,
"Sets the number of preallocated audio events.\n"
"Usage: s_AudioEventPoolSize [0/...]\n"
"Default: " AZ_TRAIT_AUDIOSYSTEM_AUDIO_EVENT_POOL_SIZE_DEFAULT_TEXT "\n");
REGISTER_CVAR2("s_AudioObjectPoolSize", &m_nAudioObjectPoolSize, m_nAudioObjectPoolSize, VF_REQUIRE_APP_RESTART,
"Sets the number of preallocated audio objects and corresponding audio proxies.\n"
"Usage: s_AudioObjectPoolSize [0/...]\n"
"Default: " AZ_TRAIT_AUDIOSYSTEM_AUDIO_OBJECT_POOL_SIZE_DEFAULT_TEXT "\n");
REGISTER_CVAR2("s_FileCacheManagerSize", &m_nFileCacheManagerSize, m_nFileCacheManagerSize, VF_REQUIRE_APP_RESTART,
"Sets the size in KiB the AFCM will allocate on the heap.\n"
"Usage: s_FileCacheManagerSize [0/...]\n"
"Default: " AZ_TRAIT_AUDIOSYSTEM_FILE_CACHE_MANAGER_SIZE_DEFAULT_TEXT "\n");
REGISTER_CVAR2("s_PositionUpdateThreshold", &m_fPositionUpdateThreshold, m_fPositionUpdateThreshold, VF_CHEAT | VF_CHEAT_NOCHECK,
"An audio object has to move by at least this amount to issue a position update request to the audio system.\n"
"This kind of optimization should ideally be done by the parent system so this is here for convenience.\n"
"Usage: s_PositionUpdateThreshold [0/...]\n"
"Default: 0.1 (10 cm)\n");
REGISTER_CVAR2("s_VelocityTrackingThreshold", &m_fVelocityTrackingThreshold, m_fVelocityTrackingThreshold, VF_CHEAT | VF_CHEAT_NOCHECK,
"An audio object has to change its velocity by at least this amount to issue an \"object_speed\" RTPC update request to the audio system.\n"
"Usage: s_VelocityTrackingThreshold [0/...]\n"
"Default: 0.1 (10 cm/s)\n");
REGISTER_CVAR2("s_AudioProxiesInitType", &m_nAudioProxiesInitType, m_nAudioProxiesInitType, VF_NULL,
"Can override AudioProxies' init type on a global scale.\n"
"If set it determines whether AudioProxies initialize synchronously or asynchronously.\n"
"This is a performance type cvar as asynchronously initializing AudioProxies\n"
"will have a greatly reduced impact on the calling thread.\n"
"Be aware though that when set to initialize asynchronously that audio will play back delayed.\n"
"By how much will greatly depend on the audio thread's work load.\n"
"0: AudioProxy specific initialization.\n"
"1: All AudioProxies initialize synchronously.\n"
"2: All AudioProxies initialize asynchronously.\n"
"Usage: s_AudioProxiesInitType [0/1/2]\n"
"Default: 0\n");
REGISTER_CVAR2("s_AudioListenerTranslationZOffset", &m_audioListenerTranslationZOffset, 0.f, VF_NULL,
"Use this to specify a Z-Offset (\"Up\") for the audio listener's position.\n"
"Usage: s_AudioListenerTranslationZOffset 1.3\n"
"Default: 0.0\n");
REGISTER_CVAR2("s_AudioListenerTranslationPercentage", &m_audioListenerTranslationPercentage, 0.f, VF_NULL,
"Use this to specify a percentage of translation of the audio listener between two points\n"
"(usually these are the camera's location and player's location).\n"
"Usage: s_AudioListenerTranslationPercentage [0.0..1.0]\n"
"Default: 0.0\n");
#if !defined(AUDIO_RELEASE)
REGISTER_COMMAND("s_ExecuteTrigger", CmdExecuteTrigger, VF_CHEAT,
"Execute an Audio Trigger.\n"
@@ -277,11 +267,6 @@ namespace Audio
"Usage: s_SetPanningMode headphones\n"
);
REGISTER_CVAR2("s_IgnoreWindowFocus", &m_nIgnoreWindowFocus, 0, VF_DEV_ONLY,
"If set to 1, the sound system will continue playing when the Editor or Game window loses focus.\n"
"Usage: s_IgnoreWindowFocus [0/1]\n"
"Default: 0 (off)\n");
REGISTER_CVAR2("s_DrawAudioDebug", &m_nDrawAudioDebug, 0, VF_CHEAT | VF_CHEAT_NOCHECK | VF_BITFIELD,
"Draws AudioTranslationLayer related debug data to the screen.\n"
"Usage: s_DrawAudioDebug [0ab...] (flags can be combined)\n"
@@ -317,40 +302,12 @@ namespace Audio
"a: Errors\n"
"b: Warnings\n"
"c: Comments\n");
REGISTER_CVAR2("s_ShowActiveAudioObjectsOnly", &m_nShowActiveAudioObjectsOnly, 1, VF_DEV_ONLY,
"When drawing audio object names on the screen this cvar can be used to choose between all registered audio objects or only those that reference active audio triggers.\n"
"Usage: s_ShowActiveAudioObjectsOnly [0/1]\n"
"Default: 1 (active only)\n");
m_pAudioTriggersDebugFilter = REGISTER_STRING("s_AudioTriggersDebugFilter", "", 0,
"Allows for filtered display of audio triggers by a search string.\n"
"Usage: s_AudioTriggersDebugFilter laser\n"
"Default: \"\" (all)\n");
m_pAudioObjectsDebugFilter = REGISTER_STRING("s_AudioObjectsDebugFilter", "", 0,
"Allows for filtered display of audio objects by a search string.\n"
"Usage: s_AudioObjectsDebugFilter spaceship.\n"
"Default: \"\" (all)\n");
#endif // !AUDIO_RELEASE
}
///////////////////////////////////////////////////////////////////////////////////////////////////
void CSoundCVars::UnregisterVariables()
{
UNREGISTER_CVAR("s_ATLPoolSize");
UNREGISTER_CVAR("s_PositionUpdateThreshold");
UNREGISTER_CVAR("s_VelocityTrackingThreshold");
UNREGISTER_CVAR("s_FileCacheManagerSize");
UNREGISTER_CVAR("s_AudioObjectPoolSize");
UNREGISTER_CVAR("s_AudioEventPoolSize");
UNREGISTER_CVAR("s_AudioProxiesInitType");
UNREGISTER_CVAR("s_AudioListenerTranslationYOffset");
UNREGISTER_CVAR("s_AudioListenerTranslationPercentage");
#if !defined(AUDIO_RELEASE)
UNREGISTER_COMMAND("s_ExecuteTrigger");
UNREGISTER_COMMAND("s_StopTrigger");
@@ -361,19 +318,14 @@ namespace Audio
UNREGISTER_COMMAND("s_PlayFile");
UNREGISTER_COMMAND("s_PlayExternalSource");
UNREGISTER_COMMAND("s_SetPanningMode");
UNREGISTER_CVAR("s_IgnoreWindowFocus");
UNREGISTER_CVAR("s_DrawAudioDebug");
UNREGISTER_CVAR("s_FileCacheManagerDebugFilter");
UNREGISTER_CVAR("s_AudioLoggingOptions");
UNREGISTER_CVAR("s_ShowActiveAudioObjectsOnly");
UNREGISTER_CVAR("s_AudioTriggersDebugFilter");
UNREGISTER_CVAR("s_AudioObjectsDebugFilter");
#endif // !AUDIO_RELEASE
}
#if !defined(AUDIO_RELEASE)
///////////////////////////////////////////////////////////////////////////////////////////////////
void CSoundCVars::CmdExecuteTrigger(IConsoleCmdArgs* pCmdArgs)
{
@@ -13,22 +13,41 @@
struct IConsoleCmdArgs;
namespace Audio
namespace Audio::CVars
{
///////////////////////////////////////////////////////////////////////////////////////////////////
// AZ CVars (new)
AZ_CVAR_EXTERNED(AZ::u64, s_ATLMemorySize);
AZ_CVAR_EXTERNED(AZ::u64, s_FileCacheManagerMemorySize);
AZ_CVAR_EXTERNED(AZ::u64, s_AudioObjectPoolSize);
AZ_CVAR_EXTERNED(AZ::u64, s_AudioEventPoolSize);
AZ_CVAR_EXTERNED(bool, s_EnableRaycasts);
AZ_CVAR_EXTERNED(float, s_RaycastMinDistance);
AZ_CVAR_EXTERNED(float, s_RaycastMaxDistance);
AZ_CVAR_EXTERNED(float, s_RaycastCacheTimeMs);
AZ_CVAR_EXTERNED(float, s_RaycastSmoothFactor);
AZ_CVAR_EXTERNED(float, s_PositionUpdateThreshold);
AZ_CVAR_EXTERNED(float, s_VelocityTrackingThreshold);
AZ_CVAR_EXTERNED(AZ::u32, s_AudioProxiesInitType);
#if !defined(AUDIO_RELEASE)
AZ_CVAR_EXTERNED(bool, s_IgnoreWindowFocus);
AZ_CVAR_EXTERNED(bool, s_ShowActiveAudioObjectsOnly);
AZ_CVAR_EXTERNED(AZ::CVarFixedString, s_AudioTriggersDebugFilter);
AZ_CVAR_EXTERNED(AZ::CVarFixedString, s_AudioObjectsDebugFilter);
#endif // !AUDIO_RELEASE
} // namespace Audio::CVars
namespace Audio
{
///////////////////////////////////////////////////////////////////////////////////////////////////
class CSoundCVars
{
public:
CSoundCVars();
~CSoundCVars();
~CSoundCVars() = default;
CSoundCVars(const CSoundCVars&) = delete; // Copy protection
CSoundCVars& operator=(const CSoundCVars&) = delete; // Copy protection
@@ -36,27 +55,10 @@ namespace Audio
void RegisterVariables();
void UnregisterVariables();
int m_nATLPoolSize;
int m_nFileCacheManagerSize;
int m_nAudioObjectPoolSize;
int m_nAudioEventPoolSize;
int m_nAudioProxiesInitType;
float m_fPositionUpdateThreshold;
float m_fVelocityTrackingThreshold;
float m_audioListenerTranslationZOffset;
float m_audioListenerTranslationPercentage;
#if !defined(AUDIO_RELEASE)
int m_nIgnoreWindowFocus;
int m_nDrawAudioDebug;
int m_nFileCacheManagerDebugFilter;
int m_nAudioLoggingOptions;
int m_nShowActiveAudioObjectsOnly;
ICVar* m_pAudioTriggersDebugFilter;
ICVar* m_pAudioObjectsDebugFilter;
private:
static void CmdExecuteTrigger(IConsoleCmdArgs* pCmdArgs);