Commit 665fbd6e authored by Lucas Moesch's avatar Lucas Moesch

WIP - added convolver initialization.

parent 3d4c2f59
......@@ -39,8 +39,10 @@ VABinauralCluster::~VABinauralCluster()
}
void
VABinauralCluster::init(int sourceID, VABinauralSoundSource* source, VABinauralListener* listener)
VABinauralCluster::init(int sourceID, VABinauralSoundSource* source, VABinauralListener* listener, ITAUPConvolution* FIRConvolverChL, ITAUPConvolution* FIRConvolverChR)
{
_FIRConvolverChL = FIRConvolverChL;
_FIRConvolverChR = FIRConvolverChR;
_listener = listener;
_listenerPos = listener->predPos;
_clusterSourcePos = _clusterSourcePos + source->predPos;
......@@ -64,6 +66,8 @@ 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;
......@@ -114,12 +118,11 @@ VABinauralCluster::getOutput()
double toaSourceChL = _listener->toaEstimator->getTOALeft(sourceMetrics.phi, sourceMetrics.theta);
double toSourceaChR = _listener->toaEstimator->getTOARight(sourceMetrics.phi, sourceMetrics.theta);
//source->vdlChL->SetDelayTime(toaDistance + toaSourceChL - toaHRTFChL);
//source->vdlChR->SetDelayTime(toaDistance + toSourceaChR - toaHRTFChR);
source->vdlChL->SetDelayTime(toaDistance + toaSourceChL);
source->vdlChR->SetDelayTime(toaDistance + toSourceaChR);
source->vdlChL->SetDelayTime(toaDistance + toaSourceChL - toaHRTFChL);
source->vdlChR->SetDelayTime(toaDistance + toSourceaChR - toaHRTFChR);
//source->vdlChL->SetDelayTime(toaDistance + toaSourceChL);
//source->vdlChR->SetDelayTime(toaDistance + toSourceaChR);
source->vdlChL->Process(input, &(_tmpChL));
source->vdlChR->Process(input, &(_tmpChR));
......@@ -130,6 +133,9 @@ VABinauralCluster::getOutput()
// convolve here!
_FIRConvolverChL->Process((*_output)[0].data(), (*_output)[0].data(), ITABase::MixingMethod::OVERWRITE);
_FIRConvolverChR->Process((*_output)[1].data(), (*_output)[1].data(), ITABase::MixingMethod::OVERWRITE);
return _output;
}
......
......@@ -4,6 +4,9 @@
// VA Includes
#include <VA.h>
// ITA includes
#include <ITAUPConvolution.h>
// Utils
#include "../BinauralSoundSource/VABinauralSoundSource.h"
#include "../BinauralListener/VABinauralListener.h"
......@@ -22,7 +25,7 @@ public:
~VABinauralCluster();
void
init(int sourceID, VABinauralSoundSource* source, VABinauralListener* listener);
init(int sourceID, VABinauralSoundSource* source, VABinauralListener* listener, ITAUPConvolution* FIRConvolverChL, ITAUPConvolution* FIRConvolverChR);
void
init(VABinauralCluster* cluster);
......@@ -53,13 +56,15 @@ private:
VABinauralListener* _listener;
ITAUPConvolution* _FIRConvolverChL;
ITAUPConvolution* _FIRConvolverChR;
VAVec3 _listenerPos;
VAVec3 _clusterSourcePos;
VAVec3 _clusterSourceToListenerPos;
std::map<int, VABinauralSoundSource* > _sources;
double
cummulativeMovingAverage(int n, double average, double value);
};
......
......@@ -7,9 +7,9 @@
#include "./VABinauralClusteringPoolFactory.h">
VABinauralClusterEngine::VABinauralClusterEngine()
VABinauralClusterEngine::VABinauralClusterEngine(int blocklength)
{
IVAPoolObjectFactory* clusteringFactory = new VABinauralClusteringPoolFactory();
IVAPoolObjectFactory* clusteringFactory = new VABinauralClusteringPoolFactory(blocklength);
_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);
clustering->init(listenerID, listener, conf.numCluster, conf.HRIRFilterLength);
// add local reference
_clusterings.insert(std::pair< int, VABinauralClustering* >(listenerID, clustering));
......
......@@ -19,13 +19,14 @@ class VABinauralClusterEngine
public:
struct clusterConfig_t {
int numCluster;
int HRIRFilterLength;
};
std::map< int, VABinauralClustering* > _clusterings;
~VABinauralClusterEngine();
VABinauralClusterEngine();
VABinauralClusterEngine(int blocklength);
void
update();
......
......@@ -8,14 +8,18 @@
// VA
#include <VAObjectPool.h>
// ITA includes
#include <ITAUPFilter.h>
// Utils
#include "./VABinauralClustering.h"
#include "./VABinauralClusterPoolFactory.h"
VABinauralClustering::VABinauralClustering()
VABinauralClustering::VABinauralClustering(int blocklength) :
_blocklength(blocklength)
{
IVAPoolObjectFactory* clusterFactory = new VABinauralClusterPoolFactory();
_clusterPool = IVAObjectPool::Create(16, 2, clusterFactory, true);
clusterPool = IVAObjectPool::Create(16, 2, clusterFactory, true);
};
VABinauralClustering::~VABinauralClustering(){};
......@@ -33,8 +37,9 @@ VABinauralClustering::removeSource(int sourceID)
}
void
VABinauralClustering::init(int listenerID, VABinauralListener* listener, int numClusters)
VABinauralClustering::init(int listenerID, VABinauralListener* listener, int numClusters, int HRIRFilterLength)
{
_HRIRFilterLength = HRIRFilterLength;
_listenerID = listenerID;
_listener = listener;
_numClusters = numClusters;
......@@ -42,7 +47,41 @@ VABinauralClustering::init(int listenerID, VABinauralListener* listener, int num
_output = new ITASampleFrame(2, listener->output->GetLength(), true);
_curState.reset(new VABinauralClusteringState(_numClusters, _listener));
// 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(0.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(0.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*
......
......@@ -19,12 +19,17 @@ class VABinauralClustering : public CVAPoolObject
// friend VABinauralClusteringState;
public:
IVAObjectPool* clusterPool;
std::map< int, ITAUPConvolution* > FIRConvolverChL;
std::map< int, ITAUPConvolution* > FIRConvolverChR;
~VABinauralClustering();
VABinauralClustering();
VABinauralClustering(int blocklength);
void
init(int listenerID, VABinauralListener* listener, int numClusters);
init(int listenerID, VABinauralListener* listener, int numClusters, int HRIRFilterLength);
ITASampleFrame*
getOutput();
......@@ -40,19 +45,20 @@ public:
private:
int _HRIRFilterLength;
int _blocklength;
int _listenerID;
int _numClusters;
double _threshold;
ITASampleFrame* _output;
std::unique_ptr<VABinauralClusteringState> _curState;
std::unique_ptr<VABinauralClusteringState> _nextState;
VABinauralListener* _listener;
IVAObjectPool* _clusterPool;
std::set< int > _delSourceIDs;
std::unique_ptr<VABinauralClusteringState> _curState;
std::unique_ptr<VABinauralClusteringState> _nextState;
std::map< int, VABinauralSoundSource* > _unassignedSources;
std::map< int, VABinauralSoundSource* > _assignedSources;
......
#include "VABinauralClusteringPoolFactory.h"
#include "VABinauralClustering.h"
VABinauralClusteringPoolFactory::VABinauralClusteringPoolFactory()
VABinauralClusteringPoolFactory::VABinauralClusteringPoolFactory(int blocklength) :
_blocklength(blocklength)
{
}
......@@ -13,5 +14,5 @@ VABinauralClusteringPoolFactory::~VABinauralClusteringPoolFactory()
CVAPoolObject*
VABinauralClusteringPoolFactory::CreatePoolObject()
{
return new VABinauralClustering();
return new VABinauralClustering(_blocklength);
};
\ No newline at end of file
......@@ -8,12 +8,14 @@
class VABinauralClusteringPoolFactory : public IVAPoolObjectFactory
{
public:
VABinauralClusteringPoolFactory();
VABinauralClusteringPoolFactory(int blocklength);
~VABinauralClusteringPoolFactory();
CVAPoolObject*
CreatePoolObject();
private:
int _blocklength;
};
#endif // IW_VACORE_BINAURALCLUSTERINGPOOLFACTORY
\ No newline at end of file
......@@ -10,34 +10,39 @@
#include "./VABinauralClusterPoolFactory.h"
VABinauralClusteringState::VABinauralClusteringState(int numClusters, VABinauralListener* listener) :
VABinauralClusteringState::VABinauralClusteringState(int numClusters, VABinauralListener* listener, IVAObjectPool* clusterPool, std::map<int, ITAUPConvolution*>* FIRConvolverChL, std::map<int, ITAUPConvolution*>* FIRConvolverChR) :
numClusters(numClusters),
listener(listener)
listener(listener),
_clusterPool(clusterPool),
_FIRConvolverChL(FIRConvolverChL),
_FIRConvolverChR(FIRConvolverChR)
{
for (int i = numClusters - 1; i >= 0; --i)
{
freeClusterIDs.push(i);
}
IVAPoolObjectFactory* clusterFactory = new VABinauralClusterPoolFactory();
_clusterPool = IVAObjectPool::Create(16, 2, clusterFactory, true);
}
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)
freeClusterIDs(state.freeClusterIDs),
_clusterPool(state._clusterPool),
_FIRConvolverChL(state._FIRConvolverChL),
_FIRConvolverChR(state._FIRConvolverChR)
{
IVAPoolObjectFactory* clusterFactory = new VABinauralClusterPoolFactory();
_clusterPool = IVAObjectPool::Create(16, 2, clusterFactory, true);
std::map< int, VABinauralCluster* >::const_iterator it;
for (it = state.clusters.begin(); it != state.clusters.end(); ++it)
{
......@@ -104,7 +109,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);
cluster->init(sourceID, source, listener, _FIRConvolverChL->find(clusterID)->second, _FIRConvolverChR->find(clusterID)->second);
clusters.insert(std::pair< int, VABinauralCluster* >(clusterID, cluster));
freeClusterIDs.pop();
......
......@@ -7,6 +7,9 @@
#include <VA.h>
#include <VAPoolObject.h>
// ITA includes
#include <ITAUPConvolution.h>
// Utils
#include "VABinauralCluster.h"
#include "../BinauralSoundSource/VABinauralSoundSource.h"
......@@ -23,7 +26,7 @@ public:
VABinauralListener* listener;
VABinauralClusteringState(int numClusters, VABinauralListener* listener);
VABinauralClusteringState(int numClusters, VABinauralListener* listener, IVAObjectPool* clusterPool, std::map<int, ITAUPConvolution*>* FIRConvolverCHL, std::map<int, ITAUPConvolution*>* FIRConvolverCHR);
VABinauralClusteringState(const VABinauralClusteringState& state);
......@@ -44,6 +47,8 @@ public:
double getMaxError();
private:
std::map<int, ITAUPConvolution*>* _FIRConvolverChL;
std::map<int, ITAUPConvolution*>* _FIRConvolverChR;
IVAObjectPool* _clusterPool;
};
......
......@@ -4,8 +4,8 @@
VABinauralSoundSource::VABinauralSoundSource(const config_t& conf) :
conf( conf )
{
vdlChL = new CITAVariableDelayLine(conf.sampleRate, conf.blockLength, 3. * conf.sampleRate, CITAVariableDelayLine::CUBIC_SPLINE_INTERPOLATION);
vdlChR = new CITAVariableDelayLine(conf.sampleRate, conf.blockLength, 3. * conf.sampleRate, CITAVariableDelayLine::CUBIC_SPLINE_INTERPOLATION);
vdlChL = new CITAVariableDelayLine(conf.sampleRate, conf.blockLength, 3. * conf.sampleRate, CITAVariableDelayLine::SWITCH);
vdlChR = new CITAVariableDelayLine(conf.sampleRate, conf.blockLength, 3. * conf.sampleRate, CITAVariableDelayLine::SWITCH);
}
......
......@@ -27,7 +27,7 @@ VABinauralRealTimeRenderer::VABinauralRealTimeRenderer( const CVAAudioRendererIn
_curSceneState(NULL),
_indicateReset(false),
_resetAck(false),
_clusterEngine()
_clusterEngine(GetBlocklength())
{
init(*_params.pConfig);
......@@ -345,7 +345,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 };
VABinauralClusterEngine::clusterConfig_t config = { /*numClusters=*/ 9, /*hrirFilterLength*/ _hrirFilterLength};
_clusterEngine.addListener(listenerID, listener, config);
}
......
......@@ -91,15 +91,10 @@ void CVAAudioRendererRegistry::RegisterInternalCoreFactoryMethods()
#endif
#ifdef VACORE_WITH_RENDERER_BINAURAL_ROOM_ACOUSTICS
RegisterRendererDefaultFactory< CVARoomAcousticsAudioRenderer>( "BinauralRoomAcoustics" );
<<<<<<< HEAD
#endif // VACORE_WITH_RENDERER_BINAURAL_ROOM_ACOUSTICS
#ifdef VACORE_WITH_RENDERER_BINAURAL_REAL_TIME
RegisterRendererDefaultFactory< VABinauralRealTimeRenderer>("BinauralRealTime");
#endif // VACORE_WITH_RENDERER_BINAURAL_REAL_TIME
=======
#endif
>>>>>>> develop
// Prototyping
#ifdef VACORE_WITH_RENDERER_PROTOTYPE_FREE_FIELD
RegisterRendererDefaultFactory< CVAPrototypeFreeFieldAudioRenderer >( "PrototypeFreeField" );
......
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