Applying ITAGeo changes and adding tests for source and receiver directivity filter engine feature

parent bf80ef43
......@@ -19,7 +19,7 @@
#ifndef INCLUDE_WATCHER_ITA_PROPAGATION_MODELS_FILTER_ENGINE
#define INCLUDE_WATCHER_ITA_PROPAGATION_MODELS_FILTER_ENGINE
// ITAPropagationModel includes
// ITAPropagationModel includes
#include "Base.h"
#include "Definitions.h"
......@@ -36,7 +36,7 @@
namespace ITAPropagationModels
{
using namespace std;
//! Transfer function filter generator for propagation paths
/**
* Generates transfer functions in the frequency-domain that
......@@ -56,32 +56,48 @@ namespace ITAPropagationModels
*
* @note Throws ITAException if sensors have different number of channels
*/
static int GetNumSensorChannels( const ITAGeo::CPropagationPathList& oPathList );
static int GetNumSensorChannels(const ITAGeo::CPropagationPathList& oPathList);
//! Checks if the sensor is the same anchor for all propagation paths
/**
* @param[in] oPathList Propagation path list
* @return True, if path list shares the same sensor
*
* @note Throws ITAException if sensors have different number of channels
*/
static bool HasSameSensorAnchor( const ITAGeo::CPropagationPathList& oPathList );
static bool ValidateSameSensor(const ITAGeo::CPropagationPathList& oPathList);
//! Checks if the sensor is the same anchor for all propagation paths
/**
* @param[in] oPathList Propagation path list
* @return True, if path list shares the same emitter
*
* @note Throws ITAException if sensors have different number of channels
*/
static bool ValidateSameEmitter(const ITAGeo::CPropagationPathList& oPathList);
//! Applies all acoustic models like reflection diffraction models
void ApplyAcousticModels( ITAGeo::CPropagationPathList& oPathList );
void ApplyAcousticModels(ITAGeo::CPropagationPathList& oPathList);
inline void ApplyAcousticModels(ITAGeo::CPropagationPath& oPath)
{
ITAGeo::CPropagationPathList oPathList;
oPathList.push_back(oPath);
ApplyAcousticModels(oPathList);
};
//!Applies diffraction models
/**
* @param[out] oPathList Propagation path list
* @param[in] iModel Acoustic material model type. If value is set to -1, the default material model is used.
*/
void ApplyDiffractionModel( ITAGeo::CPropagationPathList& oPathList, int iModel = -1);
void ApplyDiffractionModel(ITAGeo::CPropagationPathList& oPathList, int iModel = -1);
//!Applies reflection models
/**
* @param[out] oPathList Propagation path list
* @param[in] iModel Acoustic material model type. If value is set to -1, the default material model is used.
*/
void ApplyReflectionModel( ITAGeo::CPropagationPathList& oPathList, int iModel = -1 );
void ApplyReflectionModel(ITAGeo::CPropagationPathList& oPathList, int iModel = -1);
//!Applies emitter models
/**
......@@ -97,55 +113,53 @@ namespace ITAPropagationModels
*/
void ApplySensorModel(ITAGeo::CPropagationPathList& oPathList, int iModel = -1);
void ApplyTransmissionModel( ITAGeo::CPropagationPathList& oPathList, int iModel = -1 ); // @todo
void ApplyTransmissionModel(ITAGeo::CPropagationPathList& oPathList, int iModel = -1); // @todo
//! Generate multi-channel propagation path (for multi-channel receiver directivity)
/**
* @todo AER
*/
void Generate( const ITAGeo::CPropagationPathList& oPathList, ITABase::CHDFTSpectra& oFilter, bool* pbDFTDegreeTooSmall = NULL );
void Generate(const ITAGeo::CPropagationPathList& oPathList, ITABase::CHDFTSpectra& oFilter, bool* pbDFTDegreeTooSmall = NULL);
inline void Generate(const ITAGeo::CPropagationPath& oPath, ITABase::CHDFTSpectra& oFilter, bool* pbDFTDegreeTooSmall = NULL)
{
ITAGeo::CPropagationPathList oPathList;
oPathList.push_back(oPath);
Generate(oPathList, oFilter, pbDFTDegreeTooSmall);
};
//! Generate single-channel propagation path (for single-channel receiver directivity)
inline void Generate( const ITAGeo::CPropagationPathList& oPathList, ITABase::CHDFTSpectrum& oFilter, bool* pbDFTDegreeTooSmall = NULL )
inline void Generate(const ITAGeo::CPropagationPathList& oPathList, ITABase::CHDFTSpectrum& oFilter, bool* pbDFTDegreeTooSmall = NULL)
{
const vector< ITABase::CHDFTSpectrum* > vpSpectra = { &oFilter };
ITABase::CHDFTSpectra oTF( vpSpectra );
Generate( oPathList, oTF, pbDFTDegreeTooSmall );
ITABase::CHDFTSpectra oTF(vpSpectra);
Generate(oPathList, oTF, pbDFTDegreeTooSmall);
};
//! Sets a connection to the material manager
void SetMaterialManager( const ITAGeo::CMaterialManager* pMaterialManager );
void SetMaterialManager(const ITAGeo::Material::IManager* pMaterialManager);
// Returns pointer to material manager or null
const ITAGeo::CMaterialManager* GetMaterialManager() const;
const ITAGeo::Material::IManager* GetMaterialManager() const;
private:
unique_ptr<ITABase::CHDFTSpectra> m_pAccumulatedSpectra; //!< Gathered propagation paths from list
unique_ptr<ITABase::CHDFTSpectra> m_pTempPropPathSpectra; //!< Single prop-path spectra
static struct m_DefaultValues //!< Default values
const struct DefaultResolutions //!< Default values
{
static const int iReflectionModel = ITAGeo::IAcousticMaterial::SCALAR;
static const int iDiffractionModel = ITAGeo::IAcousticMaterial::THIRD_OCTAVE;
static const int iEmitterModel = ITAGeo::IAcousticMaterial::SCALAR;
static const int iSensorModel = ITAGeo::IAcousticMaterial::SCALAR;
};
int iReflectionModel = ITAGeo::Material::IMaterial::SCALAR;
int iDiffractionModel = ITAGeo::Material::IMaterial::THIRD_OCTAVE;
int iEmitterModel = ITAGeo::Material::IMaterial::SCALAR;
int iSensorModel = ITAGeo::Material::IMaterial::SCALAR;
} m_oDefaultResolutions;
const ITAGeo::CMaterialManager* m_pMaterialManager;
std::shared_ptr< const ITAGeo::Material::IManager > m_pMaterialManager;
const double m_dHumidity = 80.0;
const double m_dTemperature = 20.0;
const float m_fSpeedOfSound = ITAConstants::SPEED_OF_SOUND_F;
static struct m_DefaultDiffractionModel //!< Default values for diffractions
{
int iModel = 1;
};
const int m_iDefaultDiffractionModel = 1;
};
}
......
This diff is collapsed.
......@@ -4,3 +4,5 @@ add_subdirectory( "Maekawa" )
add_subdirectory( "Svensson" )
add_subdirectory( "UTD" )
add_subdirectory( "FilterEngine" )
add_subdirectory( "ReceiverDirectivityTest" )
add_subdirectory( "SourceDirectivityTest" )
cmake_minimum_required( VERSION 2.8 )
project( ITAPropagationModelsTest )
list( APPEND CMAKE_MODULE_PATH "$ENV{VISTA_CMAKE_COMMON}" )
include( VistaCommon )
vista_use_package( ITABase REQUIRED FIND_DEPENDENCIES )
vista_use_package( ITAGeo REQUIRED FIND_DEPENDENCIES )
vista_use_package( ITAPropagationModels REQUIRED FIND_DEPENDENCIES )
vista_use_package( ITAFFT REQUIRED FIND_DEPENDENCIES )
if( ITA_CORE_LIBS_BUILD_STATIC )
add_definitions( -DITA_BASE_STATIC )
endif( )
if( ITA_GEOMETRICAL_ACOUSTICS_BUILD_STATIC )
add_definitions( -DITA_PROPAGATION_MODELS_STATIC _DITA_PROPAGATION_PATH_SIM_STATIC -DITA_GEO_STATIC )
endif( )
add_executable( ReceiverDirectivityTest ReceiverDirectivityTest.cpp )
target_link_libraries( ReceiverDirectivityTest ${VISTA_USE_PACKAGE_LIBRARIES} )
vista_configure_app( ReceiverDirectivityTest )
vista_install( ReceiverDirectivityTest )
vista_create_default_info_file( ReceiverDirectivityTest )
set_property( TARGET ReceiverDirectivityTest PROPERTY FOLDER "ITAGeometricalAcoustics/Tests/ITAPropagationModels" )
/*
* ----------------------------------------------------------------
*
* ITA geometrical acoustics
* (c) Copyright Institute of Technical Acoustics (ITA)
* RWTH Aachen University, Germany, 2015-2018
*
* ----------------------------------------------------------------
* ____ __________ _______
* // / //__ ___/ // _ |
* // / // / // /_| |
* // / // / // ___ |
* //__/ //__/ //__/ |__|
*
* ----------------------------------------------------------------
*
*/
#include <ITAPropagationModels/FilterEngine.h>
#include <ITAGeo/Base.h>
#include <ITAGeo/Directivity/Base.h>
#include <ITAGeo/Directivity/DAFF_TimeDomain.h>
#include <ITAFFTUtils.h>
using namespace std;
using namespace ITAConstants;
using namespace ITAGeo;
using namespace ITAPropagationModels;
int main( int, char** )
{
auto pSenderLeft = make_shared< CEmitter >(VistaVector3D(-2.0f, 0.0f, 0.0f));
auto pSenderRight = make_shared< CEmitter >(VistaVector3D(2.0f, 0.0f, 0.0f));
shared_ptr< Directivity::CDAFF_TimeDomain > pHRIR = make_shared< Directivity::CDAFF_TimeDomain >();
pHRIR->LoadFromFile("ITA_Artificial_Head_5x5_44kHz_128.v17.ir.daff");
auto pReceiver = make_shared< CSensor >(VistaVector3D(0.0f, 0.0f, 0.0f));
pReceiver->pDirectivity = pHRIR;
CPropagationPath oPathFromLeft;
oPathFromLeft.push_back(pSenderLeft);
oPathFromLeft.push_back(pReceiver);
CPropagationPath oPathFromRight;
oPathFromRight.push_back(pSenderRight);
oPathFromRight.push_back(pReceiver);
CFilterEngine oFilterEngine;
// Set filter length according to the maximum path length
const float fSpeedOfSound = SPEED_OF_SOUND_F; // Approximation of speed of sound at ~20C
const float fSampleRate = 44.1e3f;
int iFilterLengthSamples = (int)(oPathFromLeft.GetLength() / fSpeedOfSound * fSampleRate);
iFilterLengthSamples = int(iFilterLengthSamples + 4096);
ITABase::CHDFTSpectra oTransmissionFilterLeft(fSampleRate, pReceiver->iNumChannels, iFilterLengthSamples);
bool bDFTDegreeTooSmallFlag;
oFilterEngine.ApplyAcousticModels(oPathFromLeft); // @todo aer remove / merge into Generate()
oFilterEngine.Generate(oPathFromLeft, oTransmissionFilterLeft, &bDFTDegreeTooSmallFlag);
if (bDFTDegreeTooSmallFlag)
cerr << "DFT lengh too small, could not include all path completely into target filter" << endl;
ITAFFTUtils::Export(&oTransmissionFilterLeft, "SourceFromLeft.wav"); // Exports in time domain as impulse response (IR)
iFilterLengthSamples = (int)(oPathFromRight.GetLength() / fSpeedOfSound * fSampleRate);
iFilterLengthSamples = int(iFilterLengthSamples + 4096);
ITABase::CHDFTSpectra oTransmissionFilterRight(fSampleRate, pReceiver->iNumChannels, iFilterLengthSamples);
oFilterEngine.ApplyAcousticModels(oPathFromRight); // @todo aer remove / merge into Generate()
oFilterEngine.Generate(oPathFromRight, oTransmissionFilterRight, &bDFTDegreeTooSmallFlag);
if (bDFTDegreeTooSmallFlag)
cerr << "DFT lengh too small, could not include all path completely into target filter" << endl;
ITAFFTUtils::Export(&oTransmissionFilterRight, "SourceFromRight.wav");
}
SourceFromLeft = ita_read( 'SourceFromLeft.wav' );
SourceFromRight = ita_read( 'SourceFromRight.wav' );
SourceFromLeftAndRight = ita_merge( SourceFromLeft, SourceFromRight );
SourceFromLeftAndRight.pt
\ No newline at end of file
cmake_minimum_required( VERSION 2.8 )
project( ITAPropagationModelsTest )
list( APPEND CMAKE_MODULE_PATH "$ENV{VISTA_CMAKE_COMMON}" )
include( VistaCommon )
vista_use_package( ITABase REQUIRED FIND_DEPENDENCIES )
vista_use_package( ITAPropagationModels REQUIRED FIND_DEPENDENCIES )
vista_use_package( ITAFFT REQUIRED FIND_DEPENDENCIES )
if( ITA_CORE_LIBS_BUILD_STATIC )
add_definitions( -DITA_BASE_STATIC )
endif( )
if( ITA_GEOMETRICAL_ACOUSTICS_BUILD_STATIC )
add_definitions( -DITA_PROPAGATION_MODELS_STATIC _DITA_PROPAGATION_PATH_SIM_STATIC -DITA_GEO_STATIC )
endif( )
add_executable( SourceDirectivityTest SourceDirectivityTest.cpp )
target_link_libraries( SourceDirectivityTest ${VISTA_USE_PACKAGE_LIBRARIES} )
vista_configure_app( SourceDirectivityTest )
vista_install( SourceDirectivityTest )
vista_create_default_info_file( SourceDirectivityTest )
set_property( TARGET SourceDirectivityTest PROPERTY FOLDER "ITAGeometricalAcoustics/Tests/ITAPropagationModels" )
/*
* ----------------------------------------------------------------
*
* ITA geometrical acoustics
* (c) Copyright Institute of Technical Acoustics (ITA)
* RWTH Aachen University, Germany, 2015-2018
*
* ----------------------------------------------------------------
* ____ __________ _______
* // / //__ ___/ // _ |
* // / // / // /_| |
* // / // / // ___ |
* //__/ //__/ //__/ |__|
*
* ----------------------------------------------------------------
*
*/
#include <ITAPropagationModels/FilterEngine.h>
#include <ITAGeo/Base.h>
#include <ITAGeo/Material/Manager.h>
#include <ITAFFTUtils.h>
#include <ITAISO9613.h>
using namespace std;
using namespace ITAConstants;
using namespace ITAGeo;
using namespace ITAPropagationModels;
int main( int, char** )
{
/*
|___x___|
/\
s \ r
\ /
___x___
|______|
*/
auto pSender = make_shared< CEmitter >( VistaVector3D( -2.0f, 0.0f, 0.0f ) );
auto pReceiver = make_shared< CSensor >( VistaVector3D( 2.0f, 0.0f, 0.0f ) );
CMaterialDirectory oMaterialDirectory( "./" );
auto pReflection = make_shared< CSpecularReflection >( VistaVector3D( 0.0f, 2.0f, 0.0f ) );
pReflection->pAcousticMaterial = oMaterialDirectory.GetMaterial( "stonewall" );
auto pW = std::make_shared< CITADiffractionOuterWedgeAperture >();
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 oPathDirect;
oPathDirect.push_back( pSender );
oPathDirect.push_back( pReceiver );
CPropagationPath oPathReflection;
oPathReflection.push_back( pSender );
oPathReflection.push_back( pReflection );
oPathReflection.push_back( pReceiver );
CPropagationPath oPathDiffraction;
oPathDiffraction.push_back( pSender );
oPathDiffraction.push_back( pW );
oPathDiffraction.push_back( pReceiver );
CPropagationPathList oPathList;
oPathList.push_back(oPathDirect);
oPathList.push_back(oPathReflection);
oPathList.push_back(oPathDiffraction);
CFilterEngine oFilterEngine;
oFilterEngine.SetMaterialManager( &oMaterialDirectory );
// Set filter length according to the maximum path length
const float fSpeedOfSound = SPEED_OF_SOUND_F; //Approximation of speed of sound at ~20C
const float fSampleRate = 44.1e3f;
int iFilterLengthSamples = ( int ) ( oPathList.GetMaxLength() / fSpeedOfSound * fSampleRate );
iFilterLengthSamples = int( iFilterLengthSamples + 4096 );
ITABase::CHDFTSpectra oTransmissionFilter( fSampleRate, pReceiver->iNumChannels, iFilterLengthSamples );
bool bDFTDegreeTooSmallFlag;
oFilterEngine.ApplyAcousticModels( oPathList ); // @todo aer remove / merge into Generate()
oFilterEngine.Generate( oPathList, oTransmissionFilter, &bDFTDegreeTooSmallFlag );
if( bDFTDegreeTooSmallFlag )
cerr << "DFT lengh too small, could not include all path completely into target filter" << endl;
ITAFFTUtils::Export( &oTransmissionFilter, "FilterEngineTest.wav" ); // Exports in time domain as impulse response (IR)
}
%% Example with one diffraction and one reflaction component
ThreePath_Example = ita_read('ThreePaths_Example.wav');
ita_plot(ThreePath_Example)
%% Image source example
ImageSource_Example = ita_read('ImageSource_Example.wav');
ImageSource_Example.pf
\ No newline at end of file
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