From b9c8a01c35d84323e69ec68081398bd392ab451d Mon Sep 17 00:00:00 2001 From: Lucas Moesch Date: Fri, 12 Oct 2018 16:34:15 +0200 Subject: [PATCH] Fixed initial source trajectories. --- conf/VACore.recording.ini | 26 +++++++---- .../VABinauralCluster.cpp | 6 ++- .../VABinauralClusterEngine.cpp | 6 --- .../VABinauralClustering.cpp | 20 ++++---- .../VABinauralClusteringState.cpp | 2 +- .../VABinauralSoundSource.cpp | 2 + .../VABinauralSoundSource.h | 1 + .../RealTime/Utils/Config/VAConfig.cpp | 3 +- .../Binaural/RealTime/Utils/Config/VAConfig.h | 1 + .../RealTime/VABinauralRealTimeRenderer.cpp | 46 ++++++++++++++----- .../RealTime/VABinauralRealTimeRenderer.h | 2 +- 11 files changed, 74 insertions(+), 41 deletions(-) diff --git a/conf/VACore.recording.ini b/conf/VACore.recording.ini index f01b452..36eff55 100644 --- a/conf/VACore.recording.ini +++ b/conf/VACore.recording.ini @@ -34,21 +34,31 @@ Samplerate = 44100 Buffersize = 64 OutputChannels = 2 +[Renderer:MyBinauralRealTime] +Class = BinauralRealTime +Enabled = true +Reproductions = MyTalkthroughHeadphones +RecordOutputEnabled = true +RecordOutputFilePath = BinauralRealTime_rendering.wav + [Renderer:MyBinauralFreeField] Class = BinauralFreeField Enabled = true -Reproductions = MyHeadphones +Reproductions = MyTalkthroughHeadphones RecordOutputEnabled = true -RecordOutputFilePath = $(ProjectName)_rendering.wav +RecordOutputFilePath = BinauralFreeField_rendering.wav -[Reproduction:MyHeadphones] -Class = Headphones +[Reproduction:MyTalkthroughHeadphones] +Class = Talkthrough Enabled = true -HpIRInvFile = HD650_all_inv.wav -HpIRInvCalibrationGainDecibel = 0.1 +Name = Generic talkthrough to output group Outputs = MyDesktopHP -RecordOutputEnabled = true -RecordOutputFilePath = $(ProjectName)_reproduction.wav +InputDetectorEnabled = false +OutputDetectorEnabled = false +RecordInputEnabled = false +RecordInputFilePath = $(ProjectName)_Reproduction_MyTalkthroughHeadphones_Input.wav +RecordOutputEnabled = false +RecordOutputFilePath = $(ProjectName)_Reproduction_MyTalkthroughHeadphones_Output.wav [Setup] [Output:MyDesktopHP] diff --git a/src/Rendering/Binaural/RealTime/Utils/BinauralClusterEngine/VABinauralCluster.cpp b/src/Rendering/Binaural/RealTime/Utils/BinauralClusterEngine/VABinauralCluster.cpp index 5025c99..eb4b129 100644 --- a/src/Rendering/Binaural/RealTime/Utils/BinauralClusterEngine/VABinauralCluster.cpp +++ b/src/Rendering/Binaural/RealTime/Utils/BinauralClusterEngine/VABinauralCluster.cpp @@ -124,15 +124,19 @@ VABinauralCluster::getOutput() sourceMetrics.calc(_listener->predPos, _listener->predView, _listener->predUp, source->predPos); double toaDistance = sourceMetrics.dist / 343; // TODO: Medium Propagation.... - double toaSourceChL = _listener->toaEstimator->getTOALeft(sourceMetrics.phi, sourceMetrics.theta); double toSourceaChR = _listener->toaEstimator->getTOARight(sourceMetrics.phi, sourceMetrics.theta); + float gain = float(1/sourceMetrics.dist * source->state->GetVolume(VAConfig::amplitudeCalibration)); + source->vdlChL->SetDelayTime(toaDistance + toaSourceChL - toaHRTFChL); source->vdlChR->SetDelayTime(toaDistance + toSourceaChR - toaHRTFChR); source->vdlChL->Process(input, &(_tmpChL)); source->vdlChR->Process(input, &(_tmpChR)); + + _tmpChL.mul_scalar(gain); + _tmpChR.mul_scalar(gain); (*_output)[0] += _tmpChL; (*_output)[1] += _tmpChR; diff --git a/src/Rendering/Binaural/RealTime/Utils/BinauralClusterEngine/VABinauralClusterEngine.cpp b/src/Rendering/Binaural/RealTime/Utils/BinauralClusterEngine/VABinauralClusterEngine.cpp index 5073ce2..bf58b2a 100644 --- a/src/Rendering/Binaural/RealTime/Utils/BinauralClusterEngine/VABinauralClusterEngine.cpp +++ b/src/Rendering/Binaural/RealTime/Utils/BinauralClusterEngine/VABinauralClusterEngine.cpp @@ -21,12 +21,6 @@ VABinauralClusterEngine::~VABinauralClusterEngine() void VABinauralClusterEngine::update() { -/* std::map< int, VABinauralClustering* >::iterator it; - for (it = _clusterings.begin(); it != _clusterings.end(); ++it) - { - it->second->update(); - }*/ - for (auto const& clustering : _clusterings) { clustering.second->update(); diff --git a/src/Rendering/Binaural/RealTime/Utils/BinauralClusterEngine/VABinauralClustering.cpp b/src/Rendering/Binaural/RealTime/Utils/BinauralClusterEngine/VABinauralClustering.cpp index ba07fe0..dac4191 100644 --- a/src/Rendering/Binaural/RealTime/Utils/BinauralClusterEngine/VABinauralClustering.cpp +++ b/src/Rendering/Binaural/RealTime/Utils/BinauralClusterEngine/VABinauralClustering.cpp @@ -58,16 +58,10 @@ VABinauralClustering::getOutput() }; std::map< int, VABinauralCluster*>::const_iterator clusterIt; - clusterIt = _curState->clusters.begin(); - ITASampleFrame* clusterOutput = clusterIt->second->getOutput(); - - (*_output)[0] += (*clusterOutput)[0]; - (*_output)[1] += (*clusterOutput)[1]; - - for (++clusterIt; clusterIt != _curState->clusters.end(); ++clusterIt) + for (clusterIt = _curState->clusters.begin(); clusterIt != _curState->clusters.end(); ++clusterIt) { - clusterOutput = clusterIt->second->getOutput(); + ITASampleFrame* clusterOutput = clusterIt->second->getOutput(); (*_output)[0] += (*clusterOutput)[0]; (*_output)[1] += (*clusterOutput)[1]; @@ -79,8 +73,8 @@ VABinauralClustering::getOutput() void VABinauralClustering::update() { - if (_nextState == nullptr) - { +// if (_nextState == nullptr) +// { VABinauralClusteringState* state = new VABinauralClusteringState(_numClusters, _listener, clusterPool); //new VABinauralClusteringState(*_curState); @@ -109,7 +103,9 @@ VABinauralClustering::update() for (sourceIt = _unassignedSources.begin(); sourceIt != _unassignedSources.end(); ++sourceIt) { - state->addSource(sourceIt->first, sourceIt->second, _threshold, 0); + if (sourceIt->second->hasValidTrajectory){ + state->addSource(sourceIt->first, sourceIt->second, _threshold, 0); + }; } // TODO: refinement @@ -123,7 +119,7 @@ VABinauralClustering::update() //_unassignedSources.clear(); _nextState.reset(state); - } +// } } void diff --git a/src/Rendering/Binaural/RealTime/Utils/BinauralClusterEngine/VABinauralClusteringState.cpp b/src/Rendering/Binaural/RealTime/Utils/BinauralClusterEngine/VABinauralClusteringState.cpp index d70a764..c55e688 100644 --- a/src/Rendering/Binaural/RealTime/Utils/BinauralClusterEngine/VABinauralClusteringState.cpp +++ b/src/Rendering/Binaural/RealTime/Utils/BinauralClusterEngine/VABinauralClusteringState.cpp @@ -101,7 +101,7 @@ VABinauralClusteringState::removeSource(int sourceID) std::pair< int, VABinauralCluster*> VABinauralClusteringState::createCluster(int sourceID, VABinauralSoundSource* source) { - int clusterID = freeClusterIDs.back(); + int clusterID = freeClusterIDs.front(); VABinauralCluster* cluster = dynamic_cast< VABinauralCluster* >(_clusterPool->RequestObject()); // Reference = 1 cluster->init(sourceID, source, listener); diff --git a/src/Rendering/Binaural/RealTime/Utils/BinauralSoundSource/VABinauralSoundSource.cpp b/src/Rendering/Binaural/RealTime/Utils/BinauralSoundSource/VABinauralSoundSource.cpp index 7bff158..ca50112 100644 --- a/src/Rendering/Binaural/RealTime/Utils/BinauralSoundSource/VABinauralSoundSource.cpp +++ b/src/Rendering/Binaural/RealTime/Utils/BinauralSoundSource/VABinauralSoundSource.cpp @@ -25,7 +25,9 @@ VABinauralSoundSource::PreRequest() sourceMotionConf.iNumHistoryKeys = conf.motionModelNumHistoryKeys; motionModel = new CVASharedMotionModel(new CVABasicMotionModel(sourceMotionConf), true); + state = nullptr; data = nullptr; + hasValidTrajectory = false; } void diff --git a/src/Rendering/Binaural/RealTime/Utils/BinauralSoundSource/VABinauralSoundSource.h b/src/Rendering/Binaural/RealTime/Utils/BinauralSoundSource/VABinauralSoundSource.h index dbdcf0b..958c028 100644 --- a/src/Rendering/Binaural/RealTime/Utils/BinauralSoundSource/VABinauralSoundSource.h +++ b/src/Rendering/Binaural/RealTime/Utils/BinauralSoundSource/VABinauralSoundSource.h @@ -31,6 +31,7 @@ public: bool hasValidTrajectory; const config_t conf; + CVASoundSourceState* state; CVASoundSourceDesc* data; CVASharedMotionModel* motionModel; CITAVariableDelayLine* vdlChL; diff --git a/src/Rendering/Binaural/RealTime/Utils/Config/VAConfig.cpp b/src/Rendering/Binaural/RealTime/Utils/Config/VAConfig.cpp index 9c37c66..d093ca1 100644 --- a/src/Rendering/Binaural/RealTime/Utils/Config/VAConfig.cpp +++ b/src/Rendering/Binaural/RealTime/Utils/Config/VAConfig.cpp @@ -1,7 +1,8 @@ #include "VAConfig.h" int VAConfig::blockLength = 128; -int VAConfig::hrirLength = 256; +int VAConfig::hrirLength = 128; +double VAConfig::amplitudeCalibration = 1.0; VAConfig::VAConfig() {} VAConfig::~VAConfig() {} diff --git a/src/Rendering/Binaural/RealTime/Utils/Config/VAConfig.h b/src/Rendering/Binaural/RealTime/Utils/Config/VAConfig.h index e13cb3d..2ce65ee 100644 --- a/src/Rendering/Binaural/RealTime/Utils/Config/VAConfig.h +++ b/src/Rendering/Binaural/RealTime/Utils/Config/VAConfig.h @@ -6,6 +6,7 @@ class VAConfig public: static int blockLength; static int hrirLength; + static double amplitudeCalibration; private: VAConfig(); ~VAConfig(); diff --git a/src/Rendering/Binaural/RealTime/VABinauralRealTimeRenderer.cpp b/src/Rendering/Binaural/RealTime/VABinauralRealTimeRenderer.cpp index 6bfd868..2236dc7 100644 --- a/src/Rendering/Binaural/RealTime/VABinauralRealTimeRenderer.cpp +++ b/src/Rendering/Binaural/RealTime/VABinauralRealTimeRenderer.cpp @@ -27,8 +27,7 @@ VABinauralRealTimeRenderer::VABinauralRealTimeRenderer( const CVAAudioRendererIn _newSceneState(NULL), _curSceneState(NULL), _indicateReset(false), - _resetAck(false), - _clusterEngine() + _resetAck(false) { init(*_params.pConfig); @@ -104,6 +103,10 @@ VABinauralRealTimeRenderer::init( const CVAStruct& oArgs ) VAConfig::blockLength = GetBlocklength(); VAConfig::hrirLength = _hrirFilterLength; + VAConfig::amplitudeCalibration = _core->GetCoreConfig()->dDefaultAmplitudeCalibration; + + // initialize after config + _clusterEngine = new VABinauralClusterEngine(); } void @@ -150,7 +153,7 @@ VABinauralRealTimeRenderer::ProcessStream(const ITAStreamInfo* streamInfo) updateTrajectories(time); // -- create output for every listener - for (auto const& clusteringIt : _clusterEngine._clusterings) + for (auto const& clusteringIt : _clusterEngine->_clusterings) { VABinauralClustering* clustering = clusteringIt.second; @@ -186,6 +189,8 @@ VABinauralRealTimeRenderer::UpdateScene(CVASceneState* newSceneState) // update sources updateSources(&diff); + _clusterEngine->update(); + // Alte Szene freigeben (dereferenzieren) if (_curSceneState) _curSceneState->RemoveReference(); @@ -231,16 +236,35 @@ VABinauralRealTimeRenderer::updateSources( CVASceneStateDiff* diff ) CVASoundSourceState* sourceCur = (_curSceneState ? _curSceneState->GetSoundSourceState(sourceID) : nullptr); CVASoundSourceState* sourceNew = (_newSceneState ? _newSceneState->GetSoundSourceState(sourceID) : nullptr); + if (sourceNew && (sourceNew != sourceCur)) + { + source->state = sourceNew; + } + const CVAMotionState* motionCur = (sourceCur ? sourceCur->GetMotionState() : nullptr); const CVAMotionState* motionNew = (sourceNew ? sourceNew->GetMotionState() : nullptr); if (motionNew && (motionNew != motionCur)) { source->motionModel->InputMotionKey(motionNew); + // Dirty Hack + if (!source->hasValidTrajectory) + { + VAVec3 pos = motionNew->GetPosition(); + + if (pos != VAVec3(0, 0, 0)) + { + VAVec3 view = motionNew->GetView(); + VAVec3 up = motionNew->GetUp(); + + source->predPos = pos; + source->predView = view; + source->predUp = up; + source->hasValidTrajectory = true; + } + } } } - - _clusterEngine.update(); } void @@ -284,8 +308,6 @@ VABinauralRealTimeRenderer::updateListeners( CVASceneStateDiff* diff ) listener->directivity = (IVADirectivity*) listenerNew->GetDirectivity(); } } - - _clusterEngine.update(); } void @@ -293,6 +315,8 @@ VABinauralRealTimeRenderer::createSource( const int sourceID, const CVASoundSour { VABinauralSoundSource* source = dynamic_cast< VABinauralSoundSource* >(_sourcePool->RequestObject()); // Reference = 1 + // set state + source->state = (CVASoundSourceState*) sourceState; // set internal data source->data = _core->GetSceneManager()->GetSoundSourceDesc(sourceID); source->data->AddReference(); @@ -306,7 +330,7 @@ VABinauralRealTimeRenderer::createSource( const int sourceID, const CVASoundSour _sources.insert(std::pair< int, VABinauralSoundSource* >(sourceID, source)); // add source to clustering - _clusterEngine.addSource(sourceID, source); + _clusterEngine->addSource(sourceID, source); } void @@ -318,7 +342,7 @@ VABinauralRealTimeRenderer::deleteSource(int sourceID) _sources.erase(it); // remove listener reference from clustering - _clusterEngine.removeSource(sourceID); + _clusterEngine->removeSource(sourceID); source->RemoveReference(); } @@ -344,7 +368,7 @@ VABinauralRealTimeRenderer::createListener(int listenerID, const CVAReceiverStat // add listener to clustering VABinauralClusterEngine::clusterConfig_t config = { /*numClusters=*/ 9}; - _clusterEngine.addListener(listenerID, listener, config); + _clusterEngine->addListener(listenerID, listener, config); } void @@ -360,7 +384,7 @@ VABinauralRealTimeRenderer::deleteListener(int listenerID) listener->RemoveReference(); // remove listener reference from clustering - _clusterEngine.removeListener(listenerID); + _clusterEngine->removeListener(listenerID); } void VABinauralRealTimeRenderer::updateMotionStates() diff --git a/src/Rendering/Binaural/RealTime/VABinauralRealTimeRenderer.h b/src/Rendering/Binaural/RealTime/VABinauralRealTimeRenderer.h index 50b9c70..7c0a2c8 100644 --- a/src/Rendering/Binaural/RealTime/VABinauralRealTimeRenderer.h +++ b/src/Rendering/Binaural/RealTime/VABinauralRealTimeRenderer.h @@ -49,7 +49,7 @@ private: std::map< int, VABinauralSoundSource* > _sources; std::map< int, VABinauralListener* > _listeners; - VABinauralClusterEngine _clusterEngine; + VABinauralClusterEngine* _clusterEngine; CVACoreImpl* _core; -- GitLab