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

WIP looking for IIR filter bank issue

parent 779c0266
......@@ -20,7 +20,6 @@
#define IW_ITA_BIQUAD
#include <ITADSPDefinitions.h>
#include <vector>
//! Implements digital biquad component for IIR filtering
/**
......@@ -48,6 +47,14 @@ public:
float a2; //!< Numerator 3
CParams();
//! Set parameter old school
/**
* @param[in] Filter parameters coefficients in order: g, b0, b1, b2, a1, a2
*
* @note Double check order.
*/
void SetParameters( const float params[] );
} oParams;
CITABiquad();
......@@ -100,7 +107,7 @@ public:
void Process( const float* pfInputData, float* pfOutputData, const int iNumSamples, const float fOutputGain1, const float fOutputGain2, const int iOutputMode );
private:
std::vector< float > m_vfAccumulators; //!< Accumulators
float z[ 2 ]; //!< Accumulators
};
#endif // IW_ITA_BIQUAD
......@@ -9,8 +9,7 @@ CITABiquad::CITABiquad()
void CITABiquad::ClearAccumulators()
{
m_vfAccumulators.push_back( 0.0f );
m_vfAccumulators.push_back( 0.0f );
z[ 0 ] = z[ 1 ] = 0;
}
void CITABiquad::Process( const float* pfInputData, float* pfOutputData, const int iNumSamples )
......@@ -19,8 +18,8 @@ void CITABiquad::Process( const float* pfInputData, float* pfOutputData, const i
float z0, z1, z2;
// Restore accumulators from last process call
z1 = m_vfAccumulators[ 0 ];
z2 = m_vfAccumulators[ 1 ];
z1 = z[ 0 ];
z2 = z[ 1 ];
for( int i = 0; i < iNumSamples; i++ )
{
......@@ -36,8 +35,8 @@ void CITABiquad::Process( const float* pfInputData, float* pfOutputData, const i
}
// Store accumulators for next process call
m_vfAccumulators[ 0 ] = z1;
m_vfAccumulators[ 1 ] = z2;
z[ 0 ] = z1;
z[ 1 ] = z2;
return;
}
......@@ -47,8 +46,8 @@ void CITABiquad::Process( const float* pfInputData, float* pfOutputData, const i
// Local accumulators
float z0, z1, z2;
z1 = m_vfAccumulators[ 0 ];
z2 = m_vfAccumulators[ 1 ];
z1 = z[ 0 ];
z2 = z[ 1 ];
if( iOutputMode == ITABase::MixingMethod::ADD )
{
......@@ -80,8 +79,8 @@ void CITABiquad::Process( const float* pfInputData, float* pfOutputData, const i
}
// Store accumulators
m_vfAccumulators[ 0 ] = z1;
m_vfAccumulators[ 1 ] = z2;
z[ 0 ] = z1;
z[ 1 ] = z2;
return;
}
......@@ -93,8 +92,8 @@ void CITABiquad::Process( const float* pfInputData, float* out, const int iNumSa
// Local accumulators
float z0, z1, z2;
z1 = m_vfAccumulators[ 0 ];
z2 = m_vfAccumulators[ 1 ];
z1 = z[ 0 ];
z2 = z[ 1 ];
// Factor for linear gain
const float fLinearGainFactor = ( fOutputGain2 - fOutputGain1 ) / float( iNumSamples );
......@@ -134,8 +133,8 @@ void CITABiquad::Process( const float* pfInputData, float* out, const int iNumSa
}
// Store accumulators
m_vfAccumulators[ 0 ] = z1;
m_vfAccumulators[ 1 ] = z2;
z[ 0 ] = z1;
z[ 1 ] = z2;
}
CITABiquad::CParams::CParams()
......@@ -147,3 +146,13 @@ CITABiquad::CParams::CParams()
, b2( 0 )
{
}
void CITABiquad::CParams::SetParameters( const float params[] )
{
g = params[ 0 ];
b0 = params[ 1 ];
b1 = params[ 2 ];
b2 = params[ 3 ];
a1 = params[ 4 ];
a2 = params[ 5 ];
}
......@@ -13,13 +13,13 @@
CITAThirdOctaveFilterbankIIR::CITAThirdOctaveFilterbankIIR( const double dSampleRate, const int iBlockLength )
: m_dSampleRate( dSampleRate )
, m_iBlockLength( iBlockLength )
, m_nBandsInternal( int( ITADSPThirdOctaveFilterbankIIR::vfFrequencies.size() ) )
, m_nBandsInternal( ITADSPThirdOctaveFilterbankIIR::ITA_BIQUAD_FILTER_NUM_BANDS )
, m_nBiquadsPerBand( ITADSPThirdOctaveFilterbankIIR::ITA_BIQUAD_FILTER_NUM_BIQUADS_PER_BAND )
{
if( dSampleRate != ITADSPThirdOctaveFilterbankIIR::dSamplingFrequency )
ITA_EXCEPT1( INVALID_PARAMETER, "Filterbank does not support this samplingrate" );
if( m_nBandsInternal != ITABase::CThirdOctaveGainMagnitudeSpectrum::GetNumBands() )
if( m_nBandsInternal + 1 != ITABase::CThirdOctaveGainMagnitudeSpectrum::GetNumBands() )
ITA_EXCEPT1( INVALID_PARAMETER, "Filterbank does not match third octave band number" );
// Initialize biquads
......@@ -33,7 +33,7 @@ CITAThirdOctaveFilterbankIIR::CITAThirdOctaveFilterbankIIR( const double dSample
const std::vector< float >& vfBiquad( vvfBandBiquads[ j ] );
CITABiquad& oBiquad( m_vBiquads[ i * m_nBiquadsPerBand + j ] );
oBiquad.oParams.g = vfBiquad[ 0 ];
oBiquad.oParams.a0 = vfBiquad[ 1 ];
//oBiquad.oParams.a0 = vfBiquad[ 1 ];
oBiquad.oParams.a1 = vfBiquad[ 2 ];
oBiquad.oParams.a2 = vfBiquad[ 3 ];
oBiquad.oParams.b0 = vfBiquad[ 4 ];
......
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