Commit 6a52da6c authored by Lucas Moesch's avatar Lucas Moesch
Browse files

Added first HRTF convolution implementation.

parent 813af282
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
#include "../../../../../directivities/VADirectivityDAFFHRIR.h" #include "../../../../../directivities/VADirectivityDAFFHRIR.h"
// ITA includes // ITA includes
#include <ITAUPFilter.h>
#include <ITAUPFilterPool.h>
#include <ITAConstants.h> #include <ITAConstants.h>
// Utils // Utils
...@@ -51,7 +53,9 @@ VABinauralCluster::init(int sourceID, VABinauralSoundSource* source, VABinauralL ...@@ -51,7 +53,9 @@ VABinauralCluster::init(int sourceID, VABinauralSoundSource* source, VABinauralL
_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
_output = new ITASampleFrame(2, listener->output->GetLength(), true); _output = new ITASampleFrame(2, listener->output->GetLength(), true);
_tempHRIR = new ITASampleFrame(2, 256, 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);
...@@ -124,9 +128,6 @@ VABinauralCluster::getOutput() ...@@ -124,9 +128,6 @@ VABinauralCluster::getOutput()
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->Process(input, &(_tmpChL)); source->vdlChL->Process(input, &(_tmpChL));
source->vdlChR->Process(input, &(_tmpChR)); source->vdlChR->Process(input, &(_tmpChR));
...@@ -137,10 +138,29 @@ VABinauralCluster::getOutput() ...@@ -137,10 +138,29 @@ VABinauralCluster::getOutput()
// convolve here! // convolve here!
CVADirectivityDAFFHRIR* HRIR = (CVADirectivityDAFFHRIR *)_listener->directivity; CVADirectivityDAFFHRIR* HRIR = (CVADirectivityDAFFHRIR *)_listener->directivity;
ITAUPFilter* HRIRFilterChL = _FIRConvolverChL->GetFilterPool()->RequestFilter();
ITAUPFilter* HRIRFilterChR = _FIRConvolverChR->GetFilterPool()->RequestFilter();
if (HRIR){ if (HRIR){
int index = -1; int index = -1;
int filterLength = 0;
filterLength = HRIR->GetProperties()->iFilterLength;
if (_tempHRIR->length() != filterLength)
{
_tempHRIR->init(2, filterLength, false);
}
HRIR->GetHRIR(_tempHRIR, clusterSourceMetrics.phi * 180 / ITAConstants::PI_F, clusterSourceMetrics.theta * 180 / ITAConstants::PI_F, clusterSourceMetrics.dist);
HRIRFilterChL->Load((*_tempHRIR)[0].data(), filterLength);
HRIRFilterChR->Load((*_tempHRIR)[1].data(), filterLength);
HRIR->GetNearestNeighbour(clusterSourceMetrics.phi, clusterSourceMetrics.theta, &index); _FIRConvolverChL->ExchangeFilter(HRIRFilterChL);
_FIRConvolverChR->ExchangeFilter(HRIRFilterChR);
_FIRConvolverChL->ReleaseFilter(HRIRFilterChL);
_FIRConvolverChR->ReleaseFilter(HRIRFilterChR);
_FIRConvolverChL->Process((*_output)[0].data(), (*_output)[0].data(), ITABase::MixingMethod::OVERWRITE); _FIRConvolverChL->Process((*_output)[0].data(), (*_output)[0].data(), ITABase::MixingMethod::OVERWRITE);
_FIRConvolverChR->Process((*_output)[1].data(), (*_output)[1].data(), ITABase::MixingMethod::OVERWRITE); _FIRConvolverChR->Process((*_output)[1].data(), (*_output)[1].data(), ITABase::MixingMethod::OVERWRITE);
......
...@@ -53,6 +53,7 @@ private: ...@@ -53,6 +53,7 @@ private:
ITASampleBuffer _tmpChR; ITASampleBuffer _tmpChR;
ITASampleFrame* _output; ITASampleFrame* _output;
ITASampleFrame* _tempHRIR;
VABinauralListener* _listener; VABinauralListener* _listener;
......
...@@ -87,16 +87,23 @@ VABinauralClustering::init(int listenerID, VABinauralListener* listener, int num ...@@ -87,16 +87,23 @@ VABinauralClustering::init(int listenerID, VABinauralListener* listener, int num
ITASampleFrame* ITASampleFrame*
VABinauralClustering::getOutput() VABinauralClustering::getOutput()
{ {
// --
_output->zero(); _output->zero();
// swap out clustering state // swap out clustering state
if (_nextState != nullptr) _curState.reset(_nextState.release()); if (_nextState != nullptr){
_curState.reset(_nextState.release());
};
std::map< int, VABinauralCluster*>::const_iterator clusterIt;
clusterIt = _curState->clusters.begin();
ITASampleFrame* clusterOutput = clusterIt->second->getOutput();
std::map< int, VABinauralCluster*>::const_iterator it; (*_output)[0] += (*clusterOutput)[0];
for (it = _curState->clusters.begin(); it != _curState->clusters.end(); ++it) (*_output)[1] += (*clusterOutput)[1];
for (++clusterIt; clusterIt != _curState->clusters.end(); ++clusterIt)
{ {
ITASampleFrame* clusterOutput = it->second->getOutput(); clusterOutput = clusterIt->second->getOutput();
(*_output)[0] += (*clusterOutput)[0]; (*_output)[0] += (*clusterOutput)[0];
(*_output)[1] += (*clusterOutput)[1]; (*_output)[1] += (*clusterOutput)[1];
...@@ -108,8 +115,6 @@ VABinauralClustering::getOutput() ...@@ -108,8 +115,6 @@ VABinauralClustering::getOutput()
void void
VABinauralClustering::update() VABinauralClustering::update()
{ {
//TODO: DIRTY HACK
if (_nextState == nullptr) if (_nextState == nullptr)
{ {
......
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