ITAThirdOctaveFilterbankFIR.h 3.18 KB
Newer Older
1
2
3
4
5
/*
 * ----------------------------------------------------------------
 *
 *		ITA core libs
 *		(c) Copyright Institute of Technical Acoustics (ITA)
6
 *		RWTH Aachen University, Germany, 2015-2018
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
 *
 * ----------------------------------------------------------------
 *				    ____  __________  _______
 *				   //  / //__   ___/ //  _   |
 *				  //  /    //  /    //  /_|  |
 *				 //  /    //  /    //  ___   |
 *				//__/    //__/    //__/   |__|
 *
 * ----------------------------------------------------------------
 *
 */

#ifndef IW_ITA_THIRD_OCTAVE_FILTERBANK_FIR
#define IW_ITA_THIRD_OCTAVE_FILTERBANK_FIR

#include <ITAThirdOctaveFilterbank.h>
#include <ITAThirdOctaveFIRFilterGenerator.h>

#include <ITAUPConvolution.h>
#include <ITAUPFilter.h>
#include <ITAFastMath.h>

#include <cassert>

//! Terzfilterbank mittels Dynamic Single-Channel Blockfalter (FIR Filter)
class ITA_DSP_API CITAThirdOctaveFilterbankFIR : public CITAThirdOctaveFilterbank
{
public:
	inline CITAThirdOctaveFilterbankFIR( const double dSampleRate, const int iBlockLength )
		: m_pfFilter( nullptr )
		, m_pGenerator( nullptr )
		, m_pConvolver( nullptr )
	{
		m_iBlocklength = iBlockLength;
		// [fwe] Hier wird die Filterlänge für Directivities festgelegt
		m_iFilterLength = 128;
		m_pfFilter = fm_falloc( m_iFilterLength, true );

		m_pGenerator = new CITAThirdOctaveFIRFilterGenerator( dSampleRate, m_iFilterLength );

		m_pConvolver = new ITAUPConvolution( iBlockLength, m_iFilterLength );
		m_pConvolver->SetFilterExchangeMode( ITAUPConvolution::CROSSFADE_COSINE_SQUARE );
		m_pConvolver->SetFilterCrossfadeLength( 32 );

		SetIdentity( false );
	}

	inline virtual ~CITAThirdOctaveFilterbankFIR()
	{
		fm_free( m_pfFilter );
		delete m_pGenerator;
		delete m_pConvolver;
	}

	inline virtual void SetIdentity( const bool bSmoothChangeover )
	{
		ITAUPFilter* pFilter = m_pConvolver->RequestFilter();
		int iLatency = m_pGenerator->GetLatency();
		assert( iLatency < m_iFilterLength );
		fm_zero( m_pfFilter, m_iFilterLength );
		m_pfFilter[ iLatency ] = 1;
		pFilter->Load( m_pfFilter, m_iFilterLength );
		m_pConvolver->ExchangeFilter( pFilter, ( bSmoothChangeover ? ITAUPConvolution::AUTO : ITAUPConvolution::SWITCH ) );
		pFilter->Release();	// Auto-release
	}

73
	inline virtual void SetMagnitudes( const CITAThirdOctaveGainMagnitudeSpectrum& oMags, const bool bSmoothChangeover = true )
74
	{
75
		m_pGenerator->GenerateFilter( oMags, m_pfFilter );
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
		ITAUPFilter* pFilter = m_pConvolver->RequestFilter();
		pFilter->Load( m_pfFilter, m_iFilterLength );
		m_pConvolver->ExchangeFilter( pFilter, ( bSmoothChangeover ? ITAUPConvolution::AUTO : ITAUPConvolution::SWITCH ) );
		pFilter->Release();	// Auto-release
	}

	inline int GetLatency() const
	{
		return m_pGenerator->GetLatency();
	}

	inline virtual void Clear()
	{
		m_pConvolver->clear();
		SetIdentity( true );
	}

	inline virtual void Process( const float* pfInputSamples, float* pfOutputSamples )
	{
		m_pConvolver->Process( pfInputSamples, m_iBlocklength, pfOutputSamples, m_iBlocklength );
	}

private:
	int m_iBlocklength;
	int m_iFilterLength;
	float* m_pfFilter;
	CITAThirdOctaveFIRFilterGenerator* m_pGenerator;
	ITAUPConvolution* m_pConvolver;
};

#endif // IW_ITA_THIRD_OCTAVE_FILTERBANK_FIR