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

Added global VAConfig.

parent 6a52da6c
...@@ -12,50 +12,53 @@ ...@@ -12,50 +12,53 @@
#include <ITAConstants.h> #include <ITAConstants.h>
// Utils // Utils
#include "../Config/VAConfig.h"
#include "../RelationMetrics/VARelationMetrics.h" #include "../RelationMetrics/VARelationMetrics.h"
#include "../BinauralTimeOfArrivalEstimator/VABinauralTOAEstimator.h" #include "../BinauralTimeOfArrivalEstimator/VABinauralTOAEstimator.h"
VABinauralCluster::VABinauralCluster() VABinauralCluster::VABinauralCluster()
{ {
} _output = new ITASampleFrame(2, VAConfig::blockLength, true);
_tempHRIR = new ITASampleFrame(2, VAConfig::hrirLength, true);
VABinauralCluster::VABinauralCluster(const VABinauralCluster& cluster) : // initialize left channel convolver for each cluster
maxError(cluster.maxError), _FIRConvolverChL = new ITAUPConvolution(VAConfig::blockLength, VAConfig::hrirLength);
numSources(cluster.numSources), _FIRConvolverChL->SetFilterExchangeFadingFunction(ITABase::FadingFunction::COSINE_SQUARE);
_clusterSourcePos(cluster._clusterSourcePos) _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() _FIRConvolverChR = new ITAUPConvolution(VAConfig::blockLength, VAConfig::hrirLength);
{
VABinauralSoundSource* source;
std::map<int, VABinauralSoundSource*>::const_iterator it;
// clear all references from this cluster _FIRConvolverChR->SetFilterExchangeFadingFunction(ITABase::FadingFunction::COSINE_SQUARE);
for (it = _sources.begin(); it != _sources.end();) _FIRConvolverChR->SetFilterCrossfadeLength((std::min)(VAConfig::blockLength, 32));
{ _FIRConvolverChR->SetGain(1.0f, true);
source = it->second;
it = _sources.erase(it);
source->RemoveReference(); ITAUPFilter* HRIRFilterChR = _FIRConvolverChR->RequestFilter();
} HRIRFilterChR->identity();
_FIRConvolverChR->ExchangeFilter(HRIRFilterChR);
} }
VABinauralCluster::~VABinauralCluster()
{}
void 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; _listener = listener;
_listenerPos = listener->predPos; _listenerPos = listener->predPos;
_clusterSourcePos = _clusterSourcePos + source->predPos; _clusterSourcePos = _clusterSourcePos + source->predPos;
_clusterSourceToListenerPos = _clusterSourcePos - _listenerPos; _clusterSourceToListenerPos = _clusterSourcePos - _listenerPos;
// TODO: do new in the constructor and reshape on init if nescessary int outputLength = listener->output->GetLength();
_output = new ITASampleFrame(2, listener->output->GetLength(), true);
_tempHRIR = new ITASampleFrame(2, 256, true); if (_output->length() != outputLength) _output->init(2, outputLength, true);
_tmpChL.Init(listener->output->GetLength(), true); _tmpChL.Init(listener->output->GetLength(), true);
_tmpChR.Init(listener->output->GetLength(), true); _tmpChR.Init(listener->output->GetLength(), true);
...@@ -73,14 +76,14 @@ VABinauralCluster::init(int sourceID, VABinauralSoundSource* source, VABinauralL ...@@ -73,14 +76,14 @@ VABinauralCluster::init(int sourceID, VABinauralSoundSource* source, VABinauralL
void void
VABinauralCluster::init(VABinauralCluster* cluster) VABinauralCluster::init(VABinauralCluster* cluster)
{ {
_FIRConvolverChL = cluster->_FIRConvolverChL;
_FIRConvolverChR = cluster->_FIRConvolverChR;
_listener = cluster->_listener; _listener = cluster->_listener;
_listenerPos = _listener->predPos; _listenerPos = _listener->predPos;
_clusterSourcePos = cluster->_clusterSourcePos; _clusterSourcePos = cluster->_clusterSourcePos;
_clusterSourceToListenerPos = _clusterSourcePos - _listenerPos; _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); _tmpChL.Init(_listener->output->GetLength(), true);
_tmpChR.Init(_listener->output->GetLength(), true); _tmpChR.Init(_listener->output->GetLength(), true);
...@@ -228,3 +231,19 @@ VABinauralCluster::removeSource(int sourceID) ...@@ -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: ...@@ -20,12 +20,10 @@ public:
VABinauralCluster(); VABinauralCluster();
VABinauralCluster(const VABinauralCluster& cluster);
~VABinauralCluster(); ~VABinauralCluster();
void void
init(int sourceID, VABinauralSoundSource* source, VABinauralListener* listener, ITAUPConvolution* FIRConvolverChL, ITAUPConvolution* FIRConvolverChR); init(int sourceID, VABinauralSoundSource* source, VABinauralListener* listener);
void void
init(VABinauralCluster* cluster); init(VABinauralCluster* cluster);
...@@ -48,6 +46,9 @@ public: ...@@ -48,6 +46,9 @@ public:
void void
reset(); reset();
void
PreRelease();
private: private:
ITASampleBuffer _tmpChL; ITASampleBuffer _tmpChL;
ITASampleBuffer _tmpChR; ITASampleBuffer _tmpChR;
......
...@@ -7,9 +7,9 @@ ...@@ -7,9 +7,9 @@
#include "./VABinauralClusteringPoolFactory.h"> #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); _clusteringPool = IVAObjectPool::Create(16, 2, clusteringFactory, true);
} }
...@@ -70,7 +70,7 @@ VABinauralClusterEngine::addListener(int listenerID, VABinauralListener* listene ...@@ -70,7 +70,7 @@ VABinauralClusterEngine::addListener(int listenerID, VABinauralListener* listene
{ {
VABinauralClustering* clustering = dynamic_cast< VABinauralClustering* >(_clusteringPool->RequestObject()); // Reference = 1 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 // add local reference
_clusterings.insert(std::pair< int, VABinauralClustering* >(listenerID, clustering)); _clusterings.insert(std::pair< int, VABinauralClustering* >(listenerID, clustering));
......
...@@ -19,14 +19,13 @@ class VABinauralClusterEngine ...@@ -19,14 +19,13 @@ class VABinauralClusterEngine
public: public:
struct clusterConfig_t { struct clusterConfig_t {
int numCluster; int numCluster;
int HRIRFilterLength;
}; };
std::map< int, VABinauralClustering* > _clusterings; std::map< int, VABinauralClustering* > _clusterings;
~VABinauralClusterEngine(); ~VABinauralClusterEngine();
VABinauralClusterEngine(int blocklength); VABinauralClusterEngine();
void void
update(); update();
......
...@@ -15,8 +15,7 @@ ...@@ -15,8 +15,7 @@
#include "./VABinauralClustering.h" #include "./VABinauralClustering.h"
#include "./VABinauralClusterPoolFactory.h" #include "./VABinauralClusterPoolFactory.h"
VABinauralClustering::VABinauralClustering(int blocklength) : VABinauralClustering::VABinauralClustering()
_blocklength(blocklength)
{ {
IVAPoolObjectFactory* clusterFactory = new VABinauralClusterPoolFactory(); IVAPoolObjectFactory* clusterFactory = new VABinauralClusterPoolFactory();
clusterPool = IVAObjectPool::Create(16, 2, clusterFactory, true); clusterPool = IVAObjectPool::Create(16, 2, clusterFactory, true);
...@@ -37,9 +36,8 @@ VABinauralClustering::removeSource(int sourceID) ...@@ -37,9 +36,8 @@ VABinauralClustering::removeSource(int sourceID)
} }
void void
VABinauralClustering::init(int listenerID, VABinauralListener* listener, int numClusters, int HRIRFilterLength) VABinauralClustering::init(int listenerID, VABinauralListener* listener, int numClusters)
{ {
_HRIRFilterLength = HRIRFilterLength;
_listenerID = listenerID; _listenerID = listenerID;
_listener = listener; _listener = listener;
_numClusters = numClusters; _numClusters = numClusters;
...@@ -47,41 +45,7 @@ VABinauralClustering::init(int listenerID, VABinauralListener* listener, int num ...@@ -47,41 +45,7 @@ VABinauralClustering::init(int listenerID, VABinauralListener* listener, int num
_output = new ITASampleFrame(2, listener->output->GetLength(), true); _output = new ITASampleFrame(2, listener->output->GetLength(), true);
// initialize left channel convolver for each cluster _curState.reset(new VABinauralClusteringState(_numClusters, _listener, clusterPool));
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));
} }
ITASampleFrame* ITASampleFrame*
...@@ -118,7 +82,7 @@ VABinauralClustering::update() ...@@ -118,7 +82,7 @@ VABinauralClustering::update()
if (_nextState == nullptr) 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 // remove removed sources
std::set< int >::const_iterator it; std::set< int >::const_iterator it;
......
...@@ -21,15 +21,12 @@ class VABinauralClustering : public CVAPoolObject ...@@ -21,15 +21,12 @@ class VABinauralClustering : public CVAPoolObject
public: public:
IVAObjectPool* clusterPool; IVAObjectPool* clusterPool;
std::map< int, ITAUPConvolution* > FIRConvolverChL;
std::map< int, ITAUPConvolution* > FIRConvolverChR;
~VABinauralClustering(); ~VABinauralClustering();
VABinauralClustering(int blocklength); VABinauralClustering();
void void
init(int listenerID, VABinauralListener* listener, int numClusters, int HRIRFilterLength); init(int listenerID, VABinauralListener* listener, int numClusters);
ITASampleFrame* ITASampleFrame*
getOutput(); getOutput();
...@@ -45,8 +42,6 @@ public: ...@@ -45,8 +42,6 @@ public:
private: private:
int _HRIRFilterLength;
int _blocklength;
int _listenerID; int _listenerID;
int _numClusters; int _numClusters;
double _threshold; double _threshold;
......
#include "VABinauralClusteringPoolFactory.h" #include "VABinauralClusteringPoolFactory.h"
#include "VABinauralClustering.h" #include "VABinauralClustering.h"
VABinauralClusteringPoolFactory::VABinauralClusteringPoolFactory(int blocklength) : VABinauralClusteringPoolFactory::VABinauralClusteringPoolFactory()
_blocklength(blocklength)
{ {
} }
...@@ -14,5 +13,5 @@ VABinauralClusteringPoolFactory::~VABinauralClusteringPoolFactory() ...@@ -14,5 +13,5 @@ VABinauralClusteringPoolFactory::~VABinauralClusteringPoolFactory()
CVAPoolObject* CVAPoolObject*
VABinauralClusteringPoolFactory::CreatePoolObject() VABinauralClusteringPoolFactory::CreatePoolObject()
{ {
return new VABinauralClustering(_blocklength); return new VABinauralClustering();
}; };
\ No newline at end of file
...@@ -8,14 +8,13 @@ ...@@ -8,14 +8,13 @@
class VABinauralClusteringPoolFactory : public IVAPoolObjectFactory class VABinauralClusteringPoolFactory : public IVAPoolObjectFactory
{ {
public: public:
VABinauralClusteringPoolFactory(int blocklength); VABinauralClusteringPoolFactory();
~VABinauralClusteringPoolFactory(); ~VABinauralClusteringPoolFactory();
CVAPoolObject* CVAPoolObject*
CreatePoolObject(); CreatePoolObject();
private: private:
int _blocklength;
}; };
#endif // IW_VACORE_BINAURALCLUSTERINGPOOLFACTORY #endif // IW_VACORE_BINAURALCLUSTERINGPOOLFACTORY
\ No newline at end of file
...@@ -10,12 +10,10 @@ ...@@ -10,12 +10,10 @@
#include "./VABinauralClusterPoolFactory.h" #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), numClusters(numClusters),
listener(listener), listener(listener),
_clusterPool(clusterPool), _clusterPool(clusterPool)
_FIRConvolverChL(FIRConvolverChL),
_FIRConvolverChR(FIRConvolverChR)
{ {
for (int i = numClusters - 1; i >= 0; --i) for (int i = numClusters - 1; i >= 0; --i)
...@@ -24,23 +22,12 @@ VABinauralClusteringState::VABinauralClusteringState(int numClusters, VABinaural ...@@ -24,23 +22,12 @@ VABinauralClusteringState::VABinauralClusteringState(int numClusters, VABinaural
} }
} }
VABinauralClusteringState::~VABinauralClusteringState()
{
for (auto &const clusterIt : clusters)
{
clusterIt.second->RemoveReference();
}
}
VABinauralClusteringState::VABinauralClusteringState(const VABinauralClusteringState& state) : VABinauralClusteringState::VABinauralClusteringState(const VABinauralClusteringState& state) :
numClusters(state.numClusters), numClusters(state.numClusters),
listener(state.listener), listener(state.listener),
sourceClusterReference(state.sourceClusterReference), sourceClusterReference(state.sourceClusterReference),
freeClusterIDs(state.freeClusterIDs), freeClusterIDs(state.freeClusterIDs),
_clusterPool(state._clusterPool), _clusterPool(state._clusterPool)
_FIRConvolverChL(state._FIRConvolverChL),
_FIRConvolverChR(state._FIRConvolverChR)
{ {
std::map< int, VABinauralCluster* >::const_iterator it; std::map< int, VABinauralCluster* >::const_iterator it;
...@@ -50,6 +37,14 @@ VABinauralClusteringState::VABinauralClusteringState(const VABinauralClusteringS ...@@ -50,6 +37,14 @@ VABinauralClusteringState::VABinauralClusteringState(const VABinauralClusteringS
} }
} }
VABinauralClusteringState::~VABinauralClusteringState()
{
for (auto &const clusterIt : clusters)
{
clusterIt.second->RemoveReference();
}
}
void void
VABinauralClusteringState::addSource(int sourceID, VABinauralSoundSource* source, double threshold, int numBlockedClusters) VABinauralClusteringState::addSource(int sourceID, VABinauralSoundSource* source, double threshold, int numBlockedClusters)
{ {
...@@ -109,7 +104,7 @@ VABinauralClusteringState::createCluster(int sourceID, VABinauralSoundSource* s ...@@ -109,7 +104,7 @@ VABinauralClusteringState::createCluster(int sourceID, VABinauralSoundSource* s
int clusterID = freeClusterIDs.back(); int clusterID = freeClusterIDs.back();
VABinauralCluster* cluster = dynamic_cast< VABinauralCluster* >(_clusterPool->RequestObject()); // Reference = 1 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)); clusters.insert(std::pair< int, VABinauralCluster* >(clusterID, cluster));
freeClusterIDs.pop(); freeClusterIDs.pop();
......
...@@ -26,7 +26,7 @@ public: ...@@ -26,7 +26,7 @@ public:
VABinauralListener* listener; 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); VABinauralClusteringState(const VABinauralClusteringState& state);
...@@ -47,8 +47,6 @@ public: ...@@ -47,8 +47,6 @@ public:
double getMaxError(); double getMaxError();
private: private:
std::map<int, ITAUPConvolution*>* _FIRConvolverChL;
std::map<int, ITAUPConvolution*>* _FIRConvolverChR;
IVAObjectPool* _clusterPool; 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