Skip to content

Commit

Permalink
wip: Fix Amplitude plugin build.
Browse files Browse the repository at this point in the history
  • Loading branch information
na2axl committed Oct 29, 2024
1 parent 7d35aaf commit cb9eafb
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 59 deletions.
111 changes: 55 additions & 56 deletions Code/EnginePlugins/AmplitudeAudioPlugin/AmplitudeAudioSingleton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,29 @@ using namespace SparkyStudios::Audio;

namespace Log
{
static void Write(const char* format, va_list args)
static class Impl final : public Amplitude::Logger
{
if (format && format[0] != '\0')
protected:
void Log(Amplitude::eLogMessageLevel level, const char* file, int line, const Amplitude::AmString& message) override
{
constexpr size_t bufferLen = 1024;
char buffer[bufferLen] = "[Amplitude] ";

vsnprintf(buffer + 12, bufferLen - 12, format, args);

buffer[bufferLen - 1] = '\0';

ezLog::Debug("{0}", buffer);
switch (level)
{
case Amplitude::eLogMessageLevel_Debug:
ezLog::Debug("[Amplitude] {0}", message.c_str());
break;
case Amplitude::eLogMessageLevel_Info:
ezLog::Info("[Amplitude] {0}", message.c_str());
break;
case Amplitude::eLogMessageLevel_Warning:
ezLog::Warning("[Amplitude] {0}", message.c_str());
break;
case Amplitude::eLogMessageLevel_Critical:
case Amplitude::eLogMessageLevel_Error:
ezLog::Error("[Amplitude] {0}", message.c_str());
break;
}
}
}
} g_Logger;

static void DeviceNotification(Amplitude::DeviceNotification notification, const Amplitude::DeviceDescription& device, Amplitude::Driver* driver)
{
Expand All @@ -63,52 +72,51 @@ namespace Log

namespace Memory
{
static Amplitude::AmVoidPtr Malloc([[maybe_unused]] Amplitude::MemoryPoolKind pool, Amplitude::AmSize size)
{
return ezAudioMiddlewareAllocatorWrapper::GetAllocator()->Allocate(size, EZ_AUDIOSYSTEM_MEMORY_ALIGNMENT);
}

static Amplitude::AmVoidPtr Malign([[maybe_unused]] Amplitude::MemoryPoolKind pool, Amplitude::AmSize size, Amplitude::AmUInt32 alignment)
class Impl final : public Amplitude::MemoryAllocator
{
return ezAudioMiddlewareAllocatorWrapper::GetAllocator()->Allocate(size, alignment);
}
Amplitude::AmVoidPtr Malloc([[maybe_unused]] Amplitude::eMemoryPoolKind pool, Amplitude::AmSize size) override
{
return ezAudioMiddlewareAllocatorWrapper::GetAllocator()->Allocate(size, EZ_AUDIOSYSTEM_MEMORY_ALIGNMENT);
}

static Amplitude::AmVoidPtr Realloc(Amplitude::MemoryPoolKind pool, Amplitude::AmVoidPtr address, Amplitude::AmSize size)
{
if (address == nullptr)
return Malloc(pool, size);
Amplitude::AmVoidPtr Malign([[maybe_unused]] Amplitude::eMemoryPoolKind pool, Amplitude::AmSize size, Amplitude::AmUInt32 alignment) override
{
return ezAudioMiddlewareAllocatorWrapper::GetAllocator()->Allocate(size, alignment);
}

return ezAudioMiddlewareAllocatorWrapper::GetAllocator()->Reallocate(address, ezAudioMiddlewareAllocatorWrapper::GetAllocator()->AllocatedSize(address), size, EZ_AUDIOSYSTEM_MEMORY_ALIGNMENT);
}
Amplitude::AmVoidPtr Realloc(Amplitude::eMemoryPoolKind pool, Amplitude::AmVoidPtr address, Amplitude::AmSize size) override
{
if (address == nullptr)
return Malloc(pool, size);

static Amplitude::AmVoidPtr Realign(Amplitude::MemoryPoolKind pool, Amplitude::AmVoidPtr address, Amplitude::AmSize size, Amplitude::AmUInt32 alignment)
{
if (address == nullptr)
return Malign(pool, size, alignment);
return ezAudioMiddlewareAllocatorWrapper::GetAllocator()->Reallocate(address, ezAudioMiddlewareAllocatorWrapper::GetAllocator()->AllocatedSize(address), size, EZ_AUDIOSYSTEM_MEMORY_ALIGNMENT);
}

return ezAudioMiddlewareAllocatorWrapper::GetAllocator()->Reallocate(address, ezAudioMiddlewareAllocatorWrapper::GetAllocator()->AllocatedSize(address), size, alignment);
}
Amplitude::AmVoidPtr Realign(Amplitude::eMemoryPoolKind pool, Amplitude::AmVoidPtr address, Amplitude::AmSize size, Amplitude::AmUInt32 alignment) override
{
if (address == nullptr)
return Malign(pool, size, alignment);

static void Free([[maybe_unused]] Amplitude::MemoryPoolKind pool, Amplitude::AmVoidPtr address)
{
ezAudioMiddlewareAllocatorWrapper::GetAllocator()->Deallocate(address);
}
return ezAudioMiddlewareAllocatorWrapper::GetAllocator()->Reallocate(address, ezAudioMiddlewareAllocatorWrapper::GetAllocator()->AllocatedSize(address), size, alignment);
}

static Amplitude::AmSize TotalMemorySize()
{
return ezAudioMiddlewareAllocatorWrapper::GetAllocator()->GetStats().m_uiAllocationSize;
}
void Free([[maybe_unused]] Amplitude::eMemoryPoolKind pool, Amplitude::AmVoidPtr address) override
{
ezAudioMiddlewareAllocatorWrapper::GetAllocator()->Deallocate(address);
}

static Amplitude::AmSize SizeOfMemory([[maybe_unused]] Amplitude::MemoryPoolKind pool, Amplitude::AmConstVoidPtr address)
{
return ezAudioMiddlewareAllocatorWrapper::GetAllocator()->AllocatedSize(address);
}
Amplitude::AmSize SizeOf([[maybe_unused]] Amplitude::eMemoryPoolKind pool, Amplitude::AmVoidPtr address) override
{
return ezAudioMiddlewareAllocatorWrapper::GetAllocator()->AllocatedSize(address);
}
};
} // namespace Memory

namespace Utils
{
static AmVec3 ezVec3ToAmVec3(const ezVec3& vec)
{
// Amplitude and ezEngine use the same coordinate system, so no conversion is needed
return AM_V3(vec.x, vec.y, vec.z);
}
} // namespace Utils
Expand Down Expand Up @@ -211,16 +219,7 @@ ezResult ezAmplitude::Startup()
if (m_bInitialized)
return EZ_SUCCESS;

Amplitude::MemoryManagerConfig memConfig;
memConfig.alignedMalloc = Memory::Malign;
memConfig.alignedRealloc = Memory::Realign;
memConfig.free = Memory::Free;
memConfig.malloc = Memory::Malloc;
memConfig.realloc = Memory::Realloc;
memConfig.sizeOf = Memory::SizeOfMemory;
memConfig.totalReservedMemorySize = Memory::TotalMemorySize;

Amplitude::MemoryManager::Initialize(memConfig);
Amplitude::MemoryManager::Initialize(std::make_unique<Memory::Impl>());
EZ_ASSERT_DEBUG(Amplitude::MemoryManager::IsInitialized(), "Amplitude memory manager not initialized.");

DetectPlatform();
Expand All @@ -234,7 +233,7 @@ ezResult ezAmplitude::Startup()
const auto& config = m_pData->m_Configs.m_AssetProfiles[m_pData->m_sPlatform];

// Initialize the engine
Amplitude::RegisterLogFunc(Log::Write);
Amplitude::Logger::SetLogger(&Log::g_Logger);
Amplitude::RegisterDeviceNotificationCallback(Log::DeviceNotification);

ezStringBuilder assetsPath;
Expand Down Expand Up @@ -424,7 +423,7 @@ ezResult ezAmplitude::SetEntityTransform(ezAudioSystemEntityData* pEntityData, c
if (const Amplitude::Entity& entity = m_pEngine->GetEntity(pAmplitudeEntity->m_uiAmId); entity.Valid())
{
entity.SetLocation(Utils::ezVec3ToAmVec3(Transform.m_vPosition));
entity.SetOrientation(Utils::ezVec3ToAmVec3(-Transform.m_vForward), Utils::ezVec3ToAmVec3(Transform.m_vUp));
entity.SetOrientation(Amplitude::Orientation(Utils::ezVec3ToAmVec3(-Transform.m_vForward), Utils::ezVec3ToAmVec3(Transform.m_vUp)));
}

return EZ_SUCCESS;
Expand Down Expand Up @@ -709,7 +708,7 @@ ezResult ezAmplitude::SetListenerTransform(ezAudioSystemListenerData* pListenerD
if (const Amplitude::Listener& listener = m_pEngine->GetListener(pAmplitudeListener->m_uiAmId); listener.Valid())
{
listener.SetLocation(Utils::ezVec3ToAmVec3(Transform.m_vPosition));
listener.SetOrientation(Utils::ezVec3ToAmVec3(-Transform.m_vForward), Utils::ezVec3ToAmVec3(Transform.m_vUp));
listener.SetOrientation(Amplitude::Orientation(Utils::ezVec3ToAmVec3(-Transform.m_vForward), Utils::ezVec3ToAmVec3(Transform.m_vUp)));
}

return EZ_SUCCESS;
Expand Down
5 changes: 2 additions & 3 deletions Code/EnginePlugins/AmplitudeAudioPlugin/init.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
### Amplitude Audio Support for EZ Engine
###########################################

set (EZ_3RDPARTY_AMPLITUDE_SUPPORT ON CACHE BOOL "Whether to add support for the Amplitude Audio Engine.")
set(EZ_3RDPARTY_AMPLITUDE_SUPPORT ON CACHE BOOL "Whether to add support for the Amplitude Audio Engine.")
mark_as_advanced(FORCE EZ_3RDPARTY_AMPLITUDE_SUPPORT)

list(APPEND CMAKE_MODULE_PATH "$ENV{AM_SDK_PATH}/cmake" "${AM_SDK_PATH}/cmake")
set(AM_SDK_PLATFORM ${VCPKG_TARGET_TRIPLET})

find_package(AmplitudeAudioSDK REQUIRED)

######################################
Expand All @@ -40,5 +40,4 @@ function(ez_link_target_amplitude TARGET_NAME)

target_link_libraries(${TARGET_NAME} PRIVATE SparkyStudios::Audio::Amplitude::SDK::Shared)
ez_uwp_mark_import_as_content(SparkyStudios::Audio::Amplitude::SDK::Shared)
# target_link_libraries(${TARGET_NAME} PRIVATE ezAmplitude::libsamplerate)
endfunction()

0 comments on commit cb9eafb

Please sign in to comment.