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

Added first HRTF convolution implementation.

parent 813af282
......@@ -7,6 +7,8 @@
#include "../../../../../directivities/VADirectivityDAFFHRIR.h"
// ITA includes
#include <ITAUPFilter.h>
#include <ITAUPFilterPool.h>
#include <ITAConstants.h>
// Utils
......@@ -51,7 +53,9 @@ VABinauralCluster::init(int sourceID, VABinauralSoundSource* source, VABinauralL
_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);
_tmpChL.Init(listener->output->GetLength(), true);
_tmpChR.Init(listener->output->GetLength(), true);
......@@ -124,9 +128,6 @@ VABinauralCluster::getOutput()
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));
......@@ -137,10 +138,29 @@ VABinauralCluster::getOutput()
// convolve here!
CVADirectivityDAFFHRIR* HRIR = (CVADirectivityDAFFHRIR *)_listener->directivity;
ITAUPFilter* HRIRFilterChL = _FIRConvolverChL->GetFilterPool()->RequestFilter();
ITAUPFilter* HRIRFilterChR = _FIRConvolverChR->GetFilterPool()->RequestFilter();
if (HRIR){
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);
_FIRConvolverChR->Process((*_output)[1].data(), (*_output)[1].data(), ITABase::MixingMethod::OVERWRITE);
......
......@@ -53,6 +53,7 @@ private:
ITASampleBuffer _tmpChR;
ITASampleFrame* _output;
ITASampleFrame* _tempHRIR;
VABinauralListener* _listener;
......
......@@ -87,16 +87,23 @@ VABinauralClustering::init(int listenerID, VABinauralListener* listener, int num
ITASampleFrame*
VABinauralClustering::getOutput()
{
// --
_output->zero();
// 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();
std::map< int, VABinauralCluster*>::const_iterator it;
for (it = _curState->clusters.begin(); it != _curState->clusters.end(); ++it)
ITASampleFrame* clusterOutput = clusterIt->second->getOutput();
(*_output)[0] += (*clusterOutput)[0];
(*_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)[1] += (*clusterOutput)[1];
......@@ -108,8 +115,6 @@ VABinauralClustering::getOutput()
void
VABinauralClustering::update()
{
//TODO: DIRTY HACK
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