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