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

Re-implementing gain setter for filter banks

parent 6d38d1b7
......@@ -63,7 +63,8 @@ public:
virtual inline void SetIdentity( const bool bSmoothChangeover = true )
{
CITAThirdOctaveMagnitudeSpectrum oIdentity;
SetGains( oIdentity, bSmoothChangeover );
oIdentity.SetIdentity();
SetMagnitudes( oIdentity, bSmoothChangeover );
};
//! Verstärkungsfaktoren setzen
......@@ -71,7 +72,7 @@ public:
* \param oGains Neue Verstärkungsfaktoren
* \param bSmoothChangeover Überbenden (default, true) oder direktes Umschalten (false)
*/
virtual void SetGains( const CITAThirdOctaveMagnitudeSpectrum& oGains, const bool bSmoothChangeover = true ) = 0;
virtual void SetMagnitudes( const CITAThirdOctaveMagnitudeSpectrum& oGains, const bool bSmoothChangeover = true ) = 0;
//! Latenz (Verzögerung) der Filterbank zurückgeben
/**
......
......@@ -70,7 +70,7 @@ public:
pFilter->Release(); // Auto-release
}
inline virtual void SetGains( const CITAThirdOctaveMagnitudeSpectrum& oGains, const bool bSmoothChangeover = true )
inline virtual void SetMagnitudes( const CITAThirdOctaveMagnitudeSpectrum& oGains, const bool bSmoothChangeover = true )
{
m_pGenerator->GenerateFilter( oGains, m_pfFilter );
ITAUPFilter* pFilter = m_pConvolver->RequestFilter();
......
......@@ -21,6 +21,7 @@
#include <ITADSPDefinitions.h>
#include <ITAThirdOctaveFilterbank.h>
#include <ITAAmplitudeSpectrum.h>
#include <ITABiquad.h>
#include <vector>
......@@ -53,7 +54,7 @@ public:
* \param oGains Verstärkungsfaktoren
* \param bSmoothChangeover Wenn true, dann überblenden (default), sonst sofort internen Gain umschalten
*/
void SetGains( const CITAThirdOctaveMagnitudeSpectrum& oGains, const bool bSmoothChangeover = true );
void SetMagnitudes( const CITAThirdOctaveMagnitudeSpectrum& oGains, const bool bSmoothChangeover = true );
//! Alle internen Zustände zurücksetzen (Akkumulatoren der Biquads)
void Clear();
......@@ -70,7 +71,7 @@ private:
class GainUpdate
{
public:
CITAThirdOctaveMagnitudeSpectrum oGains; //!< Gain-Daten
CITAThirdOctaveMagnitudeSpectrum oMags; //! New magnitudes
int iBlendSamples; //!< Anzahl Samples zum Überblenden
};
......@@ -79,7 +80,7 @@ private:
int m_nBandsInternal; //!< Anzahl der internen Bänder
int m_nBiquadsPerBand; //!< Anzahl von Biqads pro Band
std::vector< CITABiquad > m_vBiquads; //!< Biquads, Zugriff: [Band][BiquadNummer]
tbb::strict_ppl::concurrent_queue< GainUpdate > m_qGains; //!< Liste von neuen Verstärkungsfaktoren
tbb::strict_ppl::concurrent_queue< CITAThirdOctaveFilterbankIIR::GainUpdate > m_qGains; //!< Liste von neuen Verstärkungsfaktoren
CITAThirdOctaveMagnitudeSpectrum m_oGainsInternal; //!< Interne Verstärkungsfaktoren
float* m_pfTempFilterBuf; //!< Zwischenpuffer für Filter
float* m_pfTempOutputBuf; //!< Zwischenpuffer für Ausgabe
......
......@@ -39,7 +39,7 @@ void CITABiquad::Process( const float* pfInputData, float* pfOutputData, const i
return;
}
void CITABiquad::Process( const float* pfInputData, float* out, int nsamples, float outputGain, int outputMode )
void CITABiquad::Process( const float* pfInputData, float* out, const int nsamples, const float outputGain, const int outputMode )
{
// Lokale Akkumulatoren
float z0, z1, z2;
......@@ -80,7 +80,7 @@ void CITABiquad::Process( const float* pfInputData, float* out, int nsamples, fl
return;
}
void CITABiquad::Process( const float* pfInputData, float* out, int nsamples, float outputGain1, float outputGain2, int outputMode )
void CITABiquad::Process( const float* pfInputData, float* out, const int nsamples, const float outputGain1, const float outputGain2, const int outputMode )
{
if( nsamples == 0 )
return;
......
......@@ -41,7 +41,7 @@ CITAThirdOctaveFIRFilterGenerator::CITAThirdOctaveFIRFilterGenerator( const doub
float c = 2 * ITAConstants::PI_F / ( float ) ( m_iFilterLength - 1 );
for( int i = 0; i < m_iFilterLength; i++ )
{
m_pfWindow[ i ] = 0.5F * ( 1 - cos( c*i ) );
m_pfWindow[ i ] = 0.5F * ( 1 - cos( c * i ) );
}
m_ifft.plan( ITAFFT::IFFT_C2R, iFilterLength, m_pfBuf1, m_pfBuf2 );
......
......@@ -5,6 +5,7 @@
#include <ITAFastMath.h>
#include <ITAStopWatch.h>
#include <ITAException.h>
#include <ITANumericUtils.h>
#include <cassert>
......@@ -45,10 +46,10 @@ int CITAThirdOctaveFilterbankIIR::GetLatency() const
return 0; // [stienen] sicher?
}
void CITAThirdOctaveFilterbankIIR::SetGains( const CITAThirdOctaveMagnitudeSpectrum& oGains, bool bSmoothChangeover )
void CITAThirdOctaveFilterbankIIR::SetMagnitudes( const CITAThirdOctaveMagnitudeSpectrum& oMagnitudes, bool bSmoothChangeover )
{
GainUpdate oUpdate;
oUpdate.oGains = oGains;
CITAThirdOctaveFilterbankIIR::GainUpdate oUpdate;
oUpdate.oMags = oMagnitudes;
oUpdate.iBlendSamples = ( bSmoothChangeover ? 1 : 0 );
m_qGains.push( oUpdate );
}
......@@ -76,12 +77,10 @@ void CITAThirdOctaveFilterbankIIR::Process( const float* pfInputSamples, float*
return; // [stienen] lieber assert? Filter ohne Bnder?
// Gains bernehmen
GainUpdate oUpdate;
CITAThirdOctaveFilterbankIIR::GainUpdate oUpdate;
bool bUpdateGains = false;
while( m_qGains.try_pop( oUpdate ) )
{
bUpdateGains = true;
}
if( bUpdateGains )
{
......@@ -99,7 +98,8 @@ void CITAThirdOctaveFilterbankIIR::Process( const float* pfInputSamples, float*
m_vBiquads[ i*m_nBiquadsPerBand + j ].Process( m_pfTempFilterBuf, m_pfTempFilterBuf, m_iBlockLength );
// Letztes Biquad mit Gain: tmp => output
m_vBiquads[ i*m_nBiquadsPerBand + k ].Process( m_pfTempFilterBuf, m_pfTempOutputBuf, m_iBlockLength, oUpdate.oGains[ i ], ( i == 0 ? CITABiquad::OUTPUT_OVERWRITE : CITABiquad::OUTPUT_ADD ) );
const float fGain = float( db10_to_ratio( oUpdate.oMags[ i ] ) );
m_vBiquads[ i*m_nBiquadsPerBand + k ].Process( m_pfTempFilterBuf, m_pfTempOutputBuf, m_iBlockLength, fGain, ( i == 0 ? CITABiquad::OUTPUT_OVERWRITE : CITABiquad::OUTPUT_ADD ) );
}
}
else
......@@ -115,11 +115,13 @@ void CITAThirdOctaveFilterbankIIR::Process( const float* pfInputSamples, float*
m_vBiquads[ i*m_nBiquadsPerBand + j ].Process( m_pfTempFilterBuf, m_pfTempFilterBuf, m_iBlockLength );
// Letztes Biquad mit Gain: tmp => output
m_vBiquads[ i*m_nBiquadsPerBand + k ].Process( m_pfTempFilterBuf, m_pfTempOutputBuf, m_iBlockLength, m_oGainsInternal[ i ], oUpdate.oGains[ i ], ( i == 0 ? CITABiquad::OUTPUT_OVERWRITE : CITABiquad::OUTPUT_ADD ) );
const float fGain1 = m_oGainsInternal[ i ];
const float fGain2 = float( db10_to_ratio( oUpdate.oMags[ i ] ) );
m_vBiquads[ i*m_nBiquadsPerBand + k ].Process( m_pfTempFilterBuf, m_pfTempOutputBuf, m_iBlockLength, fGain1, fGain2, ( i == 0 ? CITABiquad::OUTPUT_OVERWRITE : CITABiquad::OUTPUT_ADD ) );
}
}
m_oGainsInternal = oUpdate.oGains;
m_oGainsInternal = oUpdate.oMags;
}
else
{
......
......@@ -12,7 +12,8 @@
using namespace std;
const double g_dSampleRate = 44100;
const int g_iFilterLength = int( ceil( g_dSampleRate / CITAThirdOctaveMagnitudeSpectrum::GetCenterFrequencies()[ 0 ] ) );
//const int g_iFilterLength = int( ceil( g_dSampleRate / CITAThirdOctaveMagnitudeSpectrum::GetCenterFrequencies()[ 0 ] ) );
const int g_iFilterLength = int( 10 * ceil( g_dSampleRate / CITAThirdOctaveMagnitudeSpectrum::GetCenterFrequencies()[ 0 ] ) );
void TestThirdOctaveFilterGeneratorFIRIdentity();
void TestThirdOctaveFilterGeneratorFIRZero();
......
......@@ -31,7 +31,7 @@ void TestThirdOctaveFilterbankIIR()
CITAThirdOctaveMagnitudeSpectrum oMags;
oMags.SetIdentity();
pIIRFilterbank->SetGains( oMags );
pIIRFilterbank->SetMagnitudes( oMags );
ITASampleBuffer y( iSampleLength );
......@@ -42,14 +42,14 @@ void TestThirdOctaveFilterbankIIR()
cout << "Runtime identity magnitudes:" << sw.ToString() << endl;
y.Normalize();
writeAudiofile( "bankout_zeros_iir.wav", &y, g_dSampleRate );
writeAudiofile( "ITADSPThirdOctaveFilterbankTest_IIR_Identity.wav", &y, g_dSampleRate );
y.Zero();
delete pIIRFilterbank;
pIIRFilterbank = CITAThirdOctaveFilterbank::Create( g_dSampleRate, iSampleLength, CITAThirdOctaveFilterbank::IIR_BIQUADS_ORDER10 );
oMags.SetZero();
pIIRFilterbank->SetGains( oMags );
pIIRFilterbank->SetMagnitudes( oMags );
sw.start();
pIIRFilterbank->Process( x.GetData(), y.GetData() );
......@@ -57,19 +57,20 @@ void TestThirdOctaveFilterbankIIR()
cout << "Runtime zero magnitude:" << sw.ToString() << endl;
y.Normalize();
writeAudiofile( "bankout_identity_iir.wav", &y, g_dSampleRate );
writeAudiofile( "ITADSPThirdOctaveFilterbankTest_IIR_Zeros.wav", &y, g_dSampleRate );
delete pIIRFilterbank;
pIIRFilterbank = CITAThirdOctaveFilterbank::Create( g_dSampleRate, iSampleLength, CITAThirdOctaveFilterbank::IIR_BIQUADS_ORDER10 );
oMags[ 10 ] = 0.01f;
oMags[ 11 ] = 0.001f;
oMags[ 12 ] = 0.050f;
oMags[ 13 ] = 0.30f;
oMags[ 14 ] = 0.80f;
oMags[ 3 ] = 2.0f;
// dB values
oMags[ 3 ] = 3.0f;
oMags[ 10 ] = -3.0f;
oMags[ 11 ] = -6.0f;
oMags[ 12 ] = -9.0f;
oMags[ 13 ] = -9.0f;
oMags[ 14 ] = -7.0f;
pIIRFilterbank->SetGains( oMags );
pIIRFilterbank->SetMagnitudes( oMags );
sw.start();
pIIRFilterbank->Process( x.GetData(), y.GetData() );
......@@ -77,7 +78,7 @@ void TestThirdOctaveFilterbankIIR()
cout << "Runtime real magnitudes:" << sw.ToString() << endl;
y.Normalize();
writeAudiofile( "bankout_realmags_iir.wav", &y, g_dSampleRate );
writeAudiofile( "ITADSPThirdOctaveFilterbankTest_IIR_SomeBands.wav", &y, g_dSampleRate );
delete pIIRFilterbank;
}
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