Commit cfdeb920 authored by Lucas Moesch's avatar Lucas Moesch

wip

parent 21bc8d13
......@@ -12,7 +12,7 @@ VABinauralCluster::VABinauralCluster()
VABinauralCluster::VABinauralCluster(const VABinauralCluster& cluster) :
maxError(cluster.maxError),
_numSources(cluster._numSources),
numSources(cluster.numSources),
_clusterSourcePos(cluster._clusterSourcePos)
{
......@@ -54,7 +54,7 @@ VABinauralCluster::init(int sourceID, VABinauralSoundSource* source, VABinauralL
// --
source->AddReference();
++_numSources;
++numSources;
}
ITASampleFrame*
......@@ -109,7 +109,7 @@ VABinauralCluster::addSource(int sourceID, VABinauralSoundSource* source)
{
double err = getDistError(source);
_clusterSourcePos = (source->predPos + _clusterSourcePos * _numSources) / (_numSources + 1);
_clusterSourcePos = (source->predPos + _clusterSourcePos * numSources) / (numSources + 1);
_clusterSourceToListenerPos = _clusterSourcePos - _listenerPos;
maxError = std::max(err, maxError);
......@@ -119,13 +119,13 @@ VABinauralCluster::addSource(int sourceID, VABinauralSoundSource* source)
// --
source->AddReference();
++_numSources;
++numSources;
}
void
VABinauralCluster::addSource(int sourceID, VABinauralSoundSource* source, double error)
{
_clusterSourcePos = (source->predPos + _clusterSourcePos * _numSources) / (_numSources + 1);
_clusterSourcePos = (source->predPos + _clusterSourcePos * numSources) / (numSources + 1);
_clusterSourceToListenerPos = _clusterSourcePos - _listenerPos;
maxError = std::max(error, maxError);
......@@ -134,6 +134,23 @@ VABinauralCluster::addSource(int sourceID, VABinauralSoundSource* source, double
// --
source->AddReference();
++_numSources;
++numSources;
}
void
VABinauralCluster::removeSource(int sourceID)
{
std::map<int, VABinauralSoundSource*>::const_iterator it = _sources.find(sourceID);
VABinauralSoundSource* source = it->second;
_sources.erase(it);
source->RemoveReference();
_clusterSourcePos = (_clusterSourcePos * numSources - source->predPos) / (numSources - 1);
//TODO: MaxError
--numSources;
}
......@@ -12,6 +12,7 @@
class VABinauralCluster : public CVAPoolObject
{
public:
int numSources;
double maxError;
VABinauralCluster();
......@@ -36,14 +37,12 @@ public:
addSource(int sourceID, VABinauralSoundSource* source, double error);
void
removeSource();
removeSource(int sourceID);
void
reset();
private:
int _numSources;
ITASampleBuffer _tmpChL;
ITASampleBuffer _tmpChR;
......
......@@ -80,13 +80,15 @@ VABinauralClustering::update()
std::map< int, VABinauralSoundSource* >::iterator delIt = _unassignedSources.find(*it);
VABinauralSoundSource* source = delIt->second;
state->removeSource(*it);
_unassignedSources.erase(delIt);
// remove if in assigned sources
std::map< int, VABinauralSoundSource* >::iterator = _assignedSources.find(sourceID);
source = it->second;
delIt = _assignedSources.find(*it);
source = delIt->second;
_assignedSources.erase(it);
_assignedSources.erase(delIt);
}
// add unassigned sources
......
......@@ -75,6 +75,24 @@ VABinauralClusteringState::addSource(int sourceID, VABinauralSoundSource* source
sourceClusterReference.insert(std::pair< int, int >(sourceID, nearestClusterID));
}
void
VABinauralClusteringState::removeSource(int sourceID)
{
std::map<int, int>::const_iterator itSource = sourceClusterReference.find(sourceID);
std::map<int, VABinauralCluster*>::const_iterator itCluster = clusters.find(itSource->second);
VABinauralCluster* cluster = itCluster->second;
cluster->removeSource(sourceID);
if (cluster->numSources <= 0)
{
clusters.erase(itCluster);
freeClusterIDs.push(itSource->second);
cluster->RemoveReference();
}
}
std::pair< int, VABinauralCluster*>
VABinauralClusteringState::createCluster(int sourceID, VABinauralSoundSource* source)
{
......
......@@ -32,6 +32,9 @@ public:
void
addSource(int sourceID, VABinauralSoundSource* source, double threshold, int numBlockedClusters);
void
removeSource(int sourceID);
std::pair< int, VABinauralCluster*>
createCluster(int sourceID, VABinauralSoundSource* source);
......
......@@ -28,6 +28,7 @@ public:
int blockLength;
};
bool hasValidTrajectory;
const config_t conf;
CVASoundSourceDesc* data;
......@@ -36,7 +37,7 @@ public:
CITAVariableDelayLine* vdlChR;
VAVec3 predPos;
VAVec3 prefView;
VAVec3 predView;
VAVec3 predUp;
VABinauralSoundSource(const config_t& conf);
......
......@@ -111,7 +111,9 @@ VABinauralRealTimeRenderer::processStream(const ITAStreamInfo* streamInfo)
fm_zero(outputChR, GetBlocklength());
const CVAAudiostreamState* streamState = dynamic_cast< const CVAAudiostreamState* >(streamInfo);
double dListenerTime = streamState->dSysTime;
double time = streamState->dSysTime;
updateTrajectories(time);
// -- create output for every listener
std::map< int, VABinauralListener* >::const_iterator it;
......@@ -312,4 +314,41 @@ VABinauralRealTimeRenderer::deleteListener(int listenerID)
// remove listener reference from clustering
_clusterEngine.removeListener(listenerID);
}
\ No newline at end of file
}
void VABinauralRealTimeRenderer::updateMotionStates()
{
// Neue Quellendaten bernehmen
for (std::map< int, VABinauralSoundSource* >::iterator it = _sources.begin(); it != _sources.end(); ++it)
{
int sourceID = it->first;
VABinauralSoundSource* source = it->second;
CVASoundSourceState* sourceCur = (_curSceneState ? _curSceneState->GetSoundSourceState(sourceID) : nullptr);
CVASoundSourceState* sourceNew = (_newSceneState ? _newSceneState->GetSoundSourceState(sourceID) : nullptr);
const CVAMotionState* motionCur = (sourceCur ? sourceCur->GetMotionState() : nullptr);
const CVAMotionState* motionNew = (sourceNew ? sourceNew->GetMotionState() : nullptr);
if (motionNew && (motionNew != motionCur))
{
//VA_TRACE("BinauralFreeFieldAudioRenderer", "Source " << iSourceID << " new motion state");
source->motionModel->InputMotionKey(motionNew);
}
}
}
void
VABinauralRealTimeRenderer::updateTrajectories( double time )
{
std::map<int, VABinauralSoundSource*>::iterator it;
for ( it=_sources.begin(); it != _sources.end(); ++it)
{
bool isValid = true;
VABinauralSoundSource* source = it->second;
source->motionModel->HandleMotionKeys();
isValid &= source->motionModel->EstimatePosition(time, source->predPos);
isValid &= source->motionModel->EstimateOrientation(time, source->predView, source->predUp);
source->hasValidTrajectory = isValid;
}
}
......@@ -78,6 +78,12 @@ private:
void
deleteSource( const int sourceID );
void
updateMotionStates();
void
updateTrajectories(double time);
};
......
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