Commit f0cffea9 authored by Dipl.-Ing. Jonas Stienen's avatar Dipl.-Ing. Jonas Stienen
Browse files

NCTC module interface debug stuff

parent 5f0d5de5
......@@ -26,23 +26,23 @@
CVANCTCReproduction::CVANCTCReproduction( const CVAAudioReproductionModuleInitParams& oParams )
: CVAObject( oParams.sClass + ":" + oParams.sID )
, m_oParams( oParams )
, m_pdsStreamFilter( NULL )
, m_iListenerID( -1 )
, m_dGain( 1.0f )
, m_bTrackedListenerHRIR( false )
, m_pDefaultHRIR( NULL )
, m_oParams( oParams )
, m_pdsStreamFilter( NULL )
, m_iListenerID( -1 )
, m_dGain( 1.0f )
, m_bTrackedListenerHRIR( false )
, m_pDefaultHRIR( NULL )
{
m_oParams.pCore->RegisterModule( this );
CVAConfigInterpreter conf( *(m_oParams.pConfig) );
CVAConfigInterpreter conf( *( m_oParams.pConfig ) );
conf.OptInteger( "TrackedListenerID", m_iListenerID, 1 );
// Validate outputs
if( m_oParams.vpOutputs.size() != 1 )
VA_EXCEPT2( INVALID_PARAMETER, "Only one output target per NCTC reproduction instance allowed" );
// NCTC configuration
ITANCTC::Config oNCTCConf;
conf.OptInteger( "CTCFilterLength", oNCTCConf.iCTCFilterLength, 4096 );
......@@ -55,15 +55,15 @@ CVANCTCReproduction::CVANCTCReproduction( const CVAAudioReproductionModuleInitPa
conf.OptString( "Optimization", sOptimization );
// ...
oNCTCConf.iOptimization = ITANCTC::Config::OPTIMIZATION_NONE;
oNCTCConf.N = int( m_oParams.vpOutputs[0]->GetPhysicalOutputChannels().size() );
oNCTCConf.N = int( m_oParams.vpOutputs[ 0 ]->GetPhysicalOutputChannels().size() );
// Loudspeaker
oNCTCConf.voLoudspeaker.resize( oNCTCConf.N );
for( int i=0; i<oNCTCConf.N; i++ )
for( int i = 0; i < oNCTCConf.N; i++ )
{
ITANCTC::Config::Loudspeaker& oLS( oNCTCConf.voLoudspeaker[i] );
const CVAHardwareDevice* pLSOut( m_oParams.vpOutputs[0]->vpDevices[i] );
ITANCTC::Config::Loudspeaker& oLS( oNCTCConf.voLoudspeaker[ i ] );
const CVAHardwareDevice* pLSOut( m_oParams.vpOutputs[ 0 ]->vpDevices[ i ] );
oLS.oPose.vPos.SetValues( pLSOut->vPos.x, pLSOut->vPos.y, pLSOut->vPos.z );
//oLS.oPose.qOrient.SetToNeutralQuaternion();
oLS.oPose.SetOrientationYPRdeg( pLSOut->oOrientYPRDegree.yaw, pLSOut->oOrientYPRDegree.pitch, pLSOut->oOrientYPRDegree.roll );
......@@ -76,7 +76,7 @@ CVANCTCReproduction::CVANCTCReproduction( const CVAAudioReproductionModuleInitPa
if( pReader->openFile( correctPath( sDataFilePath ) ) == 0 )
{
DAFFContentDFT* pLSEQ = dynamic_cast< DAFFContentDFT* >( pReader->getContent() );
if( pLSEQ == nullptr )
VA_EXCEPT2( INVALID_PARAMETER, "Could not read DAFF content of loudspeaker " + pLSOut->sIdentifier );
......@@ -91,7 +91,7 @@ CVANCTCReproduction::CVANCTCReproduction( const CVAAudioReproductionModuleInitPa
}
}
m_vpSpectra.push_back( new ITAHDFTSpectra( oNCTCConf.fSampleRate, 2, oNCTCConf.iCTCFilterLength+1, true ) );
m_vpSpectra.push_back( new ITAHDFTSpectra( oNCTCConf.fSampleRate, 2, oNCTCConf.iCTCFilterLength + 1, true ) );
}
#ifdef VACORE_REPRODUCTION_NCTC_WITH_SWEET_SPOT_WIDENING
......@@ -102,13 +102,13 @@ CVANCTCReproduction::CVANCTCReproduction( const CVAAudioReproductionModuleInitPa
conf.OptNumber( "WaveIncidenceAngleCompensationFactor", dWaveIncidenceAngleCompensationFactor, 1.0f );
oNCTCConf.fWaveIncidenceAngleCompensationFactor = float( dWaveIncidenceAngleCompensationFactor );
#endif
// Create NCTC instance
m_pNCTC = new ITANCTC( oNCTCConf );
double dBeta;
conf.OptNumber( "RegularizationBeta", dBeta, 0.001f );
m_pNCTC->SetBeta( float( dBeta ) );
oNCTCConf.fRegularizationFactor = float( dBeta );
// Create NCTC instance
m_pNCTC = new ITANCTC( oNCTCConf );
int iDelaySamples;
conf.OptInteger( "DelaySamples", iDelaySamples, oNCTCConf.iCTCFilterLength / 2 );
......@@ -116,7 +116,7 @@ CVANCTCReproduction::CVANCTCReproduction( const CVAAudioReproductionModuleInitPa
// NCTC Stream filter
ITANCTCStreamFilter::Config oNCTCStreamConf;
oNCTCStreamConf.N = m_pNCTC->GetN();
oNCTCStreamConf.N = m_pNCTC->GetNumChannels();
oNCTCStreamConf.dSampleRate = m_oParams.pCore->GetCoreConfig()->oAudioDriverConfig.dSampleRate;
oNCTCStreamConf.iBlockLength = m_oParams.pCore->GetCoreConfig()->oAudioDriverConfig.iBuffersize;
oNCTCStreamConf.iFilterLength = oNCTCConf.iCTCFilterLength;
......@@ -125,20 +125,19 @@ CVANCTCReproduction::CVANCTCReproduction( const CVAAudioReproductionModuleInitPa
conf.OptInteger( "CTCFilterExchangeMode", oNCTCStreamConf.iFilterExchangeMode, ITAUPConvolution::CROSSFADE_COSINE_SQUARE );
conf.OptBool( "UseTrackedListenerHRIR", m_bTrackedListenerHRIR, false );
std::string sCTCDefaultHRIR_raw;
bool bEntryPresent = conf.OptString( "CTCDefaultHRIR", sCTCDefaultHRIR_raw );
std::string sCTCDefaultHRIR = m_oParams.pCore->FindFilePath( sCTCDefaultHRIR_raw );
if( bEntryPresent && sCTCDefaultHRIR.empty() && !m_bTrackedListenerHRIR )
VA_EXCEPT2(INVALID_PARAMETER, "Could not find default HRIR file for NCTC reproduction module. Switch to tracked listener HRIR or specify correct path.")
VA_EXCEPT2( INVALID_PARAMETER, "Could not find default HRIR file for NCTC reproduction module. Switch to tracked listener HRIR or specify correct path." )
double dSampleRate = m_oParams.pCore->GetCoreConfig()->oAudioDriverConfig.dSampleRate;
double dSampleRate = m_oParams.pCore->GetCoreConfig()->oAudioDriverConfig.dSampleRate;
if( sCTCDefaultHRIR.empty() == false )
m_pDefaultHRIR = new CVAHRIRDatasetDAFF2D( sCTCDefaultHRIR, "CTCDefaultHRIR", dSampleRate );
m_pdsStreamFilter = new ITANCTCStreamFilter( oNCTCStreamConf );
return;
}
......@@ -148,11 +147,11 @@ CVANCTCReproduction::~CVANCTCReproduction()
m_pdsStreamFilter = NULL;
for( int i=0; i<m_pNCTC->GetN(); i++ )
for( int i = 0; i < m_pNCTC->GetNumChannels(); i++ )
{
delete m_vpSpectra[i];
delete m_vpSpectra[ i ];
const ITANCTC::Config::Loudspeaker& oLS( m_pNCTC->GetConfig().voLoudspeaker[i] );
const ITANCTC::Config::Loudspeaker& oLS( m_pNCTC->GetConfig().voLoudspeaker[ i ] );
if( oLS.pDirectivity != nullptr )
delete oLS.pDirectivity->getParent();
}
......@@ -180,11 +179,23 @@ int CVANCTCReproduction::CallObject( const CVAStruct& oArgs, CVAStruct& oReturn
const CVAStructValue* pStruct;
if( oArgs.HasKey( "debug" ) )
{
const CVAStruct& oDebugArgs( oArgs[ "debug" ] );
if( oDebugArgs.HasKey( "export_ctc_filters" ) )
{
if( oDebugArgs[ "export_ctc_filters" ].IsNumeric() )
m_iDebugExportCTCFilters = oDebugArgs[ "export_ctc_filters" ];
if( oDebugArgs.HasKey( "export_ctc_filters_base_name" ) )
m_sDebugExportCTCFiltersBaseName = oDebugArgs[ "export_ctc_filters_base_name" ];
}
}
// Commands: print, get, set
if( ( pStruct = oArgs.GetValue( "print" ) ) != nullptr )
{
VA_PRINT( "Available commands for " +CVAObject::GetObjectName()+ ": print, set, get" );
VA_PRINT( "Available commands for " + CVAObject::GetObjectName() + ": print, set, get" );
VA_PRINT( "PRINT:" );
VA_PRINT( "\t'print', 'help'" );
VA_PRINT( "GET:" );
......@@ -192,10 +203,10 @@ int CVANCTCReproduction::CallObject( const CVAStruct& oArgs, CVAStruct& oReturn
VA_PRINT( "SET:" );
VA_PRINT( "\t'set', 'gain', 'value', <number>" );
oReturn["Return"] = true; // dummy return value, otherwise Problem with MATLAB
oReturn[ "Return" ] = true; // dummy return value, otherwise Problem with MATLAB
return 1;
}
if( ( pStruct = oArgs.GetValue( "get" ) ) != nullptr )
{
if( pStruct->GetDatatype() != CVAStructValue::STRING )
......@@ -204,7 +215,7 @@ int CVANCTCReproduction::CallObject( const CVAStruct& oArgs, CVAStruct& oReturn
if( sGetCommand == "gain" )
{
oReturn["gain"] = m_dGain;
oReturn[ "gain" ] = m_dGain;
return 1;
}
else
......@@ -219,8 +230,8 @@ int CVANCTCReproduction::CallObject( const CVAStruct& oArgs, CVAStruct& oReturn
VA_EXCEPT2( INVALID_PARAMETER, "Gain value must be numerical" );
m_dGain = *pStruct;
std::vector< float > vfGains( m_pNCTC->GetN() );
for( int n = 0; n < m_pNCTC->GetN(); n++ )
std::vector< float > vfGains( m_pNCTC->GetNumChannels() );
for( int n = 0; n < m_pNCTC->GetNumChannels(); n++ )
vfGains[ n ] = float( m_dGain );
m_pdsStreamFilter->SetGains( vfGains );
return 0;
......@@ -231,12 +242,12 @@ int CVANCTCReproduction::CallObject( const CVAStruct& oArgs, CVAStruct& oReturn
if( pStruct->GetDatatype() != CVAStructValue::DATA )
VA_EXCEPT2( INVALID_PARAMETER, "Delay must be a vector of numeric values" );
if( pStruct->GetDataSize() != m_pNCTC->GetN() * sizeof( float ) )
if( pStruct->GetDataSize() != m_pNCTC->GetNumChannels() * sizeof( float ) )
VA_EXCEPT2( INVALID_PARAMETER, "Dimension mismatch, N delay values required" );
const float* pfAdditionalDelayData = ( const float* ) ( pStruct->GetData() );
std::vector< float > vfDelayTime = m_pNCTC->GetDelayTime();
for( int n = 0; n < m_pNCTC->GetN(); n++ )
for( int n = 0; n < m_pNCTC->GetNumChannels(); n++ )
vfDelayTime[ n ] += pfAdditionalDelayData[ n ];
m_pNCTC->SetDelayTime( vfDelayTime );
......@@ -247,14 +258,14 @@ int CVANCTCReproduction::CallObject( const CVAStruct& oArgs, CVAStruct& oReturn
{
if( pStruct->GetDatatype() != CVAStructValue::STRING )
VA_EXCEPT2( INVALID_PARAMETER, "Export base name must be a string" );
std::string sExportFileBaseName = *pStruct;
if( sExportFileBaseName.empty() )
sExportFileBaseName = "VANCTC_CTCFilter_";
for( size_t n = 0; n < m_vpSpectra.size(); n++ )
ITAFFTUtils::Export( m_vpSpectra[ n ], sExportFileBaseName + IntToString( int( n + 1 ) ) );
return 0;
}
......@@ -262,7 +273,7 @@ int CVANCTCReproduction::CallObject( const CVAStruct& oArgs, CVAStruct& oReturn
{
if( pStruct->GetDatatype() != CVAStructValue::STRING )
VA_EXCEPT2( INVALID_PARAMETER, "Export base name must be a string" );
std::string sExportFileBaseName = *pStruct;
if( sExportFileBaseName.empty() )
sExportFileBaseName = "VANCTC_HRIR_";
......@@ -283,7 +294,7 @@ int CVANCTCReproduction::CallObject( const CVAStruct& oArgs, CVAStruct& oReturn
VA_EXCEPT2( INVALID_PARAMETER, "CrossTalkCancellationFactor value must be numerical" );
m_pNCTC->SetCrossTalkCancellationFactor( float( double( *pStruct ) ) );
// Force update
m_pNCTC->CalculateFilter( m_vpSpectra );
m_pdsStreamFilter->ExchangeFilters( m_vpSpectra );
......@@ -332,7 +343,7 @@ void CVANCTCReproduction::SetTrackedListener( int iID )
void CVANCTCReproduction::UpdateScene( CVASceneState* pNewState )
{
if( m_iListenerID == -1 )
if( m_iListenerID == -1 )
return;
CVAListenerState* pListenerState( pNewState->GetListenerState( m_iListenerID ) );
......@@ -356,9 +367,9 @@ void CVANCTCReproduction::UpdateScene( CVASceneState* pNewState )
m_pNCTC->SetHRIR( m_pDefaultHRIR->GetDAFFContent() );
}
double x,y,z, vx, vy, vz, ux, uy, uz;
m_oParams.pCore->GetListenerRealWorldHeadPositionOrientationVU( m_iListenerID, x,y,z, vx,vy,vz, ux,uy,uz );
double x, y, z, vx, vy, vz, ux, uy, uz;
m_oParams.pCore->GetListenerRealWorldHeadPositionOrientationVU( m_iListenerID, x, y, z, vx, vy, vz, ux, uy, uz );
ITANCTC::Pose oHeadPose;
oHeadPose.vPos.SetValues( x, y, z );
/* @todo jst
......@@ -372,8 +383,19 @@ void CVANCTCReproduction::UpdateScene( CVASceneState* pNewState )
m_pNCTC->UpdateHeadPose( oHeadPose );
m_pNCTC->CalculateFilter( m_vpSpectra );
if( m_iDebugExportCTCFilters > 0 )
{
m_iDebugExportCTCFilters--;
if( m_sDebugExportCTCFiltersBaseName.empty() )
m_sDebugExportCTCFiltersBaseName = "VANCTC_" + GetObjectName() + "_CTCFilter_";
for( size_t n = 0; n < m_vpSpectra.size(); n++ )
ITAFFTUtils::Export( m_vpSpectra[ n ], m_sDebugExportCTCFiltersBaseName + IntToString( int( n + 1 ) ) );
}
m_pdsStreamFilter->ExchangeFilters( m_vpSpectra );
return;
}
......
......@@ -57,6 +57,9 @@ private:
ITANCTCStreamFilter* m_pdsStreamFilter;
std::vector< ITAHDFTSpectra* > m_vpSpectra;
double m_dGain;
mutable int m_iDebugExportCTCFilters; //! Exports given number of filters during streaming
mutable std::string m_sDebugExportCTCFiltersBaseName; //! Export file base name
};
#endif // ( VACORE_WITH_REPRODUCTION_BINAURAL_NCTC == 1 )
......
Supports Markdown
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