Commit 53fccd17 authored by Dipl.-Ing. Jonas Stienen's avatar Dipl.-Ing. Jonas Stienen
Browse files

Starting to find bug in pool handling of scene updates

parent 4bacf059
......@@ -346,7 +346,10 @@ void CVAContainerState::SetObject( const int iID, CVASceneStateBase* pObject )
// Referenz auf altem Objekt entfernen und bei neuem Objekt hinzufgen
pObject->AddReference();
if( i->second )
{
assert( i->second->GetNumReferences() > 0 );
i->second->RemoveReference();
}
i->second = pObject;
return;
......
......@@ -20,14 +20,10 @@
#include "VAMotionState.h"
#include <cassert>
#include <cmath>
void CVAReceiverState::Initialize( double dModificationTime )
{
// Nullposition
data.pMotionState = GetManager()->RequestMotionState();
data.pMotionState->Initialize( dModificationTime );
data.pMotionState = nullptr; // undefined position
data.iAuraMode = IVAInterface::VA_AURAMODE_ALL;
data.iDirectivityID = -1;
data.pDirectivity = nullptr;
......@@ -42,7 +38,11 @@ void CVAReceiverState::Copy( const CVAReceiverState* pSrc, double dModificationT
assert( pSrc->IsFixed() );
// Abhngige Objekte des Vorlagenobjektes autonom referenzieren
pSrc->data.pMotionState->AddReference();
if( pSrc->data.pMotionState )
{
assert( pSrc->data.pMotionState->GetNumReferences() > 0 );
pSrc->data.pMotionState->AddReference();
}
// Daten kopieren
data = pSrc->data;
......@@ -50,23 +50,32 @@ void CVAReceiverState::Copy( const CVAReceiverState* pSrc, double dModificationT
SetModificationTime( dModificationTime );
}
void CVAReceiverState::Fix() {
void CVAReceiverState::Fix()
{
// Alle enthaltenen Objekte fixieren
if( data.pMotionState ) data.pMotionState->Fix();
if( data.pMotionState )
data.pMotionState->Fix();
// Selbst fixieren
CVASceneStateBase::Fix();
}
void CVAReceiverState::PreRelease() {
void CVAReceiverState::PreRelease()
{
// Alle Referenzen auf abhngige Objekte entfernen
if( data.pMotionState ) data.pMotionState->RemoveReference();
if( data.pMotionState )
{
assert( data.pMotionState->GetNumReferences() > 0 );
data.pMotionState->RemoveReference();
data.pMotionState = NULL;
}
// Funktion der Oberklasse aufrufen
CVASceneStateBase::PreRelease();
}
const CVAMotionState* CVAReceiverState::GetMotionState() const {
const CVAMotionState* CVAReceiverState::GetMotionState() const
{
return data.pMotionState;
}
......@@ -88,19 +97,28 @@ CVAMotionState* CVAReceiverState::AlterMotionState()
// Falls der Zustand finalisiert => Zustand aus der Basiskonfig => Autonomen Zustand erzeugen
// Falls der Zustand nicht finalisiert => Bereits erzeugter autonomen Zustand => Diesen zurckgeben
if( data.pMotionState->IsFixed() )
if( !data.pMotionState )
{
// Autonomen Zustand ableiten
CVAMotionState* pNewState = GetManager()->RequestMotionState();
// nderungszeit des bergeordneten Szenezustands bernehmen
double dCreationTime = GetModificationTime();
pNewState->Copy( data.pMotionState, dCreationTime );
data.pMotionState->RemoveReference();
data.pMotionState = pNewState;
data.pMotionState = GetManager()->RequestMotionState();
data.pMotionState->Initialize( GetModificationTime() );
}
else
{
if( data.pMotionState->IsFixed() )
{
// Autonomen Zustand ableiten
CVAMotionState* pNewState = GetManager()->RequestMotionState();
// nderungszeit des bergeordneten Szenezustands bernehmen
double dCreationTime = GetModificationTime();
pNewState->Copy( data.pMotionState, dCreationTime );
data.pMotionState->RemoveReference();
data.pMotionState = pNewState;
}
}
VA_TRACE( "SoundReceiverState", "Requested new motion state" );
return data.pMotionState;
}
......@@ -201,5 +219,4 @@ double CVAReceiverState::CVAAnthropometricParameter::GetHeadDepthParameterFromLU
b = 0;
return ( m_vvdHeadDepthParameterLUT[ a ][ b ] );
}
......@@ -218,6 +218,7 @@ CVASoundSourceState* CVASceneManager::RequestSoundSourceState()
{
CVASoundSourceState* pState = dynamic_cast< CVASoundSourceState* >( m_pPoolSourceStates->RequestObject() );
pState->SetManager( this );
assert( pState->GetNumReferences() == 1 );
return pState;
}
......
......@@ -142,7 +142,8 @@ CVASoundSourceState* CVASceneState::AlterSoundSourceState( const int iSourceID )
assert( pList );
// Zustand der Quelle fr Modifkation ableiten
if( pCurState->IsFixed() ) {
if( pCurState->IsFixed() )
{
// Autonomen Zustand ableiten
CVASoundSourceState* pNewState = GetManager()->RequestSoundSourceState();
......
......@@ -15,13 +15,10 @@
#include <VA.h>
#include "../Directivities/VADirectivity.h"
#include "../VALog.h"
#include "VASceneManager.h"
#include "VAMotionState.h"
#include <ITANumericUtils.h>
#include <cassert>
void CVASoundSourceState::Initialize( double dModificationTime )
......@@ -29,8 +26,8 @@ void CVASoundSourceState::Initialize( double dModificationTime )
data.pMotionState = nullptr; // undefined position
data.dSoundPower = g_dSoundPower_94dB_SPL_1m;
data.iAuraMode = IVAInterface::VA_AURAMODE_ALL;
data.iDirID = -1;
data.pDirData = nullptr;
data.iDirectivityID = -1;
data.pDirectivity = nullptr;
SetModificationTime( dModificationTime );
}
......@@ -43,7 +40,10 @@ void CVASoundSourceState::Copy( const CVASoundSourceState* pSrc, double dModific
// Abhngige Objekte des Vorlagenobjektes autonom referenzieren
if( pSrc->data.pMotionState )
{
assert( pSrc->data.pMotionState->GetNumReferences() > 0 );
pSrc->data.pMotionState->AddReference();
}
// Daten kopieren
data = pSrc->data;
......@@ -65,7 +65,11 @@ void CVASoundSourceState::PreRelease()
{
// Alle Referenzen auf abhngige Objekte entfernen
if( data.pMotionState )
{
assert( data.pMotionState->GetNumReferences() > 0 );
data.pMotionState->RemoveReference();
data.pMotionState = NULL;
}
// Funktion der Oberklasse aufrufen
CVASceneStateBase::PreRelease();
......@@ -128,25 +132,25 @@ double CVASoundSourceState::GetSoundPower() const
int CVASoundSourceState::GetDirectivityID() const
{
return data.iDirID;
return data.iDirectivityID;
}
const IVADirectivity* CVASoundSourceState::GetDirectivityData() const
{
return data.pDirData;
return data.pDirectivity;
}
void CVASoundSourceState::SetDirectivityID( int iDirectivityID )
{
assert( !IsFixed() );
data.iDirID = iDirectivityID;
data.iDirectivityID = iDirectivityID;
VA_VERBOSE( "SoundSourceState", "Directivity identifier changed" );
}
void CVASoundSourceState::SetDirectivityData( const IVADirectivity* pDirData )
{
assert( !IsFixed() );
data.pDirData = pDirData;
data.pDirectivity = pDirData;
VA_VERBOSE( "SoundSourceState", "Directivity dataset changed" );
}
......
......@@ -86,8 +86,8 @@ private:
CVAMotionState* pMotionState; //!< Motion state pointer
double dSoundPower; //!< Sound power [W]
int iAuraMode; //!< Current auralization mode
int iDirID; //!< Directivity identifier
const IVADirectivity* pDirData; //!< Pointer to directivity data set
int iDirectivityID; //!< Directivity identifier
const IVADirectivity* pDirectivity; //!< Pointer to directivity data set
CVAStruct oParams; //!< Sound source parameters for special implementations
} data;
......
......@@ -2034,27 +2034,22 @@ int CVACoreImpl::DeleteSoundSource( const int iSoundSourceID )
VA_TRY
{
m_pNewSceneState->RemoveSoundSource( iSoundSourceID );
int iResult = 0;
if( iResult == 0 )
{
// Ereignis generieren, wenn erfolgreich
CVAEvent ev;
ev.iEventType = CVAEvent::SOUND_SOURCE_DELETED;
ev.pSender = this;
ev.iObjectID = iSoundSourceID;
m_pEventManager->EnqueueEvent( ev );
}
// Ereignis generieren, wenn erfolgreich
CVAEvent ev;
ev.iEventType = CVAEvent::SOUND_SOURCE_DELETED;
ev.pSender = this;
ev.iObjectID = iSoundSourceID;
m_pEventManager->EnqueueEvent( ev );
if( !bSync )
UnlockUpdate();
VA_INFO( "Core", "Deleted sound source " << iSoundSourceID );
return iResult;
return 0;
}
VA_FINALLY
VA_FINALLY
{
if( !bSync )
UnlockUpdate();
......@@ -3174,7 +3169,7 @@ void CVACoreImpl::SetSoundReceiverDirectivity( const int iID, const int iDirecti
if( !bSync )
UnlockUpdate();
VA_INFO( "Core", "Linked sound receiver " + std::to_string( long( iID ) ) + " with HRIR dataset " + std::to_string( long( iDirectivityID ) ) );
VA_INFO( "Core", "Linked sound receiver " + std::to_string( long( iID ) ) + " with receiver directivity dataset " + std::to_string( long( iDirectivityID ) ) );
}
VA_RETHROW;
......
......@@ -7,7 +7,7 @@
using namespace std;
IVAInterface* core = NULL;
IVAInterface* va = NULL;
class EventBasedGenericRenderingController : public IVAEventHandler
{
......@@ -33,7 +33,7 @@ public:
oArgs[ "SourceID" ] = 1;
try
{
oReturn = core->CallModule( "GenericPath:MyGenericRenderer", oArgs );
oReturn = va->CallModule( "GenericPath:MyGenericRenderer", oArgs );
}
catch( CVAException& e )
{
......@@ -57,10 +57,76 @@ public:
};
CoreEventDumper dumper;
void bugfix_scene_pool_clearance_issue();
void TestModuleInterface();
void AudioRenderers();
void AudioReproductions();
void CreateHRIRs();
void CreateAudioSignals();
void CreateScene();
void ConnectSignals();
void TestSignalAndSourceConnections();
int main( int, char** )
{
try
{
va = VACore::CreateCoreInstance( "../conf/VACore.ini" );
//va = VACore::CreateCoreInstance( GetCoreConfig() );
// Attach (register) event handler
//va->AttachEventHandler( &dumper );
va->AttachEventHandler( &rendering_controller );
CVAVersionInfo ver;
va->GetVersionInfo( &ver );
cout << ver.ToString() << endl;
va->Initialize();
va->AddSearchPath( "../data" );
/*
TestModuleInterface();
AudioRenderers();
AudioReproductions();
CreateHRIRs();
CreateAudioSignals();
CreateScene();
//ConnectSignals();
TestSignalAndSourceConnections();
*/
bugfix_scene_pool_clearance_issue();
va->SetGlobalAuralizationMode( IVAInterface::VA_AURAMODE_ALL );
VistaTimeUtils::Sleep( 10000 );
va->Finalize();
}
catch( CVAException& e )
{
cerr << "Error: " << e << endl;
int iErrorCode = e.GetErrorCode();
delete va;
return iErrorCode;
}
delete va;
return 0;
}
void AudioRenderers()
{
std::vector< CVAAudioRendererInfo > voRenderers;
core->GetRenderingModules( voRenderers );
va->GetRenderingModules( voRenderers );
if( voRenderers.size() )
cout << "Found " << voRenderers.size() << " audio renderer" << endl;
......@@ -76,7 +142,7 @@ void AudioRenderers()
void AudioReproductions()
{
std::vector< CVAAudioReproductionInfo > voReproductions;
core->GetReproductionModules( voReproductions );
va->GetReproductionModules( voReproductions );
if( voReproductions.size() )
cout << "Found " << voReproductions.size() << " audio renderer" << endl;
......@@ -92,7 +158,7 @@ void AudioReproductions()
void TestModuleInterface()
{
std::vector< CVAModuleInfo > viModuleInfos;
core->GetModules( viModuleInfos );
va->GetModules( viModuleInfos );
if( viModuleInfos.size() )
cout << "Found " << viModuleInfos.size() << " modules" << endl;
......@@ -105,7 +171,6 @@ void TestModuleInterface()
CVAStruct GetCoreConfig()
{
CVAStruct oConfig;
CVAStruct oSectionDebug;
......@@ -150,109 +215,92 @@ void CreateAudioSignals()
string sNetStreamID;
try
{
sNetStreamID = core->CreateSignalSourceNetworkStream( "localhost", 12480, "CoreTestNetStream" );
sNetStreamID = va->CreateSignalSourceNetworkStream( "localhost", 12480, "CoreTestNetStream" );
}
catch( CVAException& e )
{
cerr << "Caught exception during stream signal source connection:" << e << endl;
}
string sFileID = core->CreateSignalSourceBufferFromFile( "Audiofiles/Bauer.wav" );
core->SetSignalSourceBufferPlaybackAction( sFileID, IVAInterface::VA_PLAYBACK_ACTION_PLAY );
core->SetSignalSourceBufferLooping( sFileID, true );
string sFileID = va->CreateSignalSourceBufferFromFile( "$(DemoSound)" );
va->SetSignalSourceBufferPlaybackAction( sFileID, IVAInterface::VA_PLAYBACK_ACTION_PLAY );
va->SetSignalSourceBufferLooping( sFileID, true );
}
void CreateHRIRs()
{
core->CreateDirectivityFromFile( "HRIR/ITA-Kunstkopf_HRIR_AP11_Pressure_Equalized_3x3_256.v17.ir.daff" );
va->CreateDirectivityFromFile( "$(DefaultHRIR)" );
}
void CreateScene()
{
int iListenerID = core->CreateSoundReceiver( "MyListener" );
core->SetSoundReceiverAuralizationMode( iListenerID, IVAInterface::VA_AURAMODE_ALL );
core->SetSoundReceiverOrientationVU( iListenerID, VAVec3( 0.7172f, 0.0f, -0.7172f ), VAVec3( 0, 1, 0 ) );
core->SetSoundReceiverDirectivity( iListenerID, 1 );
int iListenerID = va->CreateSoundReceiver( "MyListener" );
va->SetSoundReceiverAuralizationMode( iListenerID, IVAInterface::VA_AURAMODE_ALL );
va->SetSoundReceiverOrientationVU( iListenerID, VAVec3( 0.7172f, 0.0f, -0.7172f ), VAVec3( 0, 1, 0 ) );
va->SetSoundReceiverDirectivity( iListenerID, 1 );
core->SetActiveSoundReceiver( iListenerID );
va->SetActiveSoundReceiver( iListenerID );
int iSoundSource = core->CreateSoundSource( "MySoundSource" );
core->SetSoundSourcePosition( iSoundSource, VAVec3( -2.0f, 0, 0 ) );
int iSoundSource = va->CreateSoundSource( "MySoundSource" );
va->SetSoundSourcePosition( iSoundSource, VAVec3( -2.0f, 0, 0 ) );
}
void ConnectSignals()
{
//core->SetSoundSourceSignalSource( 1, "audiofile1" );
core->SetSoundSourceSignalSource( 1, "netstream1" );
}
int main()
void TestSignalAndSourceConnections()
{
int iSourceID = va->CreateSoundSource();
string sSignalID = va->CreateSignalSourceBufferFromFile( "$(DemoSound)" );
va->SetSoundSourceSignalSource( iSourceID, sSignalID );
va->SetSoundSourceSignalSource( iSourceID, "" );
va->SetSoundSourceSignalSource( iSourceID, sSignalID );
va->SetSoundSourceSignalSource( iSourceID, sSignalID );
va->SetSoundSourceSignalSource( iSourceID, sSignalID );
va->SetSoundSourceSignalSource( iSourceID, sSignalID );
va->SetSoundSourceSignalSource( iSourceID, "" );
va->DeleteSignalSource( sSignalID );
sSignalID = va->CreateSignalSourceBufferFromFile( "$(DemoSound)" );
va->DeleteSignalSource( sSignalID );
sSignalID = va->CreateSignalSourceBufferFromFile( "$(DemoSound)" );
string sSignalID2 = va->CreateSignalSourceBufferFromFile( "$(DemoSound)" );
va->SetSoundSourceSignalSource( iSourceID, sSignalID );
va->SetSoundSourceSignalSource( iSourceID, sSignalID2 );
try
{
core = VACore::CreateCoreInstance( "../conf/VACore.ini" );
//core = VACore::CreateCoreInstance( GetCoreConfig() );
// Attach (register) event handler
core->AttachEventHandler( &dumper );
core->AttachEventHandler( &rendering_controller );
CVAVersionInfo ver;
core->GetVersionInfo( &ver );
cout << ver.ToString() << endl;
core->Initialize();
core->AddSearchPath( "../data" );
TestModuleInterface();
AudioRenderers();
AudioReproductions();
CreateHRIRs();
CreateAudioSignals();
CreateScene();
ConnectSignals();
core->SetGlobalAuralizationMode( IVAInterface::VA_AURAMODE_ALL );
VistaTimeUtils::Sleep( 10000 );
core->Finalize();
va->DeleteSignalSource( sSignalID2 );
}
catch( CVAException& e )
catch( CVAException e )
{
cerr << "Error: " << e << endl;
int iErrorCode = e.GetErrorCode();
delete core;
return iErrorCode;
; // good
}
va->DeleteSoundSource( iSourceID );
va->DeleteSignalSource( sSignalID2 );
}
delete core;
return 0;
void ConnectSignals()
{
//va->SetSoundSourceSignalSource( 1, "audiofile1" );
va->SetSoundSourceSignalSource( 1, "netstream1" );
}
void testLoadDirectivity()
{
cout << "Loading a directivity" << endl;
cout << "Load 1: ID = " << core->CreateDirectivityFromFile( "D:/Temp/Directivity/trompete1.ddb", "Trompete1" ) << endl;
cout << "Load 1: ID = " << va->CreateDirectivityFromFile( "D:/Temp/Directivity/trompete1.ddb", "Trompete1" ) << endl;
//
//// Test: Gleiches Sound nochmal laden...
//cout << "Load 2: ID = " << (id = core->LoadSound("ding.wav", "Max")) << endl;
//cout << "Load 2: ID = " << (id = va->LoadSound("ding.wav", "Max")) << endl;
//cout << "Load 3: ID = " << core->LoadSound("D:/ding.wav", "Max") << endl;
//cout << "Load 3: ID = " << va->LoadSound("D:/ding.wav", "Max") << endl;
//core->PrintDirectivityInfos();
//va->PrintDirectivityInfos();
//cout << "Freeing Sound " << id << endl;
//core->FreeSound(id);
//va->FreeSound(id);
//core->PrintDirectivityInfos();
//va->PrintDirectivityInfos();
}
void testLoadSound()
......@@ -261,25 +309,25 @@ void testLoadSound()
int id1, id2, id3;
const std::string sSequencerID = core->CreateSignalSourceSequencer( "MySequencer" );
const std::string sSequencerID = va->CreateSignalSourceSequencer( "MySequencer" );
CVAStruct oSequencerSample;
oSequencerSample[ "name" ] = "Max";
oSequencerSample[ "filepath" ] = "ding.wav";
cout << "Load 1: ID = " << ( id1 = core->AddSignalSourceSequencerSample( sSequencerID, oSequencerSample ) ) << endl;
cout << "Load 1: ID = " << ( id1 = va->AddSignalSourceSequencerSample( sSequencerID, oSequencerSample ) ) << endl;
// Test: Gleiches Sound nochmal laden...
cout << "Load 2: ID = " << ( id2 = core->AddSignalSourceSequencerSample( sSequencerID, oSequencerSample ) ) << endl;
cout << "Load 2: ID = " << ( id2 = va->AddSignalSourceSequencerSample( sSequencerID, oSequencerSample ) ) << endl;
oSequencerSample[ "name" ] = "Moritz";
oSequencerSample[ "filepath" ] = "dong.wav";
cout << "Load 3: ID = " << ( id3 = core->AddSignalSourceSequencerSample( sSequencerID, oSequencerSample ) ) << endl;
cout << "Load 3: ID = " << ( id3 = va->AddSignalSourceSequencerSample( sSequencerID, oSequencerSample ) ) << endl;
//core->PrintSoundInfos();
//va->PrintSoundInfos();
cout << "Freeing Sound " << id1 << endl;
core->RemoveSignalSourceSequencerSample( sSequencerID, id1 );
va->RemoveSignalSourceSequencerSample( sSequencerID, id1 );
//core->PrintSoundInfos();
//va->PrintSoundInfos();
}
void testScene()
......@@ -288,64 +336,78 @@ void testScene()
int iSource1, iSource2, iSource3;
iSource1 = core->CreateSoundSource( "Source1" );
//core->SetSoundSourceName(iSource1, "Max der Erste");
iSource1 = va->CreateSoundSource( "Source1" );
//va->SetSoundSourceName(iSource1, "Max der Erste");
cout << "Create sound source 1: ID = " << iSource1 << endl;
core->LockUpdate();
va->LockUpdate();
iSource2 = core->CreateSoundSource( "Source2" );
//core->SetSoundSourceName(iSource2, "Klaus die Katze");
iSource2 = va->CreateSoundSource( "Source2" );
//va->SetSoundSourceName(iSource2, "Klaus die Katze");
cout << "Create sound source 1: ID = " << iSource2 << endl;
iSource3 = core->CreateSoundSource( "Source3" );
iSource3 = va->CreateSoundSource( "Source3" );
cout << "Create sound source 1: ID = " << iSource3 << endl;
// Positions & orientations
core->SetSoundSourceOrientationVU( iSource1, VAVec3( 1, 2, 3 ), VAVec3( 4, 5, 6 ) );
core->SetSoundSourcePosition( iSource2, VAVec3( 47, 11, 0 ) );
//core->SetSoundSourceOrientationYPR(iSource3, 47, 11, 0);
va->SetSoundSourceOrientationVU( iSource1, VAVec3( 1, 2, 3 ), VAVec3( 4, 5, 6 ) );
va->SetSoundSourcePosition( iSource2, VAVec3( 47, 11, 0 ) );
//va->SetSoundSourceOrientationYPR(iSource3, 47, 11, 0);
//cout << "Create listener 1: ID = " << core->CreateListener("Listener1") << endl;
core->UnlockUpdate();
//cout << "Create listener 1: ID = " << va->CreateListener("Listener1") << endl;
va->UnlockUpdate();
VAVec3 v3Pos;
VAQuat qOrient;
core->GetSoundSourcePose( iSource1, v3Pos, qOrient );
va->GetSoundSourcePose( iSource1, v3Pos, qOrient );