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

Fixing headphone reproduction issue #8

parent b2ac3586
......@@ -46,14 +46,32 @@ CVAHeadphonesReproduction::CVAHeadphonesReproduction( const CVAAudioReproduction
CVAConfigInterpreter conf( *(m_oParams.pConfig) );
// Gains
if( oParams.pConfig->HasKey( "HpIRInvCalibrationGain" ) && oParams.pConfig->HasKey( "HpIRInvCalibrationGainDecibel" ) )
VA_EXCEPT2( INVALID_PARAMETER, "HPIRInvCalibrationGain was included in the configuration both as factor and decibel and I can't decide which one is correct." );
double dEqualizationCalibrationGain;
if( oParams.pConfig->HasKey( "HpIRInvCalibrationGainDecibel" ) )
{
double dEqualizationCalibrationGainDecibel;
conf.ReqNumber( "HpIRInvCalibrationGainDecibel", dEqualizationCalibrationGainDecibel );
dEqualizationCalibrationGain = db20_to_ratio( dEqualizationCalibrationGainDecibel );
}
else if( oParams.pConfig->HasKey( "HpIRInvCalibrationGain" ) )
{
conf.ReqNumber( "HpIRInvCalibrationGain", dEqualizationCalibrationGain );
}
else
{
dEqualizationCalibrationGain = 1.0f;
}
// Inverse IR file
std::string sFilePathRaw;
conf.ReqString( "HpIRInvFile", sFilePathRaw );
std::string sFilePath = m_oParams.pCore->GetCoreConfig()->mMacros.SubstituteMacros( sFilePathRaw );
double dEqualizationCalibrationGainDecibel;
conf.ReqNumber( "HpIRInvCalibrationGainDecibel", dEqualizationCalibrationGainDecibel );
m_sfHpIRInv.Load( sFilePath ); // sets length to given number of samples
if( m_sfHpIRInv.channels() != 2 )
......@@ -66,7 +84,6 @@ CVAHeadphonesReproduction::CVAHeadphonesReproduction( const CVAAudioReproduction
VA_WARN( "HPEQ reproduction module", "Filter length of given inverse HPIR file is longer than configured length" );
// Calibrate ( HPTF * HPTFinv == 0dB )
double dEqualizationCalibrationGain = db10_to_ratio( dEqualizationCalibrationGainDecibel );
m_sfHpIRInv.mul_scalar( float( dEqualizationCalibrationGain ) );
double dSampleRate = m_oParams.pCore->GetCoreConfig()->oAudioDriverConfig.dSampleRate;
......@@ -127,7 +144,7 @@ int CVAHeadphonesReproduction::CallObject( const CVAStruct& oArgs, CVAStruct& oR
VA_EXCEPT2( INVALID_PARAMETER, "Unrecognized GET command " + sGetCommand );
}
}
else if( ( pStruct = oArgs.GetValue( "hpirinv" ) ) != nullptr )
else if( ( pStruct = oArgs.GetValue( "HpIRInvFile" ) ) != nullptr )
{
if( pStruct->GetDatatype() != CVAStructValue::STRING )
VA_EXCEPT2( INVALID_PARAMETER, "File path value must be a string" );
......@@ -163,11 +180,13 @@ int CVAHeadphonesReproduction::CallObject( const CVAStruct& oArgs, CVAStruct& oR
if( !m_pHPEQStreamFilter->ExchangeFilter( m_sfHpIRInv ) )
VA_ERROR( GetObjectName(), "Could not exchange filter impulse response, length mismatch" );
if( oArgs.HasKey( "GAIN" ) )
if( oArgs.HasKey( "HPIRInvCalibrationGain" ) && oArgs.HasKey( "HPIRInvCalibrationGainDecibel" ) )
VA_EXCEPT2( INVALID_PARAMETER, "HPIRInvCalibrationGain was passed both as factor and decibel and I can't decide which one is correct." );
if( oArgs.HasKey( "HPIRInvCalibrationGain" ) )
{
const CVAStructValue* pGainValue = oArgs.GetValue( "GAIN" );
const CVAStructValue* pGainValue = oArgs.GetValue( "HPIRInvCalibrationGain" );
if( pGainValue != nullptr )
{
if( pGainValue->IsNumeric() == false )
......@@ -176,26 +195,45 @@ int CVAHeadphonesReproduction::CallObject( const CVAStruct& oArgs, CVAStruct& oR
double dGain = double( *pGainValue );
m_pHPEQStreamFilter->fGain = float( dGain );
oReturn["Return"] = true; // dummy return value, otherwise Problem with MATLAB
oReturn[ "HPIRInvCalibrationGain" ] = dGain;
oReturn[ "HPIRInvCalibrationGainDecibel" ] = ratio_to_db20( dGain );
return 1;
}
}
if( oArgs.HasKey( "HPIRInvCalibrationGainDebicel" ) )
{
const CVAStructValue* pGainValue = oArgs.GetValue( "HPIRInvCalibrationGainDebicel" );
if( pGainValue != nullptr )
{
if( pGainValue->IsNumeric() == false )
VA_EXCEPT2( INVALID_PARAMETER, "Gain value must be numerical" );
double dGainDecibel = double( *pGainValue );
m_pHPEQStreamFilter->fGain = float( db20_to_ratio( dGainDecibel ) );
oReturn[ "HPIRInvCalibrationGain" ] = db20_to_ratio( dGainDecibel );
oReturn[ "HPIRInvCalibrationGainDecibel" ] = dGainDecibel;
return 1;
}
else
{
VA_EXCEPT2( INVALID_PARAMETER, "Gain value missing" );
}
}
oReturn["Return"] = true; // dummy return value, otherwise Problem with MATLAB
oReturn["hpirinv"] = "updated"; // dummy return value, otherwise Problem with MATLAB
return 1;
}
else
{
VA_EXCEPT2( INVALID_PARAMETER, "Unrecognized SET value, use 'print' 'help' for further information" );
}
}
else
{
VA_EXCEPT2( INVALID_PARAMETER, "Unrecognized command called, use 'PRINT' 'HELP' for more information" );
}
return -1;
}
void CVAHeadphonesReproduction::SetInputDatasource( ITADatasource* p )
......
......@@ -30,8 +30,8 @@ public:
ITADatasource* GetOutputDatasource();
int GetNumInputChannels() const;
void SetTrackedListener( const int iListenerID ) {};
void UpdateScene( CVASceneState* pNewState ) {};
inline void SetTrackedListener( const int ) {};
inline void UpdateScene( CVASceneState* ) {};
CVAObjectInfo GetObjectInfo() const;
int CallObject( const CVAStruct& oArgs, CVAStruct& oReturn );
......
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