Files
o3de/Gems/AudioSystem/Code/Platform/Common/Default/AudioSystemGemSystemComponent_default.cpp
T
Eric Phister 0a68f23ee0 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.
2021-06-23 16:57:48 -05:00

68 lines
2.2 KiB
C++

/*
* 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