ITADSPThirdOctaveFilterbankTest.cpp 1.94 KB
Newer Older
1
#include <ITAThirdOctaveFilterbank.h>
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

#include <ITAAudiofileWriter.h>
#include <ITAStopWatch.h>
#include <ITASampleBuffer.h>

#include <iostream>

using namespace std;

const double g_dSampleRate = 44100;
const int g_iFilterLength = 512;

void TestThirdOctaveFilterbankIIR();
void TestThirdOctaveFilterbankFIR() {};

17
int main( int, char** )
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
18
19
20
{
	TestThirdOctaveFilterbankIIR();
	TestThirdOctaveFilterbankFIR();
21
	return 255;
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
22
23
24
25
26
27
28
29
30
31
}

void TestThirdOctaveFilterbankIIR()
{
	const int iSampleLength = ( 1 << 17 );
	CITAThirdOctaveFilterbank* pIIRFilterbank = CITAThirdOctaveFilterbank::Create( g_dSampleRate, iSampleLength, CITAThirdOctaveFilterbank::IIR_BIQUADS_ORDER10 );

	ITASampleBuffer x( iSampleLength );
	x[ 0 ] = 1.0f;

32
	CITAThirdOctaveGainMagnitudeSpectrum oMags;
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
33
34
	oMags.SetIdentity();

35
	pIIRFilterbank->SetMagnitudes( oMags, false );
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
36
37
38
39
40
41
42
43
44
45

	ITASampleBuffer y( iSampleLength );

	ITAStopWatch sw;
	sw.start();
	pIIRFilterbank->Process( x.GetData(), y.GetData() );
	sw.stop();
	cout << "Runtime identity magnitudes:" << sw.ToString() << endl;

	y.Normalize();
46
	writeAudiofile( "ITADSPThirdOctaveFilterbankTest_IIR_Identity.wav", &y, g_dSampleRate );
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
47
48
	y.Zero();

49
	pIIRFilterbank->Clear();
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
50
51
	
	oMags.SetZero();
52
	pIIRFilterbank->SetMagnitudes( oMags, false );
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
53
54
55
56
57
58
59
	
	sw.start();
	pIIRFilterbank->Process( x.GetData(), y.GetData() );
	sw.stop();
	cout << "Runtime zero magnitude:" << sw.ToString() << endl;

	y.Normalize();
60
	writeAudiofile( "ITADSPThirdOctaveFilterbankTest_IIR_Zeros.wav", &y, g_dSampleRate );
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
61

62
	pIIRFilterbank->Clear();
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
63

64
65
66
67
68
69
70
	// 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;
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
71

72
	pIIRFilterbank->SetMagnitudes( oMags );
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
73
74
75
76
77
78
79

	sw.start();
	pIIRFilterbank->Process( x.GetData(), y.GetData() );
	sw.stop();
	cout << "Runtime real magnitudes:" << sw.ToString() << endl;

	y.Normalize();
80
	writeAudiofile( "ITADSPThirdOctaveFilterbankTest_IIR_SomeBands.wav", &y, g_dSampleRate );
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
81
82
83

	delete pIIRFilterbank;
}