Commit 789f3d32 authored by Lucas Moesch's avatar Lucas Moesch

Added global VAConfig.

parent 6a52da6c
......@@ -12,50 +12,53 @@
#include <ITAConstants.h>
// Utils
#include "../Config/VAConfig.h"
#include "../RelationMetrics/VARelationMetrics.h"
#include "../BinauralTimeOfArrivalEstimator/VABinauralTOAEstimator.h"
VABinauralCluster::VABinauralCluster()
{
}
_output = new ITASampleFrame(2, VAConfig::blockLength, true);
_tempHRIR = new ITASampleFrame(2, VAConfig::hrirLength, true);
VABinauralCluster::VABinauralCluster(const VABinauralCluster& cluster) :
maxError(cluster.maxError),
numSources(cluster.numSources),
_clusterSourcePos(cluster._clusterSourcePos)
{
// initialize left channel convolver for each cluster
_FIRConvolverChL = new ITAUPConvolution(VAConfig::blockLength, VAConfig::hrirLength);
_FIRConvolverChL->SetFilterExchangeFadingFunction(ITABase::FadingFunction::COSINE_SQUARE);
_FIRConvolverChL->SetFilterCrossfadeLength((std::min)(VAConfig::blockLength, 32));
_FIRConvolverChL->SetGain(1.0f, true);
}
ITAUPFilter* HRIRFilterChL = _FIRConvolverChL->RequestFilter();
HRIRFilterChL->identity();
_FIRConvolverChL->ExchangeFilter(HRIRFilterChL);
// initialize right channel convolver for each cluster
VABinauralCluster::~VABinauralCluster()
{
VABinauralSoundSource* source;
std::map<int, VABinauralSoundSource*>::const_iterator it;
_FIRConvolverChR = new ITAUPConvolution(VAConfig::blockLength, VAConfig::hrirLength);
// clear all references from this cluster
for (it = _sources.begin(); it != _sources.end();)
{
source = it->second;
it = _sources.erase(it);
_FIRConvolverChR->SetFilterExchangeFadingFunction(ITABase::FadingFunction::COSINE_SQUARE);
_FIRConvolverChR->SetFilterCrossfadeLength((std::min)(VAConfig::blockLength, 32));
_FIRConvolverChR->SetGain(1.0f, true);
source->RemoveReference();
}
ITAUPFilter* HRIRFilterChR = _FIRConvolverChR->RequestFilter();
HRIRFilterChR->identity();
_FIRConvolverChR->ExchangeFilter(HRIRFilterChR);
}
VABinauralCluster::~VABinauralCluster()
{}
void
VABinauralCluster::init(int sourceID, VABinauralSoundSource* source, VABinauralListener* listener, ITAUPConvolution* FIRConvolverChL, ITAUPConvolution* FIRConvolverChR)
VABinauralCluster::init(int sourceID, VABinauralSoundSource* source, VABinauralListener* listener)
{
_FIRConvolverChL = FIRConvolverChL;
_FIRConvolverChR = FIRConvolverChR;
_listener = listener;
_listenerPos = listener->predPos;
_clusterSourcePos = _clusterSourcePos + source->predPos;
_clusterSourceToListenerPos = _clusterSourcePos - _listenerPos;
// TODO: do new in the constructor and reshape on init if nescessary
_output = new ITASampleFrame(2, listener->output->GetLength(), true);
_tempHRIR = new ITASampleFrame(2, 256, true);
int outputLength = listener->output->GetLength();
if (_output->length() != outputLength) _output->init(2, outputLength, true);
_tmpChL.Init(listener->output->GetLength(), true);
_tmpChR.Init(listener->output->GetLength(), true);
......@@ -73,14 +76,14 @@ VABinauralCluster::init(int sourceID, VABinauralSoundSource* source, VABinauralL
void
VABinauralCluster::init(VABinauralCluster* cluster)
{
_FIRConvolverChL = cluster->_FIRConvolverChL;
_FIRConvolverChR = cluster->_FIRConvolverChR;
_listener = cluster->_listener;
_listenerPos = _listener->predPos;
_clusterSourcePos = cluster->_clusterSourcePos;
_clusterSourceToListenerPos = _clusterSourcePos - _listenerPos;
_output = new ITASampleFrame(2, _listener->output->GetLength(), true);
int outputLength = _listener->output->GetLength();
if (_output->length() != outputLength) _output->init(2, outputLength, true);
_tmpChL.Init(_listener->output->GetLength(), true);
_tmpChR.Init(_listener->output->GetLength(), true);
......@@ -228,3 +231,19 @@ VABinauralCluster::removeSource(int sourceID)
}
void
VABinauralCluster::PreRelease()
{
VABinauralSoundSource* source;
std::map<int, VABinauralSoundSource*>::const_iterator it;
// clear all references from this cluster
for (it = _sources.begin(); it != _sources.end();)
{
source = it->second;
it = _sources.erase(it);
source->RemoveReference();
}
}
......@@ -20,12 +20,10 @@ public:
VABinauralCluster();
VABinauralCluster(const VABinauralCluster& cluster);
~VABinauralCluster();
void
init(int sourceID, VABinauralSoundSource* source, VABinauralListener* listener, ITAUPConvolution* FIRConvolverChL, ITAUPConvolution* FIRConvolverChR);
init(int sourceID, VABinauralSoundSource* source, VABinauralListener* listener);
void
init(VABinauralCluster* cluster);
......@@ -48,6 +46,9 @@ public:
void
reset();
void
PreRelease();
private:
ITASampleBuffer _tmpChL;
ITASampleBuffer _tmpChR;
......
......@@ -7,9 +7,9 @@
#include "./VABinauralClusteringPoolFactory.h">
VABinauralClusterEngine::VABinauralClusterEngine(int blocklength)
VABinauralClusterEngine::VABinauralClusterEngine()
{
IVAPoolObjectFactory* clusteringFactory = new VABinauralClusteringPoolFactory(blocklength);
IVAPoolObjectFactory* clusteringFactory = new VABinauralClusteringPoolFactory();
_clusteringPool = IVAObjectPool::Create(16, 2, clusteringFactory, true);
}
......@@ -70,7 +70,7 @@ VABinauralClusterEngine::addListener(int listenerID, VABinauralListener* listene
{
VABinauralClustering* clustering = dynamic_cast< VABinauralClustering* >(_clusteringPool->RequestObject()); // Reference = 1
clustering->init(listenerID, listener, conf.numCluster, conf.HRIRFilterLength);
clustering->init(listenerID, listener, conf.numCluster);
// add local reference
_clusterings.insert(std::pair< int, VABinauralClustering* >(listenerID, clustering));
......
......@@ -19,14 +19,13 @@ class VABinauralClusterEngine
public:
struct clusterConfig_t {
int numCluster;
int HRIRFilterLength;
};
std::map< int, VABinauralClustering* > _clusterings;
~VABinauralClusterEngine();
VABinauralClusterEngine(int blocklength);
VABinauralClusterEngine();
void
update();
......
......@@ -15,8 +15,7 @@
#include "./VABinauralClustering.h"
#include "./VABinauralClusterPoolFactory.h"
VABinauralClustering::VABinauralClustering(int blocklength) :
_blocklength(blocklength)
VABinauralClustering::VABinauralClustering()
{
IVAPoolObjectFactory* clusterFactory = new VABinauralClusterPoolFactory();
clusterPool = IVAObjectPool::Create(16, 2, clusterFactory, true);
......@@ -37,9 +36,8 @@ VABinauralClustering::removeSource(int sourceID)
}
void
VABinauralClustering::init(int listenerID, VABinauralListener* listener, int numClusters, int HRIRFilterLength)
VABinauralClustering::init(int listenerID, VABinauralListener* listener, int numClusters)
{
_HRIRFilterLength = HRIRFilterLength;
_listenerID = listenerID;
_listener = listener;
_numClusters = numClusters;
......@@ -47,41 +45,7 @@ VABinauralClustering::init(int listenerID, VABinauralListener* listener, int num
_output = new ITASampleFrame(2, listener->output->GetLength(), true);
// initialize left channel convolver for each cluster
for (int i = 0; i < _numClusters; ++i)
{
ITAUPConvolution* convChL = new ITAUPConvolution(_blocklength, _HRIRFilterLength);
convChL->SetFilterExchangeFadingFunction(ITABase::FadingFunction::COSINE_SQUARE);
convChL->SetFilterCrossfadeLength((std::min)(_blocklength, 32));
convChL->SetGain(1.0f, true);
ITAUPFilter* HRIRFilterChL = convChL->RequestFilter();
HRIRFilterChL->identity();
convChL->ExchangeFilter(HRIRFilterChL);
FIRConvolverChL.insert(std::pair< int, ITAUPConvolution* >(i, convChL));
}
// initialize right channel convolver for each cluster
for (int i = 0; i < _numClusters; ++i)
{
ITAUPConvolution* convChR = new ITAUPConvolution(_blocklength, _HRIRFilterLength);
convChR->SetFilterExchangeFadingFunction(ITABase::FadingFunction::COSINE_SQUARE);
convChR->SetFilterCrossfadeLength((std::min)(_blocklength, 32));
convChR->SetGain(1.0f, true);
ITAUPFilter* HRIRFilterChR = convChR->RequestFilter();
HRIRFilterChR->identity();
convChR->ExchangeFilter(HRIRFilterChR);
FIRConvolverChR.insert(std::pair< int, ITAUPConvolution* >(i, convChR));
}
_curState.reset(new VABinauralClusteringState(_numClusters, _listener, clusterPool, &FIRConvolverChL, &FIRConvolverChR));
_curState.reset(new VABinauralClusteringState(_numClusters, _listener, clusterPool));
}
ITASampleFrame*
......@@ -118,7 +82,7 @@ VABinauralClustering::update()
if (_nextState == nullptr)
{
VABinauralClusteringState* state = new VABinauralClusteringState(_numClusters, _listener, clusterPool, &FIRConvolverChL, &FIRConvolverChR); //new VABinauralClusteringState(*_curState);
VABinauralClusteringState* state = new VABinauralClusteringState(_numClusters, _listener, clusterPool); //new VABinauralClusteringState(*_curState);
// remove removed sources
std::set< int >::const_iterator it;
......
......@@ -21,15 +21,12 @@ class VABinauralClustering : public CVAPoolObject
public:
IVAObjectPool* clusterPool;
std::map< int, ITAUPConvolution* > FIRConvolverChL;
std::map< int, ITAUPConvolution* > FIRConvolverChR;
~VABinauralClustering();
VABinauralClustering(int blocklength);
VABinauralClustering();
void
init(int listenerID, VABinauralListener* listener, int numClusters, int HRIRFilterLength);
init(int listenerID, VABinauralListener* listener, int numClusters);
ITASampleFrame*
getOutput();
......@@ -45,8 +42,6 @@ public:
private:
int _HRIRFilterLength;
int _blocklength;
int _listenerID;
int _numClusters;
double _threshold;
......
#include "VABinauralClusteringPoolFactory.h"
#include "VABinauralClustering.h"
VABinauralClusteringPoolFactory::VABinauralClusteringPoolFactory(int blocklength) :
_blocklength(blocklength)
VABinauralClusteringPoolFactory::VABinauralClusteringPoolFactory()
{
}
......@@ -14,5 +13,5 @@ VABinauralClusteringPoolFactory::~VABinauralClusteringPoolFactory()
CVAPoolObject*
VABinauralClusteringPoolFactory::CreatePoolObject()
{
return new VABinauralClustering(_blocklength);
return new VABinauralClustering();
};
\ No newline at end of file
......@@ -8,14 +8,13 @@
class VABinauralClusteringPoolFactory : public IVAPoolObjectFactory
{
public:
VABinauralClusteringPoolFactory(int blocklength);
VABinauralClusteringPoolFactory();
~VABinauralClusteringPoolFactory();
CVAPoolObject*
CreatePoolObject();
private:
int _blocklength;
};
#endif // IW_VACORE_BINAURALCLUSTERINGPOOLFACTORY
\ No newline at end of file
......@@ -10,12 +10,10 @@
#include "./VABinauralClusterPoolFactory.h"
VABinauralClusteringState::VABinauralClusteringState(int numClusters, VABinauralListener* listener, IVAObjectPool* clusterPool, std::map<int, ITAUPConvolution*>* FIRConvolverChL, std::map<int, ITAUPConvolution*>* FIRConvolverChR) :
VABinauralClusteringState::VABinauralClusteringState(int numClusters, VABinauralListener* listener, IVAObjectPool* clusterPool) :
numClusters(numClusters),
listener(listener),
_clusterPool(clusterPool),
_FIRConvolverChL(FIRConvolverChL),
_FIRConvolverChR(FIRConvolverChR)
_clusterPool(clusterPool)
{
for (int i = numClusters - 1; i >= 0; --i)
......@@ -24,23 +22,12 @@ VABinauralClusteringState::VABinauralClusteringState(int numClusters, VABinaural
}
}
VABinauralClusteringState::~VABinauralClusteringState()
{
for (auto &const clusterIt : clusters)
{
clusterIt.second->RemoveReference();
}
}
VABinauralClusteringState::VABinauralClusteringState(const VABinauralClusteringState& state) :
numClusters(state.numClusters),
listener(state.listener),
sourceClusterReference(state.sourceClusterReference),
freeClusterIDs(state.freeClusterIDs),
_clusterPool(state._clusterPool),
_FIRConvolverChL(state._FIRConvolverChL),
_FIRConvolverChR(state._FIRConvolverChR)
_clusterPool(state._clusterPool)
{
std::map< int, VABinauralCluster* >::const_iterator it;
......@@ -50,6 +37,14 @@ VABinauralClusteringState::VABinauralClusteringState(const VABinauralClusteringS
}
}
VABinauralClusteringState::~VABinauralClusteringState()
{
for (auto &const clusterIt : clusters)
{
clusterIt.second->RemoveReference();
}
}
void
VABinauralClusteringState::addSource(int sourceID, VABinauralSoundSource* source, double threshold, int numBlockedClusters)
{
......@@ -109,7 +104,7 @@ VABinauralClusteringState::createCluster(int sourceID, VABinauralSoundSource* s
int clusterID = freeClusterIDs.back();
VABinauralCluster* cluster = dynamic_cast< VABinauralCluster* >(_clusterPool->RequestObject()); // Reference = 1
cluster->init(sourceID, source, listener, _FIRConvolverChL->find(clusterID)->second, _FIRConvolverChR->find(clusterID)->second);
cluster->init(sourceID, source, listener);
clusters.insert(std::pair< int, VABinauralCluster* >(clusterID, cluster));
freeClusterIDs.pop();
......
......@@ -26,7 +26,7 @@ public:
VABinauralListener* listener;
VABinauralClusteringState(int numClusters, VABinauralListener* listener, IVAObjectPool* clusterPool, std::map<int, ITAUPConvolution*>* FIRConvolverCHL, std::map<int, ITAUPConvolution*>* FIRConvolverCHR);
VABinauralClusteringState(int numClusters, VABinauralListener* listener, IVAObjectPool* clusterPool);
VABinauralClusteringState(const VABinauralClusteringState& state);
......@@ -47,8 +47,6 @@ public:
double getMaxError();
private:
std::map<int, ITAUPConvolution*>* _FIRConvolverChL;
std::map<int, ITAUPConvolution*>* _FIRConvolverChR;
IVAObjectPool* _clusterPool;
};
......
#include "VAConfig.h"
int VAConfig::blockLength = 128;
int VAConfig::hrirLength = 256;
VAConfig::VAConfig() {}
VAConfig::~VAConfig() {}
#ifndef IW_VACORE_CONFIG
#define IW_VACORE_CONFIG
class VAConfig
{
public:
static int blockLength;
static int hrirLength;
private:
VAConfig();
~VAConfig();
};
#endif // IW_VACORE_CONFIG
\ No newline at end of file
# $Id:$
set( RelativeDir "src/Rendering/Binaural/RealTime/Utils/Config" )
set( RelativeSourceGroup "Source Files\\Rendering\\Binaural\\Realtime\\Utils\\Config" )
set( DirFiles
VAConfig.cpp
VAConfig.h
_SourceFiles.cmake
)
set( DirFiles_SourceGroup "${RelativeSourceGroup}" )
set( LocalSourceGroupFiles )
foreach( File ${DirFiles} )
list( APPEND LocalSourceGroupFiles "${RelativeDir}/${File}" )
list( APPEND ProjectSources "${RelativeDir}/${File}" )
endforeach()
source_group( ${DirFiles_SourceGroup} FILES ${LocalSourceGroupFiles} )
......@@ -2,7 +2,7 @@
set( RelativeDir "src/Rendering/Binaural/Realtime/Utils" )
set( RelativeSourceGroup "Source Files\\Rendering\\Binaural\\Realtime\\Utils" )
set( SubDirs BinauralListener BinauralClusterEngine BinauralSoundSource BinauralTimeOfArrivalEstimator RelationMetrics)
set( SubDirs BinauralListener BinauralClusterEngine BinauralSoundSource BinauralTimeOfArrivalEstimator RelationMetrics Config)
set( DirFiles
_SourceFiles.cmake
......
......@@ -16,6 +16,7 @@
#include <ITAVariableDelayLine.h>
// Utils
#include "./Utils/Config/VAConfig.h"
#include "./Utils/BinauralListener/VABinauralListenerPoolFactory.h"
#include "./Utils/BinauralSoundSource/VABinauralSoundSourcePoolFactory.h"
......@@ -27,7 +28,7 @@ VABinauralRealTimeRenderer::VABinauralRealTimeRenderer( const CVAAudioRendererIn
_curSceneState(NULL),
_indicateReset(false),
_resetAck(false),
_clusterEngine(GetBlocklength())
_clusterEngine()
{
init(*_params.pConfig);
......@@ -100,6 +101,9 @@ VABinauralRealTimeRenderer::init( const CVAStruct& oArgs )
_defaultSourceConf.blockLength = GetBlocklength();
_defaultSourceConf.sampleRate = GetSampleRate();
VAConfig::blockLength = GetBlocklength();
VAConfig::hrirLength = _hrirFilterLength;
}
void
......@@ -146,20 +150,6 @@ VABinauralRealTimeRenderer::ProcessStream(const ITAStreamInfo* streamInfo)
updateTrajectories(time);
// -- create output for every listener
/* std::map< int, VABinauralListener* >::const_iterator it;
for (it = _listeners.begin(); it != _listeners.end(); ++it)
{
VABinauralClustering* clustering = _clusterEngine.getClustering(it->first);
if (clustering){
output = clustering->getOutput();
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;
......@@ -353,7 +343,7 @@ VABinauralRealTimeRenderer::createListener(int listenerID, const CVAReceiverStat
_listeners.insert(std::pair< int, VABinauralListener* >(listenerID, listener));
// add listener to clustering
VABinauralClusterEngine::clusterConfig_t config = { /*numClusters=*/ 9, /*hrirFilterLength*/ _hrirFilterLength};
VABinauralClusterEngine::clusterConfig_t config = { /*numClusters=*/ 9};
_clusterEngine.addListener(listenerID, listener, config);
}
......
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