Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ ccp_add_library(CarbonAudio SHARED
src/AudGeometry.cpp
src/AudGeometry_Blue.cpp
src/AudObstructionOcclusion.cpp
src/AudRoom.cpp
src/AudRoom_Blue.cpp
src/AudRoomManager.cpp
src/SpatialAudioSettings.cpp
src/audio2.cpp
src/AudGameObjResource_Blue.cpp
Expand Down Expand Up @@ -86,6 +89,8 @@ target_sources(CarbonAudio PRIVATE
src/AudMusicPlayer.h
src/AudGeometry.h
src/AudObstructionOcclusion.h
src/AudRoom.h
src/AudRoomManager.h
src/SpatialAudioSettings.h
src/autoversion.h
src/DebugUtilities.h
Expand Down
12 changes: 7 additions & 5 deletions src/AudGameObjResource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
#include "SoundPrioritization.h"

//-----------------------------------------------------------------------------
// Helper function to distribute ID's
// Helper function to distribute ID's, shared with AudRoom
//-----------------------------------------------------------------------------
static AkGameObjectID GenerateEntityID()
AkGameObjectID AllocateGameObjectID()
{
static AkGameObjectID s_currentID = START_GAME_OBJ_COUNT;
return s_currentID++;
static std::atomic<AkGameObjectID> s_currentID{ START_GAME_OBJ_COUNT };
return s_currentID.fetch_add( 1, std::memory_order_relaxed );
}

AudGameObjResource::Orientation::Orientation( const Vector3& front_, const Vector3& top_ ) :
Expand Down Expand Up @@ -49,7 +49,7 @@ AudGameObjResource::AudGameObjResource( IRoot* lockobj ) : PARENTLOCK( m_paramet
m_waitingOneShotInRange( std::pair( std::chrono::steady_clock::now(), L"" ) ),
m_eventName(L"")
{
m_ID = GenerateEntityID();
m_ID = AllocateGameObjectID();

if (g_audioManager != nullptr)
{
Expand Down Expand Up @@ -142,6 +142,7 @@ void AudGameObjResource::UnregisterWwiseObject()
return;
}
m_gameObjRegistered = false;
g_audioManager->GetRoomManager().ForgetGameObject( m_ID );
}
}

Expand Down Expand Up @@ -463,6 +464,7 @@ int AudGameObjResource::ApplyEffectivePlacement( const Vector3& front, const Vec
RH2LH::convertEmitter( &soundPosLH, &tmp );

AK::SoundEngine::SetPosition( m_ID, soundPosLH );
g_audioManager->GetRoomManager().UpdateGameObjectPosition( m_ID, position );
}
return AK_Success;
}
Expand Down
8 changes: 8 additions & 0 deletions src/AudGeometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ AudGeometry::~AudGeometry()

void AudGeometry::ClearAllGeometry()
{
CcpAutoMutex lock( s_mutex );

if( s_geometrySetRefCounts.empty() )
{
return;
Expand Down Expand Up @@ -89,6 +91,8 @@ void AudGeometry::SetGeometry(
return;
}

CcpAutoMutex lock( s_mutex );

auto it = s_geometrySetRefCounts.find( geometrySetId );
if( it == s_geometrySetRefCounts.end() )
{
Expand Down Expand Up @@ -143,6 +147,8 @@ void AudGeometry::SetGeometryTransform(
return;
}

CcpAutoMutex lock( s_mutex );

if( s_geometrySetRefCounts.find( geometrySetId ) == s_geometrySetRefCounts.end() )
{
return;
Expand All @@ -161,6 +167,8 @@ void AudGeometry::RemoveGeometry(
uint64_t geometrySetId,
uint64_t instanceId )
{
CcpAutoMutex lock( s_mutex );

auto it = s_geometrySetRefCounts.find( geometrySetId );
if( it == s_geometrySetRefCounts.end() )
{
Expand Down
4 changes: 4 additions & 0 deletions src/AudGeometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

#include <unordered_map>

#include <CcpMutex.h>


/**
* @brief Registers meshes from Trinity as Spatial Audio geometry sets and manages their lifecycle.
Expand Down Expand Up @@ -85,7 +87,9 @@ BLUE_CLASS(AudGeometry) :
uint64_t geometrySetId, const Matrix& worldTransform );

/// Tracks how many active instances reference each geometry set.
/// Guarded by s_mutex, trinity sends transforms from worker threads.
inline static std::unordered_map<uint64_t, uint32_t> s_geometrySetRefCounts;
inline static CcpMutex s_mutex{ "AudGeometry", "s_mutex" };
};

TYPEDEF_BLUECLASS( AudGeometry );
22 changes: 15 additions & 7 deletions src/AudListener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,16 @@ AudListener::AudListener( IRoot* lockobj ) : AudGameObjResource( LISTENER_GAME_O

AudListener::~AudListener()
{
if( g_audioManager != nullptr && g_audioManager->GetSpatialAudioGeometryEnabled() )
if( g_audioManager != nullptr && g_audioManager->IsSpatialAudioInitialized() )
{
AK::SpatialAudio::UnregisterListener( m_ID );
}
AK::SoundEngine::RemoveDefaultListener( m_ID );
AK::SoundEngine::UnregisterGameObj( m_ID );
if( g_audioManager != nullptr )
{
g_audioManager->GetRoomManager().ForgetGameObject( m_ID );
}
}

void AudListener::RegisterWwiseObject()
Expand All @@ -33,13 +37,8 @@ void AudListener::RegisterWwiseObject()
AK::SoundEngine::RegisterGameObj(m_ID, m_name.c_str());
AK::SoundEngine::AddDefaultListener(m_ID);

// Register listener for occlusion/diffraction processing
if( g_audioManager != nullptr && g_audioManager->GetSpatialAudioGeometryEnabled() )
{
AK::SpatialAudio::RegisterListener( m_ID );
}

m_gameObjRegistered = true;
RegisterWithSpatialAudio();
}
}
else
Expand All @@ -49,6 +48,14 @@ void AudListener::RegisterWwiseObject()
}
}

void AudListener::RegisterWithSpatialAudio()
{
if( m_gameObjRegistered && g_audioManager != nullptr && g_audioManager->IsSpatialAudioInitialized() )
{
AK::SpatialAudio::RegisterListener( m_ID );
}
}

int AudListener::SetPlacementFromParent( const Vector3& front, const Vector3& top, const Vector3& position )
{
if( g_audioManager != nullptr && g_audioManager->GetState() != AudioState::Uninitialized )
Expand All @@ -66,6 +73,7 @@ int AudListener::SetPlacementFromParent( const Vector3& front, const Vector3& to
RH2LH::convertListener( &soundPosLH, &tmp );

AK::SoundEngine::SetPosition( m_ID, soundPosLH );
g_audioManager->GetRoomManager().UpdateGameObjectPosition( m_ID, position );
}
}
return AK_Success;
Expand Down
3 changes: 3 additions & 0 deletions src/AudListener.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ BLUE_CLASS( AudListener ) : public AudGameObjResource

void RegisterWwiseObject() override;
int SetPlacementFromParent( const Vector3& front, const Vector3& top, const Vector3& position ) override;

/// Registers the listener with Wwise Spatial Audio if both are initialized.
void RegisterWithSpatialAudio();
};

TYPEDEF_BLUECLASS( AudListener );
Expand Down
Loading