MaekawaTest.cpp 3.01 KB
Newer Older
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/*
 * ----------------------------------------------------------------
 *
 *		ITA geometrical acoustics
 *		(c) Copyright Institute of Technical Acoustics (ITA)
 *		RWTH Aachen University, Germany, 2015-2018
 *
 * ----------------------------------------------------------------
 * 				    ____  __________  _______
 *				   //  / //__   ___/ //  _   |
 *				  //  /    //  /    //  /_|  |
 *				 //  /    //  /    //  ___   |
 *				//__/    //__/    //__/   |__|
 *
 * ----------------------------------------------------------------
 *
 */

19
#include <ITAPropagationModels/Maekawa.h>
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
20 21 22 23 24 25 26 27 28 29 30 31 32 33

#include <ITAException.h>
#include <ITAStopWatch.h>
#include <ITAStringUtils.h>
#include <ITAFFTUtils.h>

#include <VistaBase/VistaVector3D.h>
#include <vistaBase/VistaExceptionBase.h>

#include <iostream>
#include <cassert>

using namespace std;
using namespace ITAGeo;
34
using namespace ITAPropagationModels;
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
35 36 37 38

static float g_fSampleRate = 44.1e3f;
static int g_iFilterLength = 128;

39
//! Tests running the Maekawa model functions
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
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
/**
  *
  */
int main( int, char** )
{
	auto pS = std::make_shared< CEmitter >( VistaVector3D( -2.0f, 0, 0 ) );
	auto pR = std::make_shared< CSensor >( VistaVector3D( 2.0f, 0, 0 ) );

	auto pW = std::make_shared< CITADiffractionWedgeAperture >();
	pW->v3AperturePoint.SetValues( 0.0f, 1.0f, 0.0f );
	pW->v3MainWedgeFaceNormal.SetValues( -1.0f, 1.0f, .0f );
	pW->v3MainWedgeFaceNormal.Normalize();
	pW->v3OppositeWedgeFaceNormal.SetValues( 1.0f, 1.0f, .0f );
	pW->v3OppositeWedgeFaceNormal.Normalize();
	pW->v3VertextStart.SetValues( .0f, 1.0f, -1.0f );
	pW->v3VertextEnd.SetValues( .0f, 1.0f, 1.0f );

	CPropagationPath oPropPath;
	oPropPath.push_back( pS );
	oPropPath.push_back( pW );
	oPropPath.push_back( pR );

	cout << oPropPath << endl;

	try
	{
66 67
		if( Maekawa::IsApplicable( pS->v3InteractionPoint, pR->v3InteractionPoint, pW ) )
			cout << "[OK] Maekawa method can be applied for this path" << endl;
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
68
		else
69
			cout << "[BAD] Maekawa method can't be applied for this path, trying anyway" << endl;
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
70

71 72
		double dPropLengthDirect, dPropLengthDetour;
		Maekawa::GetDirectLengthAndDetourLength( pS->v3InteractionPoint, pR->v3InteractionPoint, pW, dPropLengthDirect, dPropLengthDetour );
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
73

74 75 76
		cout << "Maekawa direct path length: " << dPropLengthDirect << " m" << endl;
		cout << "Maekawa detour path length: " << dPropLengthDetour << " m" << endl;
		cout << "Kirchhoff delta: " << Maekawa::KirchhoffDelta( dPropLengthDirect, dPropLengthDetour ) << " m" << endl;
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
77 78 79

		ITABase::CHDFTSpectrum oDiffractionTF( g_fSampleRate, g_iFilterLength / 2 + 1, true );
		ITAStopWatch sw; sw.start();
80 81
		Maekawa::CalculateDiffractionFilter( dPropLengthDirect, dPropLengthDetour, oDiffractionTF );
		cout << "Maekawa filter generation calculation time: " << timeToString( sw.stop() ) << endl;
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
82 83 84

		cout << oDiffractionTF.ToString() << endl;

85
		ITAFFTUtils::Export( &oDiffractionTF, "MaekawaTestIR.wav" );
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
86 87 88 89 90 91 92 93 94 95 96 97 98 99
	}
	catch( const VistaExceptionBase& e )
	{
		cerr << e.GetPrintStatement() << endl;
		return 255;
	}
	catch( const ITAException& e )
	{
		cerr << e << endl;
		return 255;
	}

	return 0;
}