Commit b9c8a01c authored by Lucas Moesch's avatar Lucas Moesch

Fixed initial source trajectories.

parent 789f3d32
...@@ -34,21 +34,31 @@ Samplerate = 44100 ...@@ -34,21 +34,31 @@ Samplerate = 44100
Buffersize = 64 Buffersize = 64
OutputChannels = 2 OutputChannels = 2
[Renderer:MyBinauralRealTime]
Class = BinauralRealTime
Enabled = true
Reproductions = MyTalkthroughHeadphones
RecordOutputEnabled = true
RecordOutputFilePath = BinauralRealTime_rendering.wav
[Renderer:MyBinauralFreeField] [Renderer:MyBinauralFreeField]
Class = BinauralFreeField Class = BinauralFreeField
Enabled = true Enabled = true
Reproductions = MyHeadphones Reproductions = MyTalkthroughHeadphones
RecordOutputEnabled = true RecordOutputEnabled = true
RecordOutputFilePath = $(ProjectName)_rendering.wav RecordOutputFilePath = BinauralFreeField_rendering.wav
[Reproduction:MyHeadphones] [Reproduction:MyTalkthroughHeadphones]
Class = Headphones Class = Talkthrough
Enabled = true Enabled = true
HpIRInvFile = HD650_all_inv.wav Name = Generic talkthrough to output group
HpIRInvCalibrationGainDecibel = 0.1
Outputs = MyDesktopHP Outputs = MyDesktopHP
RecordOutputEnabled = true InputDetectorEnabled = false
RecordOutputFilePath = $(ProjectName)_reproduction.wav OutputDetectorEnabled = false
RecordInputEnabled = false
RecordInputFilePath = $(ProjectName)_Reproduction_MyTalkthroughHeadphones_Input.wav
RecordOutputEnabled = false
RecordOutputFilePath = $(ProjectName)_Reproduction_MyTalkthroughHeadphones_Output.wav
[Setup] [Setup]
[Output:MyDesktopHP] [Output:MyDesktopHP]
......
...@@ -124,15 +124,19 @@ VABinauralCluster::getOutput() ...@@ -124,15 +124,19 @@ VABinauralCluster::getOutput()
sourceMetrics.calc(_listener->predPos, _listener->predView, _listener->predUp, source->predPos); sourceMetrics.calc(_listener->predPos, _listener->predView, _listener->predUp, source->predPos);
double toaDistance = sourceMetrics.dist / 343; // TODO: Medium Propagation.... double toaDistance = sourceMetrics.dist / 343; // TODO: Medium Propagation....
double toaSourceChL = _listener->toaEstimator->getTOALeft(sourceMetrics.phi, sourceMetrics.theta); double toaSourceChL = _listener->toaEstimator->getTOALeft(sourceMetrics.phi, sourceMetrics.theta);
double toSourceaChR = _listener->toaEstimator->getTOARight(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->vdlChL->SetDelayTime(toaDistance + toaSourceChL - toaHRTFChL);
source->vdlChR->SetDelayTime(toaDistance + toSourceaChR - toaHRTFChR); source->vdlChR->SetDelayTime(toaDistance + toSourceaChR - toaHRTFChR);
source->vdlChL->Process(input, &(_tmpChL)); source->vdlChL->Process(input, &(_tmpChL));
source->vdlChR->Process(input, &(_tmpChR)); source->vdlChR->Process(input, &(_tmpChR));
_tmpChL.mul_scalar(gain);
_tmpChR.mul_scalar(gain);
(*_output)[0] += _tmpChL; (*_output)[0] += _tmpChL;
(*_output)[1] += _tmpChR; (*_output)[1] += _tmpChR;
......
...@@ -21,12 +21,6 @@ VABinauralClusterEngine::~VABinauralClusterEngine() ...@@ -21,12 +21,6 @@ VABinauralClusterEngine::~VABinauralClusterEngine()
void void
VABinauralClusterEngine::update() VABinauralClusterEngine::update()
{ {
/* std::map< int, VABinauralClustering* >::iterator it;
for (it = _clusterings.begin(); it != _clusterings.end(); ++it)
{
it->second->update();
}*/
for (auto const& clustering : _clusterings) for (auto const& clustering : _clusterings)
{ {
clustering.second->update(); clustering.second->update();
......
...@@ -58,16 +58,10 @@ VABinauralClustering::getOutput() ...@@ -58,16 +58,10 @@ VABinauralClustering::getOutput()
}; };
std::map< int, VABinauralCluster*>::const_iterator clusterIt; std::map< int, VABinauralCluster*>::const_iterator clusterIt;
clusterIt = _curState->clusters.begin();
ITASampleFrame* clusterOutput = clusterIt->second->getOutput(); for (clusterIt = _curState->clusters.begin(); clusterIt != _curState->clusters.end(); ++clusterIt)
(*_output)[0] += (*clusterOutput)[0];
(*_output)[1] += (*clusterOutput)[1];
for (++clusterIt; clusterIt != _curState->clusters.end(); ++clusterIt)
{ {
clusterOutput = clusterIt->second->getOutput(); ITASampleFrame* clusterOutput = clusterIt->second->getOutput();
(*_output)[0] += (*clusterOutput)[0]; (*_output)[0] += (*clusterOutput)[0];
(*_output)[1] += (*clusterOutput)[1]; (*_output)[1] += (*clusterOutput)[1];
...@@ -79,8 +73,8 @@ VABinauralClustering::getOutput() ...@@ -79,8 +73,8 @@ VABinauralClustering::getOutput()
void void
VABinauralClustering::update() VABinauralClustering::update()
{ {
if (_nextState == nullptr) // if (_nextState == nullptr)
{ // {
VABinauralClusteringState* state = new VABinauralClusteringState(_numClusters, _listener, clusterPool); //new VABinauralClusteringState(*_curState); VABinauralClusteringState* state = new VABinauralClusteringState(_numClusters, _listener, clusterPool); //new VABinauralClusteringState(*_curState);
...@@ -109,7 +103,9 @@ VABinauralClustering::update() ...@@ -109,7 +103,9 @@ VABinauralClustering::update()
for (sourceIt = _unassignedSources.begin(); sourceIt != _unassignedSources.end(); ++sourceIt) 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 // TODO: refinement
...@@ -123,7 +119,7 @@ VABinauralClustering::update() ...@@ -123,7 +119,7 @@ VABinauralClustering::update()
//_unassignedSources.clear(); //_unassignedSources.clear();
_nextState.reset(state); _nextState.reset(state);
} // }
} }
void void
......
...@@ -101,7 +101,7 @@ VABinauralClusteringState::removeSource(int sourceID) ...@@ -101,7 +101,7 @@ VABinauralClusteringState::removeSource(int sourceID)
std::pair< int, VABinauralCluster*> std::pair< int, VABinauralCluster*>
VABinauralClusteringState::createCluster(int sourceID, VABinauralSoundSource* source) VABinauralClusteringState::createCluster(int sourceID, VABinauralSoundSource* source)
{ {
int clusterID = freeClusterIDs.back(); int clusterID = freeClusterIDs.front();
VABinauralCluster* cluster = dynamic_cast< VABinauralCluster* >(_clusterPool->RequestObject()); // Reference = 1 VABinauralCluster* cluster = dynamic_cast< VABinauralCluster* >(_clusterPool->RequestObject()); // Reference = 1
cluster->init(sourceID, source, listener); cluster->init(sourceID, source, listener);
......
...@@ -25,7 +25,9 @@ VABinauralSoundSource::PreRequest() ...@@ -25,7 +25,9 @@ VABinauralSoundSource::PreRequest()
sourceMotionConf.iNumHistoryKeys = conf.motionModelNumHistoryKeys; sourceMotionConf.iNumHistoryKeys = conf.motionModelNumHistoryKeys;
motionModel = new CVASharedMotionModel(new CVABasicMotionModel(sourceMotionConf), true); motionModel = new CVASharedMotionModel(new CVABasicMotionModel(sourceMotionConf), true);
state = nullptr;
data = nullptr; data = nullptr;
hasValidTrajectory = false;
} }
void void
......
...@@ -31,6 +31,7 @@ public: ...@@ -31,6 +31,7 @@ public:
bool hasValidTrajectory; bool hasValidTrajectory;
const config_t conf; const config_t conf;
CVASoundSourceState* state;
CVASoundSourceDesc* data; CVASoundSourceDesc* data;
CVASharedMotionModel* motionModel; CVASharedMotionModel* motionModel;
CITAVariableDelayLine* vdlChL; CITAVariableDelayLine* vdlChL;
......
#include "VAConfig.h" #include "VAConfig.h"
int VAConfig::blockLength = 128; int VAConfig::blockLength = 128;
int VAConfig::hrirLength = 256; int VAConfig::hrirLength = 128;
double VAConfig::amplitudeCalibration = 1.0;
VAConfig::VAConfig() {} VAConfig::VAConfig() {}
VAConfig::~VAConfig() {} VAConfig::~VAConfig() {}
......
...@@ -6,6 +6,7 @@ class VAConfig ...@@ -6,6 +6,7 @@ class VAConfig
public: public:
static int blockLength; static int blockLength;
static int hrirLength; static int hrirLength;
static double amplitudeCalibration;
private: private:
VAConfig(); VAConfig();
~VAConfig(); ~VAConfig();
......
...@@ -27,8 +27,7 @@ VABinauralRealTimeRenderer::VABinauralRealTimeRenderer( const CVAAudioRendererIn ...@@ -27,8 +27,7 @@ VABinauralRealTimeRenderer::VABinauralRealTimeRenderer( const CVAAudioRendererIn
_newSceneState(NULL), _newSceneState(NULL),
_curSceneState(NULL), _curSceneState(NULL),
_indicateReset(false), _indicateReset(false),
_resetAck(false), _resetAck(false)
_clusterEngine()
{ {
init(*_params.pConfig); init(*_params.pConfig);
...@@ -104,6 +103,10 @@ VABinauralRealTimeRenderer::init( const CVAStruct& oArgs ) ...@@ -104,6 +103,10 @@ VABinauralRealTimeRenderer::init( const CVAStruct& oArgs )
VAConfig::blockLength = GetBlocklength(); VAConfig::blockLength = GetBlocklength();
VAConfig::hrirLength = _hrirFilterLength; VAConfig::hrirLength = _hrirFilterLength;
VAConfig::amplitudeCalibration = _core->GetCoreConfig()->dDefaultAmplitudeCalibration;
// initialize after config
_clusterEngine = new VABinauralClusterEngine();
} }
void void
...@@ -150,7 +153,7 @@ VABinauralRealTimeRenderer::ProcessStream(const ITAStreamInfo* streamInfo) ...@@ -150,7 +153,7 @@ VABinauralRealTimeRenderer::ProcessStream(const ITAStreamInfo* streamInfo)
updateTrajectories(time); updateTrajectories(time);
// -- create output for every listener // -- create output for every listener
for (auto const& clusteringIt : _clusterEngine._clusterings) for (auto const& clusteringIt : _clusterEngine->_clusterings)
{ {
VABinauralClustering* clustering = clusteringIt.second; VABinauralClustering* clustering = clusteringIt.second;
...@@ -186,6 +189,8 @@ VABinauralRealTimeRenderer::UpdateScene(CVASceneState* newSceneState) ...@@ -186,6 +189,8 @@ VABinauralRealTimeRenderer::UpdateScene(CVASceneState* newSceneState)
// update sources // update sources
updateSources(&diff); updateSources(&diff);
_clusterEngine->update();
// Alte Szene freigeben (dereferenzieren) // Alte Szene freigeben (dereferenzieren)
if (_curSceneState) _curSceneState->RemoveReference(); if (_curSceneState) _curSceneState->RemoveReference();
...@@ -231,16 +236,35 @@ VABinauralRealTimeRenderer::updateSources( CVASceneStateDiff* diff ) ...@@ -231,16 +236,35 @@ VABinauralRealTimeRenderer::updateSources( CVASceneStateDiff* diff )
CVASoundSourceState* sourceCur = (_curSceneState ? _curSceneState->GetSoundSourceState(sourceID) : nullptr); CVASoundSourceState* sourceCur = (_curSceneState ? _curSceneState->GetSoundSourceState(sourceID) : nullptr);
CVASoundSourceState* sourceNew = (_newSceneState ? _newSceneState->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* motionCur = (sourceCur ? sourceCur->GetMotionState() : nullptr);
const CVAMotionState* motionNew = (sourceNew ? sourceNew->GetMotionState() : nullptr); const CVAMotionState* motionNew = (sourceNew ? sourceNew->GetMotionState() : nullptr);
if (motionNew && (motionNew != motionCur)) if (motionNew && (motionNew != motionCur))
{ {
source->motionModel->InputMotionKey(motionNew); 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 void
...@@ -284,8 +308,6 @@ VABinauralRealTimeRenderer::updateListeners( CVASceneStateDiff* diff ) ...@@ -284,8 +308,6 @@ VABinauralRealTimeRenderer::updateListeners( CVASceneStateDiff* diff )
listener->directivity = (IVADirectivity*) listenerNew->GetDirectivity(); listener->directivity = (IVADirectivity*) listenerNew->GetDirectivity();
} }
} }
_clusterEngine.update();
} }
void void
...@@ -293,6 +315,8 @@ VABinauralRealTimeRenderer::createSource( const int sourceID, const CVASoundSour ...@@ -293,6 +315,8 @@ VABinauralRealTimeRenderer::createSource( const int sourceID, const CVASoundSour
{ {
VABinauralSoundSource* source = dynamic_cast< VABinauralSoundSource* >(_sourcePool->RequestObject()); // Reference = 1 VABinauralSoundSource* source = dynamic_cast< VABinauralSoundSource* >(_sourcePool->RequestObject()); // Reference = 1
// set state
source->state = (CVASoundSourceState*) sourceState;
// set internal data // set internal data
source->data = _core->GetSceneManager()->GetSoundSourceDesc(sourceID); source->data = _core->GetSceneManager()->GetSoundSourceDesc(sourceID);
source->data->AddReference(); source->data->AddReference();
...@@ -306,7 +330,7 @@ VABinauralRealTimeRenderer::createSource( const int sourceID, const CVASoundSour ...@@ -306,7 +330,7 @@ VABinauralRealTimeRenderer::createSource( const int sourceID, const CVASoundSour
_sources.insert(std::pair< int, VABinauralSoundSource* >(sourceID, source)); _sources.insert(std::pair< int, VABinauralSoundSource* >(sourceID, source));
// add source to clustering // add source to clustering
_clusterEngine.addSource(sourceID, source); _clusterEngine->addSource(sourceID, source);
} }
void void
...@@ -318,7 +342,7 @@ VABinauralRealTimeRenderer::deleteSource(int sourceID) ...@@ -318,7 +342,7 @@ VABinauralRealTimeRenderer::deleteSource(int sourceID)
_sources.erase(it); _sources.erase(it);
// remove listener reference from clustering // remove listener reference from clustering
_clusterEngine.removeSource(sourceID); _clusterEngine->removeSource(sourceID);
source->RemoveReference(); source->RemoveReference();
} }
...@@ -344,7 +368,7 @@ VABinauralRealTimeRenderer::createListener(int listenerID, const CVAReceiverStat ...@@ -344,7 +368,7 @@ VABinauralRealTimeRenderer::createListener(int listenerID, const CVAReceiverStat
// add listener to clustering // add listener to clustering
VABinauralClusterEngine::clusterConfig_t config = { /*numClusters=*/ 9}; VABinauralClusterEngine::clusterConfig_t config = { /*numClusters=*/ 9};
_clusterEngine.addListener(listenerID, listener, config); _clusterEngine->addListener(listenerID, listener, config);
} }
void void
...@@ -360,7 +384,7 @@ VABinauralRealTimeRenderer::deleteListener(int listenerID) ...@@ -360,7 +384,7 @@ VABinauralRealTimeRenderer::deleteListener(int listenerID)
listener->RemoveReference(); listener->RemoveReference();
// remove listener reference from clustering // remove listener reference from clustering
_clusterEngine.removeListener(listenerID); _clusterEngine->removeListener(listenerID);
} }
void VABinauralRealTimeRenderer::updateMotionStates() void VABinauralRealTimeRenderer::updateMotionStates()
......
...@@ -49,7 +49,7 @@ private: ...@@ -49,7 +49,7 @@ private:
std::map< int, VABinauralSoundSource* > _sources; std::map< int, VABinauralSoundSource* > _sources;
std::map< int, VABinauralListener* > _listeners; std::map< int, VABinauralListener* > _listeners;
VABinauralClusterEngine _clusterEngine; VABinauralClusterEngine* _clusterEngine;
CVACoreImpl* _core; CVACoreImpl* _core;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment