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

Fixing issues with unequal filter generator, filter taps length and blocklength

parent 8720a287
......@@ -45,9 +45,9 @@ public:
private:
int m_iBlocklength;
int m_iConvolutionFilterLength;
int m_iConvolutionTaps;
int m_iGeneratorFilterLength;
std::vector< float > m_vfFilter;
std::vector< float > m_vfGeneratedFIR;
CITAThirdOctaveFIRFilterGenerator* m_pGenerator;
ITAUPConvolution* m_pConvolver;
};
......
......@@ -24,16 +24,15 @@
CITAThirdOctaveFilterbankFIR::CITAThirdOctaveFilterbankFIR( const double dSampleRate, const int iBlockLength )
: m_pGenerator( nullptr )
, m_pConvolver( nullptr )
, m_iBlocklength( iBlockLength )
{
m_iBlocklength = iBlockLength;
// [fwe] Hier wird die Filterlnge fr Directivities festgelegt, jst: dont take too short lengths as the spline interp requires zero DC offset and will cut low freq amplitudes
m_iGeneratorFilterLength = int( 4 * ceil( dSampleRate / ITABase::CThirdOctaveMagnitudeSpectrum::GetCenterFrequencies()[ 0 ] ) );
m_vfFilter.resize( m_iGeneratorFilterLength );
m_vfGeneratedFIR.resize( m_iGeneratorFilterLength );
m_pGenerator = new CITAThirdOctaveFIRFilterGenerator( dSampleRate, m_iGeneratorFilterLength );
m_iConvolutionFilterLength = ( std::max )( 128, iBlockLength );
m_pConvolver = new ITAUPConvolution( iBlockLength, m_iConvolutionFilterLength );
m_iConvolutionTaps = ( std::max )( 128, iBlockLength );
m_pConvolver = new ITAUPConvolution( iBlockLength, m_iConvolutionTaps );
m_pConvolver->SetFilterExchangeFadingFunction( ITABase::FadingFunction::COSINE_SQUARE );
m_pConvolver->SetFilterCrossfadeLength( 32 );
......@@ -48,24 +47,36 @@ CITAThirdOctaveFilterbankFIR::~CITAThirdOctaveFilterbankFIR()
void CITAThirdOctaveFilterbankFIR::SetIdentity( const bool bSmoothChangeover /*=true*/ )
{
ITAUPFilter* pFilter = m_pConvolver->RequestFilter();
int iLatency = m_pGenerator->GetLatency();
assert( iLatency < m_iGeneratorFilterLength );
fm_zero( &m_vfFilter[ 0 ], m_vfFilter.size() );
m_vfFilter[ iLatency ] = 1;
pFilter->Load( &m_vfFilter[ 0 ], ( std::min )( m_iGeneratorFilterLength, m_iConvolutionFilterLength ) );
if( iLatency > m_iGeneratorFilterLength )
ITA_EXCEPT_INVALID_PARAMETER( "Latency exceeds filter length in FIR filterbank identity setter" );
// Set a dirac with given latency
fm_zero( &m_vfGeneratedFIR[ 0 ], m_iGeneratorFilterLength );
m_vfGeneratedFIR[ iLatency ] = 1;
// Window (with rect), if convolution filter is shorter than generated filter
int iShift = std::max( 0, iLatency - m_iConvolutionTaps / 2 );
int iLength = std::min( m_iConvolutionTaps, m_iGeneratorFilterLength - iShift );
ITAUPFilter* pFilter = m_pConvolver->RequestFilter();
pFilter->Load( &m_vfGeneratedFIR[ iShift ], iLength );
m_pConvolver->ExchangeFilter( pFilter, ( bSmoothChangeover ? ITABase::FadingFunction::COSINE_SQUARE : ITABase::FadingFunction::SWITCH ) );
pFilter->Release(); // Auto-release
}
void CITAThirdOctaveFilterbankFIR::SetMagnitudes( const ITABase::CThirdOctaveGainMagnitudeSpectrum& oMags, const bool bSmoothChangeover /*= true*/ )
{
m_pGenerator->GenerateFilter( oMags, &m_vfFilter[0], false );
m_pGenerator->GenerateFilter( oMags, &m_vfGeneratedFIR[ 0 ], false );
int iRange = ( std::min )( m_iGeneratorFilterLength, m_iConvolutionTaps );
int iShift = std::max( 0, m_pGenerator->GetLatency() - iRange / 2 );
int iLength = std::min( m_iConvolutionTaps, m_iGeneratorFilterLength - iShift );
ITAUPFilter* pFilter = m_pConvolver->RequestFilter();
int iRange = ( std::min )( m_iGeneratorFilterLength, m_iConvolutionFilterLength );
int iShift = m_pGenerator->GetLatency() - iRange / 2;
assert( iShift > 0 && iShift + iRange < m_iGeneratorFilterLength );
pFilter->Load( &m_vfFilter[ iShift ], iRange );
pFilter->Load( &m_vfGeneratedFIR[ iShift ], iLength );
m_pConvolver->ExchangeFilter( pFilter, ( bSmoothChangeover ? ITABase::FadingFunction::COSINE_SQUARE : ITABase::FadingFunction::SWITCH ) );
pFilter->Release(); // Auto-release
}
......
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