Commit b9c8a01c authored by Lucas Moesch's avatar Lucas Moesch

Fixed initial source trajectories.

parent 789f3d32
......@@ -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]
......
......@@ -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;
......
......@@ -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();
......
......@@ -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
......
......@@ -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);
......
......@@ -25,7 +25,9 @@ VABinauralSoundSource::PreRequest()
sourceMotionConf.iNumHistoryKeys = conf.motionModelNumHistoryKeys;
motionModel = new CVASharedMotionModel(new CVABasicMotionModel(sourceMotionConf), true);
state = nullptr;
data = nullptr;
hasValidTrajectory = false;
}
void
......
......@@ -31,6 +31,7 @@ public:
bool hasValidTrajectory;
const config_t conf;
CVASoundSourceState* state;
CVASoundSourceDesc* data;
CVASharedMotionModel* motionModel;
CITAVariableDelayLine* vdlChL;
......
#include "VAConfig.h"
int VAConfig::blockLength = 128;
int VAConfig::hrirLength = 256;
int VAConfig::hrirLength = 128;
double VAConfig::amplitudeCalibration = 1.0;
VAConfig::VAConfig() {}
VAConfig::~VAConfig() {}
......
......@@ -6,6 +6,7 @@ class VAConfig
public:
static int blockLength;
static int hrirLength;
static double amplitudeCalibration;
private:
VAConfig();
~VAConfig();
......
......@@ -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()
......
......@@ -49,7 +49,7 @@ private:
std::map< int, VABinauralSoundSource* > _sources;
std::map< int, VABinauralListener* > _listeners;
VABinauralClusterEngine _clusterEngine;
VABinauralClusterEngine* _clusterEngine;
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