Refactoring sample rate and speed of sound, now both float

parent c358907e
......@@ -117,8 +117,8 @@ public:
int N; //!< Number of loudspeakers
int iCTCFilterLength; //!< CTC filter taps, i.e. 4096
double dSampleRate; //!< Sampling rate
float dSpeedOfSound; //!< Speed of sound, m/s
float fSampleRate; //!< Sampling rate
float fSpeedOfSound; //!< Speed of sound, m/s
int iOptimization; //!< Optimization algorithm (future work, see features/room_compensation)
float fCrossTalkCancellationFactor; //!< Factor for cross-talk cancellation (none = 0.0, full = 1.0)
float fWaveIncidenceAngleCompensationFactor; //!< Factor for cross-talk cancellation (none = 0.0, full = 1.0)
......
......@@ -38,15 +38,15 @@ ITANCTC::ITANCTC( const Config& oNCTCConfig )
for( int n = 0; n < GetN(); n++ )
{
m_vdWeights.push_back( 1.0f );
m_vpHRTFs.push_back( new ITAHDFTSpectra( m_oConfig.dSampleRate, 2, iDFTSize, true ) );
m_vfDelayTime.push_back( float( m_oConfig.iCTCFilterLength / m_oConfig.dSampleRate / 2.0f ) );
m_vpHRTFs.push_back( new ITAHDFTSpectra( m_oConfig.fSampleRate, 2, iDFTSize, true ) );
m_vfDelayTime.push_back( float( m_oConfig.iCTCFilterLength ) / m_oConfig.fSampleRate / 2.0f );
}
for( int i = 0; i < 2; i++ )
m_vpHelper2x2.push_back( new ITAHDFTSpectra( m_oConfig.dSampleRate, 2, iDFTSize, true ) );
m_vpHelper2x2.push_back( new ITAHDFTSpectra( m_oConfig.fSampleRate, 2, iDFTSize, true ) );
t = new ITAHDFTSpectrum( m_oConfig.dSampleRate, iDFTSize, true );
det = new ITAHDFTSpectrum( m_oConfig.dSampleRate, iDFTSize, true );
t = new ITAHDFTSpectrum( m_oConfig.fSampleRate, iDFTSize, true );
det = new ITAHDFTSpectrum( m_oConfig.fSampleRate, iDFTSize, true );
int l = m_oConfig.iCTCFilterLength;
m_fft.plan( ITAFFT::FFT_R2C, l, m_sfCTC_temp[ 0 ].data(), ( *m_vpHRTFs[ 0 ] )[ 0 ]->data() );
......@@ -148,7 +148,7 @@ void ITANCTC::AddHRIR( const Pose& oDest, ITASampleFrame& sfDestHRIR, bool& bOut
// Determine offset of target IR subtracting also the minimum distance to all LS
int iHRIRPreOffset = m_pHRIR->getMinEffectiveFilterOffset();
int iHRIRFilerTaps = m_pHRIR->getMaxEffectiveFilterLength();
int iLS2HeadDelaySamples = int( dDistanceMeters / m_oConfig.dSpeedOfSound * m_oConfig.dSampleRate );
int iLS2HeadDelaySamples = int( dDistanceMeters / m_oConfig.fSpeedOfSound * m_oConfig.fSampleRate );
int iOffset = ( std::max )( 0, ( int( iLS2HeadDelaySamples ) - iHRIRPreOffset - iDistanceCompensationSamples ) ); // remove starting zeros from HRIR
// Check against buffer overrun, prevent if necessary and clamp to sweet spot boundary (end of IR)
......@@ -177,7 +177,7 @@ bool ITANCTC::CalculateFilter( std::vector< ITAHDFTSpectra* >& vpCTCFilter )
return false;
float fMinDistance = GetMinimumDistanceHead2LS();
int iMinDistanceCompensationSamples = int( fMinDistance / m_oConfig.dSpeedOfSound * m_oConfig.dSampleRate );
int iMinDistanceCompensationSamples = int( fMinDistance / m_oConfig.fSpeedOfSound * m_oConfig.fSampleRate );
bool bOutOfRange = false;
for( int n = 0; n < GetN(); n++ )
......@@ -325,7 +325,7 @@ bool ITANCTC::CalculateFilter( std::vector< ITAHDFTSpectra* >& vpCTCFilter )
a->add( m_fBeta );
d->add( m_fBeta );
ITAHDFTSpectra abcd( m_oConfig.dSampleRate, 4, m_oConfig.iCTCFilterLength );
ITAHDFTSpectra abcd( m_oConfig.fSampleRate, 4, m_oConfig.iCTCFilterLength );
abcd[ 0 ]->copyFrom( *a );
abcd[ 1 ]->copyFrom( *b );
abcd[ 2 ]->copyFrom( *c );
......@@ -396,7 +396,7 @@ bool ITANCTC::CalculateFilter( std::vector< ITAHDFTSpectra* >& vpCTCFilter )
m_sfCTC_temp.div_scalar( float( m_sfCTC_temp.length() ) );
// Shift the CTC filter according to desired delay
int iShiftSamples = int( m_oConfig.dSampleRate * m_vfDelayTime[ n ] );
int iShiftSamples = int( m_oConfig.fSampleRate * m_vfDelayTime[ n ] );
if( m_vfDelayTime[ n ] < 0.0f )
iShiftSamples = m_sfCTC_temp.length() / 2; // if invalid, shift by half length
sfTargetData_shift.cyclic_write( m_sfCTC_temp, m_sfCTC_temp.length(), 0, iShiftSamples );
......@@ -596,7 +596,7 @@ ITANCTC::Config::Config()
// Set some default values
N = 0;
iCTCFilterLength = 4096;
dSpeedOfSound = 344.0f;
fSpeedOfSound = 344.0f;
iOptimization = OPTIMIZATION_NONE;
fCrossTalkCancellationFactor = 1.0f;
fWaveIncidenceAngleCompensationFactor = 1.0f;
......
......@@ -18,7 +18,7 @@ int main( int, char** )
ITANCTC::Config oNCTCConfig;
oNCTCConfig.iCTCFilterLength = 10000;//2048;
oNCTCConfig.dSampleRate = 44.1e3;
oNCTCConfig.fSampleRate = 44.1e3;
oNCTCConfig.fSpeedOfSound = 344.0f;
//oNCTCConfig.iOptimization = ITANCTC::Config::OPTIMIZATION_NONE;
//oNCTCConfig.iOptimization = ITANCTC::Config::OPTIMIZATION_AIXCAVE_FULLY_CLOSED;
......@@ -98,7 +98,7 @@ int main( int, char** )
std::vector< ITAHDFTSpectra* > vpCTCFilter;
for( int n=0; n<ctc.GetN(); n++ )
vpCTCFilter.push_back( new ITAHDFTSpectra( oNCTCConfig.dSampleRate, 2, oNCTCConfig.iCTCFilterLength+1, true ) );
vpCTCFilter.push_back( new ITAHDFTSpectra( oNCTCConfig.fSampleRate, 2, oNCTCConfig.iCTCFilterLength+1, true ) );
try
{
......
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