Commit 90f87cf7 authored by henryjandrew's avatar henryjandrew

added to ability to import data from matlab. Automatically iterates over all...

added to ability to import data from matlab. Automatically iterates over all paths of incoming data, creates new paths which do not already exist, and updates the filter coefficients of the paths using the Burg method. Unused paths can now also be deleted by setting an option in the data from matlab.
parent c076cd92
......@@ -117,6 +117,10 @@ void CVABinauralOutdoorNoiseRenderer::Init( const CVAStruct& oArgs )
m_oDefaultWaveFrontConf.blockLength = GetBlocklength();
m_oDefaultWaveFrontConf.sampleRate = GetSampleRate();
m_oDefaultWaveFrontConf.iFilterOrder = 4; //TODO: get these from the ini file as above
m_oDefaultWaveFrontConf.IR_length = 1024;
m_oDefaultWaveFrontConf.FilterDesignAlgorithm = CVABinauralOutdoorWaveFront::BURG;
VAConfig::blockLength = GetBlocklength();
VAConfig::hrirLength = m_iHRIRFilterLength;
VAConfig::amplitudeCalibration = m_pCore->GetCoreConfig()->dDefaultAmplitudeCalibration;
......@@ -140,92 +144,46 @@ void CVABinauralOutdoorNoiseRenderer::SetParameters(const CVAStruct& oInArgs)
auto it = oInArgs.Begin();
while (it != oInArgs.End()) {
//const CVAStructValue& path_temp(&it); //tempory struct to hold the path data for the current iterator
const CVAStructValue& oPath(&it);
CVAStruct path = oPath;
int path_ID = path["path"];
//int path_ID = (oPath.GetData())["path"];
//asume that wave front ID's go from 0 to ... with no gaps, and that wavefronts are not deleted or replaced
int pool_size = m_pWaveFrontPool->GetNumUsed(); //total number of wavefronts currently in use
if (path_ID > pool_size) {
CVABinauralOutdoorWaveFront* wave_front = dynamic_cast<CVABinauralOutdoorWaveFront*>(m_pWaveFrontPool->RequestObject());
m_mCurrentWaveFronts.insert(std::pair< int, CVABinauralOutdoorWaveFront* >(path_ID, wave_front));
//probably should add reference here
else {
m_mCurrentWaveFronts[path_ID]->setParameters( oPath ); //cals a function which sets all the relevant internal parameters for the path
//int path_ID = oPath.;
//int m_mPaths.find(m_mPaths.begin(), m_mPaths.end(), path_ID);
//m_mPaths.find //given path number, find the internal representation of that path to store new data in
// Update
if (oInArgs.HasKey("receiver") == false || oInArgs.HasKey("source") == false)
VA_INFO("BinauralOutdoorNoiseRenderer", "Parameter setter was called without source or receiver id, did not update any generic path filter");
if (oInArgs.HasKey("paths") == false )
VA_INFO("BinauralOutdoorNoiseRenderer", "Parameter setter was called without a path list");
int iReceiverID = oInArgs["receiver"];
int iSourceID = oInArgs["source"];
const CVAStructValue path_value = it->second; //extract data for the current path from the iterator in a useful form
const CVAStruct path = path_value;
const CVAStruct& oPaths(oInArgs["paths"]);
//This is the unique string which identifies the current path for which data is being given (stored in "path")
std::string path_ID = path["path"]; //get path identifier from simulation engine. In future iterations, this will be generated within VA
auto it = oPaths.Begin();
while (it != oPaths.End())
const CVAStructValue& oPath(it.Ge);
bool bVerbose = false;
if (oInArgs.HasKey("verbose"))
bVerbose = true;
// add source to clustering
//m_pClusterEngine->AddWaveFront( sourceID, pSource );
// adjust VDL delay for given path / cursor
bool delete_path = path["delete"];
if (delete_path ) {
m_mPaths.erase(path_ID); //delete the sound path from the map
else {
auto path_pos = m_mPaths.find(path_ID); //find the position of "path_ID" in the map
//assumes that every paths frequency parameters are updated at every call, will need to be changed in future
mNumberofPaths = oInArgs["n0_of_paths"];
for (int n = 0; n <= mNumberofPaths; n++) { //loop over all paths
std::string path_name = "prop_path_" + std::to_string(n);
if (oInArgs.HasKey( path_name ) == true) {
CVAStruct test = oInArgs[path_name]; //struct with all info relating to the current path in
if (path_pos == m_mPaths.end()) { //if the path ID is not found, create a new path with this ID
CVABinauralOutdoorWaveFront* wave_front = dynamic_cast<CVABinauralOutdoorWaveFront*>(m_pWaveFrontPool->RequestObject()); //request a new path from the pool
m_mPaths.insert(std::pair<std::string, CVABinauralOutdoorWaveFront*>(path_ID, wave_front)); //put that path into the map with the label path_ID
//TODO: might need to add a reference to the new path here? *******************************************
CVAStructValue frequency_mags = test["values"];
int num_values = frequency_mags.GetDataSize() / sizeof(float);
CVAStructValue sMags = path["frequency_magnitudes"]; //
int num_values = sMags.GetDataSize() / sizeof(float); //currently only accepts third octave values, this is a safty check
if (num_values != 31)
VA_EXCEPT1("CVABinauralOutdoorNoiseRenderer: Expected 31 frequency magnitudes.");
void *values = frequency_mags.GetData();
const float* pfMags = (const float*)values;
void *pvMags = sMags.GetData();
const float* pfMags = (const float*)pvMags; //convert to float values
ITABase::CThirdOctaveGainMagnitudeSpectrum Mags; //set third octave magnitudes
for (int i = 0; i < 31; i++) {
(mMags[n])[i] = pfMags[i]; //set the magnitudes for the internal variable
Mags.SetMagnitude(i, pfMags[i]);
//VA_INFO("BinauralOutdoorNoiseRenderer", "Frequency magnitudes from path " + path_name );
float test = Mags[0];
m_mPaths[path_ID]->setFilterCoefficients(Mags); //update the filter coefficients internal to the path based on the target frequency magnitudes
//TODO: add extra "setters" for wave front delay, position/motion e.t.c
it++; //increment iterator for the next path
VA_INFO( "BinauralOutdoorNoiseRenderer", "Received input arguments: " + oInArgs.ToString() );
......@@ -516,7 +474,7 @@ void CVABinauralOutdoorNoiseRenderer::DeleteSoundSource( int sourceID )
auto source = it->second;
m_mSources.erase( it );
// todo henry: how to remove path from this source?
// todo henry: how to remove path from this source?**** Done (I think) ****
// remove listener reference from clustering
//m_pClusterEngine->RemoveWaveFront( sourceID );
......@@ -30,6 +30,8 @@
#include "../Clustering/Engine/VABinauralClusteringEngine.h"
#include "../Clustering/WaveFront/VABinauralWaveFront.h"
#include "../Clustering/Receiver/VABinauralClusteringDirectionReceiver.h"
#include "VABinauralOutdoorWaveFront.h"
class CVABinauralOutdoorWaveFront;
class CVABinauralOutdoorSource;
......@@ -66,8 +68,8 @@ private:
std::map< int, CVABinauralOutdoorSource* > m_mSources;
std::map< int, CVABinauralClusteringDirectionReceiver* > m_mBinauralReceivers;
std::map< int, CVABinauralOutdoorWaveFront* > m_mPaths; // All path of entire scene for all sources and receivers
std::map< std::string, CVABinauralOutdoorWaveFront* > m_mPaths; // All path of entire scene for all sources and receivers
//map containing all the paths, each accessed with a unique string key
CVABinauralClusteringEngine* m_pClusterEngine;
......@@ -82,7 +84,7 @@ private:
std::atomic< bool > m_bIndicateReset, m_bResetAck;
CVABinauralClusteringDirectionReceiver::Config m_oDefaultReceiverConf; //!< Default listener config for factory object creation
CVABinauralWaveFrontBase::Config m_oDefaultWaveFrontConf;
CVABinauralOutdoorWaveFront::Config m_oDefaultWaveFrontConf;
int m_iDefaultVDLSwitchingAlgorithm;
int m_iHRIRFilterLength;
......@@ -106,9 +108,8 @@ private:
int mNumberofPaths;
std::vector<ITABase::CThirdOctaveGainMagnitudeSpectrum> mMags; //internal vector of target magnitude spectrums for IIR filter design
//vector elements correspond to the path number
//vector elements correspond to the path number *****************PROBABLY NOT NEEDED ANY MORE**********************************
std::map< int, CVABinauralOutdoorWaveFront* > m_mCurrentWaveFronts;
......@@ -7,15 +7,24 @@
#include "../../../Motion/VAMotionModelBase.h"
#include "../../../Motion/VASharedMotionModel.h"
#include "../../../Scene/VAScene.h"
#include "../../../ITACoreLibs/ITADSP/include/ITAIIRFilterGenerator.h"
#include <ITAVariableDelayLine.h>
#include <ITASampleBuffer.h>
CVABinauralOutdoorWaveFront::CVABinauralOutdoorWaveFront( const CVABinauralWaveFrontBase::Config& conf )
#include <ITAThirdOctaveFIRFilterGenerator.h>
CVABinauralOutdoorWaveFront::CVABinauralOutdoorWaveFront( const CVABinauralOutdoorWaveFront::Config& conf )
: oConf( conf )
vdlChL = new CITAVariableDelayLine( conf.sampleRate, conf.blockLength, (const float)( 3. * conf.sampleRate ), CITAVariableDelayLine::CUBIC_SPLINE_INTERPOLATION );
vdlChR = new CITAVariableDelayLine( conf.sampleRate, conf.blockLength, (const float)( 3. * conf.sampleRate ), CITAVariableDelayLine::CUBIC_SPLINE_INTERPOLATION );
if (conf.FilterDesignAlgorithm == BURG)
IIRFilterCoeffs.Initialise(conf.iFilterOrder, false);
VA_EXCEPT1("Flter coefficient design algorithm not recognised/ not yet implemented");
......@@ -94,6 +103,22 @@ void CVABinauralOutdoorWaveFront::SetClusteringPose( const VAVec3& v3Pos, const
void CVABinauralOutdoorWaveFront::setParameters(const CVAStruct &oInArgs) {
//set positions/ motion
void CVABinauralOutdoorWaveFront::setFilterCoefficients(const ITABase::CThirdOctaveGainMagnitudeSpectrum &oMags ) {
ITABase::CFiniteImpulseResponse oIR(oConf.IR_length, oConf.sampleRate); //create an empty impulse response
CITAThirdOctaveFIRFilterGenerator oIRGenerator(oConf.sampleRate, oConf.IR_length); //convert the given third ctave frequency magnitudes to an impulse response
if (oConf.FilterDesignAlgorithm == BURG)
oIRGenerator.GenerateFilter(oMags, oIR.GetData(), false); //set to false for normal, true for minimum phase needed for yulewalk
VA_EXCEPT1("Filter design algorithm not recognised/ not yet implemented");
ITADSP::IIRFilterGenerator::Burg(oIR, IIRFilterCoeffs); //using the impulse response as input, calculate the IIR filter coefficients.
......@@ -8,6 +8,12 @@
#include "../Clustering/WaveFront/VABinauralWaveFront.h"
#include <ITAThirdOctaveMagnitudeSpectrum.h>
#include <ITAIIRCoefficients.h>
#include <ITAIIRUtils.h>
// Forwards
class CVASoundSourceState;
......@@ -24,13 +30,37 @@ class CVABinauralOutdoorSource;
class CVABinauralOutdoorWaveFront : public IVABinauralWaveFront, public CVAPoolObject
struct Config
bool motionModelLogInput;
bool motionModelLogEstimated;
double motionModelWindowSize;
double motionModelWindowDelay;
int motionModelNumHistoryKeys;
double sampleRate;
int blockLength;
int iFilterOrder;
int IR_length;
int FilterDesignAlgorithm;
enum FilterDesignAlgorithm //used to select the algorithm used to design filter coefficients
BURG = 0, //Use the Burg algorithm for designing the filter coefficients
CVABinauralOutdoorSource* pSource;
int iCursorID;
bool hasValidTrajectory;
const CVABinauralWaveFrontBase::Config oConf;
const CVABinauralOutdoorWaveFront::Config oConf;
CVASoundSourceState* pState;
CVASoundSourceDesc* pData;
......@@ -44,7 +74,7 @@ public:
VAVec3 predView; // @todo jst: appears to be useless in the context of clustering, confirm
VAVec3 predUp; // @todo jst: appears to be useless in the context of clustering, confirm
CVABinauralOutdoorWaveFront( const CVABinauralWaveFrontBase::Config& conf );
CVABinauralOutdoorWaveFront( const CVABinauralOutdoorWaveFront::Config& conf );
void PreRequest();
......@@ -54,6 +84,8 @@ public:
void SetClusteringPose( const VAVec3& v3Pos, const VAVec3& v3View, const VAVec3& v3Up );
void setParameters( const CVAStruct &oInArgs );
void setFilterCoefficients(const ITABase::CThirdOctaveGainMagnitudeSpectrum &oMags );
virtual bool GetValidTrajectory() const
......@@ -75,12 +107,16 @@ public:
return CVAPoolObject::RemoveReference();
double m_dCreationTimeStamp;
CITAVariableDelayLine* vdlChL; // Substitute with SIMO VDL (must be extended with a non-interpolating output)
CITAVariableDelayLine* vdlChR; // Remove, use eparate SIMO VDL cursor for L/R channels
CITAVariableDelayLine* vdlChR; // Remove, use separate SIMO VDL cursor for L/R channels
ITABase::CThirdOctaveGainMagnitudeSpectrum fMags;
ITADSP::CIIRCoefficients IIRFilterCoeffs;
#include "VABinauralOutdoorWaveFrontPoolFactory.h"
#include "VABinauralOutdoorWaveFront.h"
CVABinauralOutdoorWaveFrontPoolFactory::CVABinauralOutdoorWaveFrontPoolFactory( CVABinauralWaveFrontBase::Config oConf )
CVABinauralOutdoorWaveFrontPoolFactory::CVABinauralOutdoorWaveFrontPoolFactory(CVABinauralOutdoorWaveFront::Config oConf )
: m_oConf( oConf )
......@@ -2,16 +2,17 @@
#include "../Clustering/WaveFront/VABinauralWaveFront.h"
#include "VABinauralOutdoorWaveFront.h"
class CVABinauralOutdoorWaveFrontPoolFactory : public IVAPoolObjectFactory
CVABinauralOutdoorWaveFrontPoolFactory( CVABinauralWaveFrontBase::Config oConf );
CVABinauralOutdoorWaveFrontPoolFactory(CVABinauralOutdoorWaveFront::Config oConf );
CVAPoolObject* CVABinauralOutdoorWaveFrontPoolFactory::CreatePoolObject();
const CVABinauralWaveFrontBase::Config m_oConf;
const CVABinauralOutdoorWaveFront::Config m_oConf;
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