Intermediate

parent fc7fb574
......@@ -19,6 +19,10 @@
#include "../BinauralTimeOfArrivalEstimator/VABinauralTOAEstimator.h"
CVABinauralClusteringDirection::CVABinauralClusteringDirection()
: m_iLastHRIRIndex( -1 )
, m_pClusteringDirectionReceiver( NULL )
, m_pFIRConvolverChL( NULL )
, m_pFIRConvolverChR( NULL )
{
m_psfOutput = new ITASampleFrame( 2, VAConfig::blockLength, true );
m_psfTempHRIR = new ITASampleFrame( 2, VAConfig::hrirLength, true );
......@@ -27,24 +31,24 @@ CVABinauralClusteringDirection::CVABinauralClusteringDirection()
CVABinauralClusteringDirection::~CVABinauralClusteringDirection()
{}
void CVABinauralClusteringDirection::Init( int iID, CVABinauralWaveFrontBase* pWaveFront, CVABinauralClusteringDirectionReceiver* listener, ITAUPConvolution* firL, ITAUPConvolution* firR )
void CVABinauralClusteringDirection::Init( int iID, CVABinauralWaveFrontBase* pWaveFront, CVABinauralClusteringDirectionReceiver* pReceiver, ITAUPConvolution* pFIRConvolverChL, ITAUPConvolution* pFIRConvolverChR )
{
m_pClusteringDirectionReceiver = listener;
v3ClusteringDirectionPos = pWaveFront->v3PredictedPos - listener->v3PredictedPosition;
m_pClusteringDirectionReceiver = pReceiver;
v3ClusteringDirectionPos = pWaveFront->v3PredictedPos - pReceiver->v3PredictedPosition;
v3ClusteringDirectionPos.Norm();
m_pFIRConvolverChL = firL;
m_pFIRConvolverChR = firR;
m_pFIRConvolverChL = pFIRConvolverChL;
m_pFIRConvolverChR = pFIRConvolverChR;
int outputLength = listener->pOutput->GetLength();
int iOutputLength = pReceiver->pOutput->GetLength();
if( m_psfOutput->length() != outputLength )
m_psfOutput->init( 2, outputLength, true );
if( m_psfOutput->length() != iOutputLength )
m_psfOutput->init( 2, iOutputLength, true );
if( m_sbTempChL.length() != outputLength )
if( m_sbTempChL.length() != iOutputLength || m_sbTempChR.length() != iOutputLength )
{
m_sbTempChL.Init( outputLength, true );
m_sbTempChR.Init( outputLength, true );
m_sbTempChL.Init( iOutputLength, true );
m_sbTempChR.Init( iOutputLength, true );
}
dMaxError = GetDistError( pWaveFront );
......@@ -62,10 +66,10 @@ void CVABinauralClusteringDirection::Init( CVABinauralClusteringDirection* pClus
m_pClusteringDirectionReceiver = pClusterDirection->m_pClusteringDirectionReceiver;
v3ClusteringDirectionPos = pClusterDirection->v3ClusteringDirectionPos;
int outputLength = m_pClusteringDirectionReceiver->pOutput->GetLength();
const int iOutputLength = m_pClusteringDirectionReceiver->pOutput->GetLength();
if( m_psfOutput->length() != outputLength )
m_psfOutput->init( 2, outputLength, true );
if( m_psfOutput->length() != iOutputLength )
m_psfOutput->init( 2, iOutputLength, true );
m_sbTempChL.Init( m_pClusteringDirectionReceiver->pOutput->GetLength(), true );
m_sbTempChR.Init( m_pClusteringDirectionReceiver->pOutput->GetLength(), true );
......@@ -81,8 +85,8 @@ ITASampleFrame* CVABinauralClusteringDirection::GetOutput()
m_psfOutput->zero();
// Get time-of-arrival for this clustering direction
VARelationMetrics clusterSourceMetrics;
clusterSourceMetrics.calc( m_pClusteringDirectionReceiver->v3PredictedPosition, m_pClusteringDirectionReceiver->predView, m_pClusteringDirectionReceiver->predUp, m_pClusteringDirectionReceiver->v3PredictedPosition + v3ClusteringDirectionPos );
VARelationMetrics oClusterSourceMetrics;
oClusterSourceMetrics.calc( m_pClusteringDirectionReceiver->v3PredictedPosition, m_pClusteringDirectionReceiver->predView, m_pClusteringDirectionReceiver->predUp, m_pClusteringDirectionReceiver->v3PredictedPosition + v3ClusteringDirectionPos );
// double toaHRTFChL = _listener->toaEstimator->getTOALeft(clusterSourceMetrics.phi, clusterSourceMetrics.theta);
// double toaHRTFChR = _listener->toaEstimator->getTOARight(clusterSourceMetrics.phi, clusterSourceMetrics.theta);
......@@ -96,53 +100,50 @@ ITASampleFrame* CVABinauralClusteringDirection::GetOutput()
for( it = m_mWaveFronts.begin(); it != m_mWaveFronts.end(); ++it )
{
CVABinauralWaveFrontBase* pWaveFront( it->second );
const ITASampleBuffer* psbInput = pWaveFront->GetInput();
pWaveFront->SetClusteringPose( m_pClusteringDirectionReceiver->v3PredictedPosition, m_pClusteringDirectionReceiver->predView, m_pClusteringDirectionReceiver->predUp );
pWaveFront->Process( psbInput, &( m_sbTempChL ), &( m_sbTempChR ) );
pWaveFront->GetOutput( &( m_sbTempChL ), &( m_sbTempChR ) );
( *m_psfOutput )[ 0 ] += m_sbTempChL;
( *m_psfOutput )[ 1 ] += m_sbTempChR;
}
// convolve here!
CVADirectivityDAFFHRIR* HRIR = ( CVADirectivityDAFFHRIR * ) m_pClusteringDirectionReceiver->pDirectivity;
ITAUPFilter* HRIRFilterChL = m_pFIRConvolverChL->GetFilterPool()->RequestFilter();
ITAUPFilter* HRIRFilterChR = m_pFIRConvolverChR->GetFilterPool()->RequestFilter();
HRIRFilterChL->Zeros();
HRIRFilterChR->Zeros();
if( HRIR )
// Convolution of HRIR
CVADirectivityDAFFHRIR* pHRIR = ( CVADirectivityDAFFHRIR* ) m_pClusteringDirectionReceiver->pDirectivity;
if( pHRIR )
{
int index = -1;
int filterLength = 0;
const int iHRIRFilterLength = pHRIR->GetProperties()->iFilterLength;
if( m_psfTempHRIR->GetLength() != iHRIRFilterLength )
m_psfTempHRIR->Init( 2, iHRIRFilterLength, false );
filterLength = HRIR->GetProperties()->iFilterLength;
float fAzimuthDeg = oClusterSourceMetrics.phi * 180 / ITAConstants::PI_F;
float fElevationDeg = oClusterSourceMetrics.theta * 180 / ITAConstants::PI_F;
float fDistance = oClusterSourceMetrics.dist;
// @todo remove, because getHRIR will override sample frame values!
m_psfTempHRIR->init( 2, filterLength, true );
int iIndex;
pHRIR->GetNearestNeighbour( fAzimuthDeg, fElevationDeg, &iIndex );
if( m_psfTempHRIR->length() != filterLength )
if( m_iLastHRIRIndex != iIndex )
{
m_psfTempHRIR->init( 2, filterLength, false );
}
pHRIR->GetHRIRByIndex( m_psfTempHRIR, iIndex, fDistance );
float phi = clusterSourceMetrics.phi * 180 / ITAConstants::PI_F;
float theta = clusterSourceMetrics.theta * 180 / ITAConstants::PI_F;
ITAUPFilter* pHRIRFilterChL = m_pFIRConvolverChL->GetFilterPool()->RequestFilter();
ITAUPFilter* pHRIRFilterChR = m_pFIRConvolverChR->GetFilterPool()->RequestFilter();
// @todo use index getter, compare with last index and only exchange if necessary
// HRIR->GetHRIRByIndex()
HRIR->GetHRIR( m_psfTempHRIR, clusterSourceMetrics.phi * 180 / ITAConstants::PI_F, clusterSourceMetrics.theta * 180 / ITAConstants::PI_F, clusterSourceMetrics.dist );
pHRIRFilterChL->Zeros();
pHRIRFilterChR->Zeros();
HRIRFilterChL->Load( ( *m_psfTempHRIR )[ 0 ].data(), filterLength );
HRIRFilterChR->Load( ( *m_psfTempHRIR )[ 1 ].data(), filterLength );
pHRIRFilterChL->Load( ( *m_psfTempHRIR )[ 0 ].data(), iHRIRFilterLength );
pHRIRFilterChR->Load( ( *m_psfTempHRIR )[ 1 ].data(), iHRIRFilterLength );
m_pFIRConvolverChL->ExchangeFilter( HRIRFilterChL );
m_pFIRConvolverChR->ExchangeFilter( HRIRFilterChR );
m_pFIRConvolverChL->ReleaseFilter( HRIRFilterChL );
m_pFIRConvolverChR->ReleaseFilter( HRIRFilterChR );
m_pFIRConvolverChL->ExchangeFilter( pHRIRFilterChL );
m_pFIRConvolverChR->ExchangeFilter( pHRIRFilterChR );
m_pFIRConvolverChL->ReleaseFilter( pHRIRFilterChL );
m_pFIRConvolverChR->ReleaseFilter( pHRIRFilterChR );
}
m_pFIRConvolverChL->Process( ( *m_psfOutput )[ 0 ].data(), ( *m_psfOutput )[ 0 ].data(), ITABase::MixingMethod::OVERWRITE );
m_pFIRConvolverChR->Process( ( *m_psfOutput )[ 1 ].data(), ( *m_psfOutput )[ 1 ].data(), ITABase::MixingMethod::OVERWRITE );
......
......@@ -44,6 +44,7 @@ private:
ITASampleBuffer m_sbTempChR;
ITASampleFrame* m_psfOutput;
ITASampleFrame* m_psfTempHRIR;
CVABinauralClusteringDirectionReceiver* m_pClusteringDirectionReceiver;
......@@ -57,6 +58,8 @@ private:
std::map< int, CVABinauralWaveFrontBase* > m_mWaveFronts;
int m_iLastHRIRIndex;
double CummulativeMovingAverage( int n, double average, double value );
};
......
......@@ -48,7 +48,7 @@ void CVABinauralWaveFrontBase::PreRelease()
*/
}
void CVABinauralWaveFrontBase::Process( const ITASampleBuffer*, ITASampleBuffer* pfLeftChannel, ITASampleBuffer* pfRightChannel )
void CVABinauralWaveFrontBase::GetOutput( ITASampleBuffer* pfLeftChannel, ITASampleBuffer* pfRightChannel )
{
// Determine ToA difference
VARelationMetrics sourceMetrics;
......@@ -67,19 +67,14 @@ void CVABinauralWaveFrontBase::Process( const ITASampleBuffer*, ITASampleBuffer*
//vdlChL->SetDelayTime( toaDistance );
//vdlChR->SetDelayTime( toaDistance );
vdlChL->Process( GetInput(), pfLeftChannel );
vdlChL->Process( GetInput(), pfRightChannel );
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 );
}
const ITASampleBuffer* CVABinauralWaveFrontBase::GetInput()
{
return pData->pSignalSourceInputBuf;
}
void CVABinauralWaveFrontBase::SetClusteringPose( const VAVec3& v3Pos, const VAVec3& v3View, const VAVec3& v3Up )
{
m_v3PredictedClusteringPos = v3Pos;
......
......@@ -60,8 +60,7 @@ public:
void PreRequest();
void PreRelease();
virtual void Process( const ITASampleBuffer*, ITASampleBuffer* pfLeftChannel, ITASampleBuffer* pfRightChannel );
virtual const ITASampleBuffer* GetInput();
virtual void GetOutput( ITASampleBuffer* pfLeftChannel, ITASampleBuffer* pfRightChannel );
void SetClusteringPose( const VAVec3& v3Pos, const VAVec3& v3View, const VAVec3& v3Up );
......
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