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

WIP - added convolver initialization.

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