VABinauralOutdoorWaveFront.cpp 3.48 KB
Newer Older
1
#include "VABinauralOutdoorWaveFront.h"
henryjandrew's avatar
wip  
henryjandrew committed
2 3
#include "VABinauralOutdoorSource.h"

4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
#include "../Clustering/VARelationMetrics.h"
#include "../Clustering/VAConfig.h"

#include "../../../Motion/VAMotionModelBase.h"
#include "../../../Motion/VASharedMotionModel.h"
#include "../../../Scene/VAScene.h"

#include <ITAVariableDelayLine.h>
#include <ITASampleBuffer.h>

CVABinauralOutdoorWaveFront::CVABinauralOutdoorWaveFront( const CVABinauralWaveFrontBase::Config& conf )
	: oConf( conf )
{
	vdlChL = new CITAVariableDelayLine( conf.sampleRate, conf.blockLength, (const float)( 3. * conf.sampleRate ), CITAVariableDelayLine::CUBIC_SPLINE_INTERPOLATION );
	vdlChR = new CITAVariableDelayLine( conf.sampleRate, conf.blockLength, (const float)( 3. * conf.sampleRate ), CITAVariableDelayLine::CUBIC_SPLINE_INTERPOLATION );
}

CVABinauralOutdoorWaveFront::~CVABinauralOutdoorWaveFront()
{
	delete vdlChR;
	delete vdlChL;
}

void CVABinauralOutdoorWaveFront::PreRequest()
{
	CVABasicMotionModel::Config sourceMotionConf;

	sourceMotionConf.bLogEstimatedOutputEnabled = oConf.motionModelLogEstimated;
	sourceMotionConf.bLogInputEnabled = oConf.motionModelLogInput;
	sourceMotionConf.dWindowDelay = oConf.motionModelWindowDelay;
	sourceMotionConf.dWindowSize = oConf.motionModelWindowSize;
	sourceMotionConf.iNumHistoryKeys = oConf.motionModelNumHistoryKeys;

	pMotionModel = new CVASharedMotionModel( new CVABasicMotionModel( sourceMotionConf ), true );
	pState = nullptr;
	pData = nullptr;
	hasValidTrajectory = false;

	/* @todo implement reset functionality for VDL
	vdlChL->Reset();
	vdlChR->Reset();
	*/
}

void CVABinauralOutdoorWaveFront::PreRelease()
{
	delete pMotionModel;
	/* @todo use reset of motion model instead of new / delete in request and release of pool
	motionModel->Reset();
	motionModel->Reset();
	*/
}

void CVABinauralOutdoorWaveFront::GetOutput( ITASampleBuffer* pfLeftChannel, ITASampleBuffer* pfRightChannel )
{
	// Determine ToA difference
	VARelationMetrics sourceMetrics;
	sourceMetrics.calc( m_v3PredictedClusteringPos, m_v3PredictedClusteringView, m_v3PredictedClusteringUp, v3PredictedPos );

	//double toaDistance = sourceMetrics.dist / 343; // TODO: get sound speed from core homogeneous medium

	//double toaSourceChL = _listener->toaEstimator->getTOALeft(sourceMetrics.phi, sourceMetrics.theta);
	//double toSourceaChR = _listener->toaEstimator->getTOARight(sourceMetrics.phi, sourceMetrics.theta);

	// @todo finalize and use TOA estimation
	//		vdlChL->SetDelayTime(std::max(0., toaDistance + toaSourceChL - toaHRTFChL));
	//		vdlChR->SetDelayTime(std::max(0., toaDistance + toaSourceChR - toaHRTFChR));

	// @todo jst: there is something wrong with the following two lines ... toaDistance seems to jump
	//vdlChL->SetDelayTime( toaDistance );
	//vdlChR->SetDelayTime( toaDistance );

henryjandrew's avatar
wip  
henryjandrew committed
76 77 78 79
	iCursorID;
	int iNumSamples;
	//pSource->pVDL->Read( iCursorID, iNumSamples); // take data from VDL to be forwarded to IIR

80 81 82 83 84 85 86 87 88 89 90 91 92 93
	vdlChL->Process( pData->pSignalSourceInputBuf, pfLeftChannel );
	vdlChL->Process( pData->pSignalSourceInputBuf, pfRightChannel );

	float gain = float( ( 1 / sourceMetrics.dist ) * pState->GetVolume( VAConfig::amplitudeCalibration ) );
	pfLeftChannel->mul_scalar( gain );
	pfRightChannel->mul_scalar( gain );
}

void CVABinauralOutdoorWaveFront::SetClusteringPose( const VAVec3& v3Pos, const VAVec3& v3View, const VAVec3& v3Up )
{
	m_v3PredictedClusteringPos = v3Pos;
	m_v3PredictedClusteringView = v3View;
	m_v3PredictedClusteringUp = v3Up;
}
henryjandrew's avatar
wip  
henryjandrew committed
94 95 96 97 98 99


void CVABinauralOutdoorWaveFront::setParameters(const CVAStruct &oInArgs) {


}