From 32449d41574d414abf4682d383c4810dfa966586 Mon Sep 17 00:00:00 2001 From: Lucas Moesch Date: Tue, 25 Sep 2018 12:05:55 +0200 Subject: [PATCH] WIP - fixing bugs --- .../VABinauralClusterEngine.cpp | 14 +++- .../VABinauralClusterEngine.h | 9 +-- .../VABinauralClustering.cpp | 67 ++++++++++--------- .../BinauralListener/VABinauralListener.h | 3 +- .../RealTime/VABinauralRealTimeRenderer.cpp | 38 +++++++++-- tests/CoreTest.cpp | 4 +- 6 files changed, 92 insertions(+), 43 deletions(-) diff --git a/src/Rendering/Binaural/RealTime/Utils/BinauralClusterEngine/VABinauralClusterEngine.cpp b/src/Rendering/Binaural/RealTime/Utils/BinauralClusterEngine/VABinauralClusterEngine.cpp index f502ff7..5073ce2 100644 --- a/src/Rendering/Binaural/RealTime/Utils/BinauralClusterEngine/VABinauralClusterEngine.cpp +++ b/src/Rendering/Binaural/RealTime/Utils/BinauralClusterEngine/VABinauralClusterEngine.cpp @@ -34,9 +34,11 @@ VABinauralClusterEngine::update() } VABinauralClustering* -VABinauralClusterEngine::getClustering(int listenerID) +VABinauralClusterEngine::getClustering(const int listenerID) { - std::map< int, VABinauralClustering* >::iterator it = _clusterings.find(listenerID); + const int id = listenerID; + + auto it = _clusterings.find(id); return it->second; } @@ -49,6 +51,8 @@ VABinauralClusterEngine::addSource( int sourceID, VABinauralSoundSource* source { it->second->addSource(sourceID, source); } + + _sources.insert(std::pair< int, VABinauralSoundSource* >(sourceID, source)); } void @@ -70,7 +74,13 @@ VABinauralClusterEngine::addListener(int listenerID, VABinauralListener* listene // add local reference _clusterings.insert(std::pair< int, VABinauralClustering* >(listenerID, clustering)); + _listeners.insert(std::pair< int, VABinauralListener* >(listenerID, listener)); + // add preexisting sources + for (auto const& sourceIt : _sources) + { + clustering->addSource(sourceIt.first, sourceIt.second); + } } void diff --git a/src/Rendering/Binaural/RealTime/Utils/BinauralClusterEngine/VABinauralClusterEngine.h b/src/Rendering/Binaural/RealTime/Utils/BinauralClusterEngine/VABinauralClusterEngine.h index 4a85143..2940fdc 100644 --- a/src/Rendering/Binaural/RealTime/Utils/BinauralClusterEngine/VABinauralClusterEngine.h +++ b/src/Rendering/Binaural/RealTime/Utils/BinauralClusterEngine/VABinauralClusterEngine.h @@ -21,6 +21,8 @@ public: int numCluster; }; + std::map< int, VABinauralClustering* > _clusterings; + ~VABinauralClusterEngine(); VABinauralClusterEngine(); @@ -29,7 +31,7 @@ public: update(); VABinauralClustering* - getClustering(int listenerID); + getClustering(const int listenerID); void addSource( int sourceID, VABinauralSoundSource* source ); @@ -45,13 +47,12 @@ public: private: std::map< int, VABinauralSoundSource* > _newSources; - std::map< int, VABinauralClustering* > _clusterings; IVAObjectPool* _sourcePool; IVAObjectPool* _clusteringPool; - //std::map< int, VABinauralSoundSource* > _sources; - //std::map< int, VABinauralListener* > _listener; + std::map< int, VABinauralSoundSource* > _sources; + std::map< int, VABinauralListener* > _listeners; }; diff --git a/src/Rendering/Binaural/RealTime/Utils/BinauralClusterEngine/VABinauralClustering.cpp b/src/Rendering/Binaural/RealTime/Utils/BinauralClusterEngine/VABinauralClustering.cpp index 1b158af..6230ec2 100644 --- a/src/Rendering/Binaural/RealTime/Utils/BinauralClusterEngine/VABinauralClustering.cpp +++ b/src/Rendering/Binaural/RealTime/Utils/BinauralClusterEngine/VABinauralClustering.cpp @@ -69,49 +69,56 @@ VABinauralClustering::getOutput() void VABinauralClustering::update() { - VABinauralClusteringState* state = new VABinauralClusteringState(*_curState); + //TODO: DIRTY HACK - // remove removed sources - std::set< int >::const_iterator it; - - for (it = _delSourceIDs.begin(); it != _delSourceIDs.end(); ++it) + if (_nextState == nullptr) { - // remove if in unassigned sources - std::map< int, VABinauralSoundSource* >::iterator delIt = _unassignedSources.find(*it); - VABinauralSoundSource* source = delIt->second; - state->removeSource(*it); + VABinauralClusteringState* state = new VABinauralClusteringState(*_curState); - _unassignedSources.erase(delIt); + // remove removed sources + std::set< int >::const_iterator it; - // remove if in assigned sources - delIt = _assignedSources.find(*it); - source = delIt->second; + for (it = _delSourceIDs.begin(); it != _delSourceIDs.end(); ++it) + { + // remove if in unassigned sources + std::map< int, VABinauralSoundSource* >::iterator delIt = _unassignedSources.find(*it); + VABinauralSoundSource* source = delIt->second; - _assignedSources.erase(delIt); - } + state->removeSource(*it); - // add unassigned sources - std::map< int , VABinauralSoundSource* >::iterator sourceIt; + _unassignedSources.erase(delIt); - for (sourceIt = _unassignedSources.begin(); sourceIt != _unassignedSources.end(); ++sourceIt) - { - state->addSource(sourceIt->first, sourceIt->second, _threshold, 0); - } + // remove if in assigned sources + delIt = _assignedSources.find(*it); + source = delIt->second; - // TODO: refinement + _assignedSources.erase(delIt); + } - // update source status - for (auto const& assignedSources: _assignedSources) - { - _assignedSources.insert(std::pair< int, VABinauralSoundSource* >(assignedSources.first, assignedSources.second)); - } + // add unassigned sources + std::map< int, VABinauralSoundSource* >::iterator sourceIt; - _unassignedSources.clear(); + for (sourceIt = _unassignedSources.begin(); sourceIt != _unassignedSources.end(); ++sourceIt) + { + state->addSource(sourceIt->first, sourceIt->second, _threshold, 0); + } - _nextState.reset(state); + // TODO: refinement - // TODO: update fixed clustertrajectories + // update source status + for (auto const& assignedSources : _assignedSources) + { + _assignedSources.insert(std::pair< int, VABinauralSoundSource* >(assignedSources.first, assignedSources.second)); + } + + _unassignedSources.clear(); + + _nextState.reset(state); + + // TODO: update fixed clustertrajectories + + } } void diff --git a/src/Rendering/Binaural/RealTime/Utils/BinauralListener/VABinauralListener.h b/src/Rendering/Binaural/RealTime/Utils/BinauralListener/VABinauralListener.h index e34f463..33fc04e 100644 --- a/src/Rendering/Binaural/RealTime/Utils/BinauralListener/VABinauralListener.h +++ b/src/Rendering/Binaural/RealTime/Utils/BinauralListener/VABinauralListener.h @@ -28,12 +28,13 @@ public: int motionModelNumHistoryKeys; }; + bool hasValidTrajectory; CVAListenerDesc* data; CVASharedMotionModel* motionModel; VAVec3 predPos; - VAVec3 prefView; + VAVec3 predView; VAVec3 predUp; ITASampleFrame* output; diff --git a/src/Rendering/Binaural/RealTime/VABinauralRealTimeRenderer.cpp b/src/Rendering/Binaural/RealTime/VABinauralRealTimeRenderer.cpp index 453fb6d..fc1574f 100644 --- a/src/Rendering/Binaural/RealTime/VABinauralRealTimeRenderer.cpp +++ b/src/Rendering/Binaural/RealTime/VABinauralRealTimeRenderer.cpp @@ -146,7 +146,7 @@ VABinauralRealTimeRenderer::ProcessStream(const ITAStreamInfo* streamInfo) updateTrajectories(time); // -- create output for every listener - std::map< int, VABinauralListener* >::const_iterator it; +/* std::map< int, VABinauralListener* >::const_iterator it; for (it = _listeners.begin(); it != _listeners.end(); ++it) { VABinauralClustering* clustering = _clusterEngine.getClustering(it->first); @@ -157,6 +157,17 @@ VABinauralRealTimeRenderer::ProcessStream(const ITAStreamInfo* streamInfo) fm_copy(outputChL, (*output)[0].data(), m_uiBlocklength); fm_copy(outputChR, (*output)[1].data(), m_uiBlocklength); } + } */ + + // TEST + for (auto const& clusteringIt : _clusterEngine._clusterings) + { + VABinauralClustering* clustering = clusteringIt.second; + + output = clustering->getOutput(); + + fm_copy(outputChL, (*output)[0].data(), m_uiBlocklength); + fm_copy(outputChR, (*output)[1].data(), m_uiBlocklength); } IncrementWritePointer(); @@ -184,6 +195,12 @@ VABinauralRealTimeRenderer::UpdateScene(CVASceneState* newSceneState) // update sources updateSources(&diff); + + // Alte Szene freigeben (dereferenzieren) + if (_curSceneState) _curSceneState->RemoveReference(); + + _curSceneState = _newSceneState; + _newSceneState = nullptr; } /* @@ -273,6 +290,7 @@ VABinauralRealTimeRenderer::updateListeners( CVASceneStateDiff* diff ) } } + _clusterEngine.update(); } void @@ -372,15 +390,27 @@ void VABinauralRealTimeRenderer::updateMotionStates() void VABinauralRealTimeRenderer::updateTrajectories( double time ) { - std::map::iterator it; - for ( it=_sources.begin(); it != _sources.end(); ++it) + + for (auto const& sourceIt: _sources) { bool isValid = true; - VABinauralSoundSource* source = it->second; + VABinauralSoundSource* source = sourceIt.second; source->motionModel->HandleMotionKeys(); isValid &= source->motionModel->EstimatePosition(time, source->predPos); isValid &= source->motionModel->EstimateOrientation(time, source->predView, source->predUp); source->hasValidTrajectory = isValid; } + + + for (auto const& listenerIt: _listeners) + { + bool isValid = true; + VABinauralListener* listener = listenerIt.second; + + listener->motionModel->HandleMotionKeys(); + isValid &= listener->motionModel->EstimatePosition(time, listener->predPos); + isValid &= listener->motionModel->EstimateOrientation(time, listener->predView, listener->predUp); + listener->hasValidTrajectory = isValid; + } } diff --git a/tests/CoreTest.cpp b/tests/CoreTest.cpp index eb3ce61..c8bca2b 100644 --- a/tests/CoreTest.cpp +++ b/tests/CoreTest.cpp @@ -73,8 +73,8 @@ int main( int, char** ) { try { - //va = VACore::CreateCoreInstance( "../conf/VACore.ini" ); - va = VACore::CreateCoreInstance( GetCoreConfig() ); + va = VACore::CreateCoreInstance( "../conf/VACore.ini" ); + //va = VACore::CreateCoreInstance( GetCoreConfig() ); // Attach (register) event handler //va->AttachEventHandler( &dumper ); -- GitLab