Commit c076cd92 authored by henryjandrew's avatar henryjandrew

wip

parent 051a29be
......@@ -5,6 +5,13 @@
#include <ctime>
#include <chrono>
#include <time.h>
#include <vector>
#include <string>
#include <sstream>
#include <ITAThirdOctaveFilterbank.h>
// VA Includes
#include <VA.h>
......@@ -26,6 +33,7 @@
#include "../Clustering/Receiver/VABinauralClusteringDirectionReceiverPoolFactory.h"
#include "VABinauralOutdoorWaveFront.h"
#include "VABinauralOutdoorWaveFrontPoolFactory.h"
#include "VABinauralOutdoorSource.h"
CVABinauralOutdoorNoiseRenderer::CVABinauralOutdoorNoiseRenderer( const CVAAudioRendererInitParams& oParams )
: ITADatasourceRealization( 2, oParams.pCore->GetCoreConfig()->oAudioDriverConfig.dSampleRate, oParams.pCore->GetCoreConfig()->oAudioDriverConfig.iBuffersize )
......@@ -127,8 +135,97 @@ ITADatasource* CVABinauralOutdoorNoiseRenderer::GetOutputDatasource()
return this;
}
void CVABinauralOutdoorNoiseRenderer::SetParameters( const CVAStruct& oInArgs )
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"];
//assert(oPath.IsData());
oPath.GetData();
//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
it++;
}
/*
// 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");
return;
}
if (oInArgs.HasKey("paths") == false )
{
VA_INFO("BinauralOutdoorNoiseRenderer", "Parameter setter was called without a path list");
return;
}
int iReceiverID = oInArgs["receiver"];
int iSourceID = oInArgs["source"];
const CVAStruct& oPaths(oInArgs["paths"]);
auto it = oPaths.Begin();
while (it != oPaths.End())
{
const CVAStructValue& oPath(it.Ge);
it++;
m_mPaths.find
}
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
//assumes that every paths frequency parameters are updated at every call, will need to be changed in future
mNumberofPaths = oInArgs["n0_of_paths"];
mMags.resize(mNumberofPaths);
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
CVAStructValue frequency_mags = test["values"];
int num_values = frequency_mags.GetDataSize() / sizeof(float);
if (num_values != 31)
VA_EXCEPT1("CVABinauralOutdoorNoiseRenderer: Expected 31 frequency magnitudes.");
void *values = frequency_mags.GetData();
const float* pfMags = (const float*)values;
for (int i = 0; i < 31; i++) {
(mMags[n])[i] = pfMags[i]; //set the magnitudes for the internal variable
}
//VA_INFO("BinauralOutdoorNoiseRenderer", "Frequency magnitudes from path " + path_name );
}
}
VA_INFO( "BinauralOutdoorNoiseRenderer", "Received input arguments: " + oInArgs.ToString() );
}
......@@ -289,15 +386,15 @@ void CVABinauralOutdoorNoiseRenderer::UpdateSoundSources( CVASceneStateDiff* dif
}
// Update wave front trajectories
std::map< int, CVABinauralOutdoorWaveFront* >::iterator it;
std::map< int, CVABinauralOutdoorSource* >::iterator it;
for( it = m_mWaveFronts.begin(); it != m_mWaveFronts.end(); ++it )
for( it = m_mSources.begin(); it != m_mSources.end(); ++it )
{
int iWaveFrontID = it->first;
CVABinauralOutdoorWaveFront* source = it->second;
int iSourceID = it->first;
CVABinauralOutdoorSource* source = it->second;
CVASoundSourceState* sourceCur = ( m_pCurSceneState ? m_pCurSceneState->GetSoundSourceState( iWaveFrontID ) : nullptr );
CVASoundSourceState* sourceNew = ( m_pNewSceneState ? m_pNewSceneState->GetSoundSourceState( iWaveFrontID ) : nullptr );
CVASoundSourceState* sourceCur = ( m_pCurSceneState ? m_pCurSceneState->GetSoundSourceState(iSourceID) : nullptr );
CVASoundSourceState* sourceNew = ( m_pNewSceneState ? m_pNewSceneState->GetSoundSourceState(iSourceID) : nullptr );
if( sourceNew && ( sourceNew != sourceCur ) )
{
......@@ -319,10 +416,14 @@ void CVABinauralOutdoorNoiseRenderer::UpdateSoundSources( CVASceneStateDiff* dif
VAVec3 view = motionNew->GetView();
VAVec3 up = motionNew->GetUp();
/*
source->v3PredictedPos = pos;
source->predView = view;
source->predUp = up;
source->hasValidTrajectory = true;
todo : in future impl trigger propagation simulation
*/
}
}
}
......@@ -386,36 +487,39 @@ void CVABinauralOutdoorNoiseRenderer::UpdateSoundReceivers( CVASceneStateDiff* d
void CVABinauralOutdoorNoiseRenderer::CreateSoundSource( const int sourceID, const CVASoundSourceState* sourceState )
{
CVABinauralOutdoorWaveFront* source = dynamic_cast< CVABinauralOutdoorWaveFront* >( m_pWaveFrontPool->RequestObject() ); // Reference = 1
//CVABinauralOutdoorWaveFront* source = dynamic_cast< CVABinauralOutdoorWaveFront* >( m_pWaveFrontPool->RequestObject() ); // Reference = 1
auto pSource = new CVABinauralOutdoorSource();
// set state
source->pState = ( CVASoundSourceState* ) sourceState;
pSource->pState = ( CVASoundSourceState* ) sourceState;
// set internal data
source->pData = m_pCore->GetSceneManager()->GetSoundSourceDesc( sourceID );
source->pData->AddReference();
pSource->pData = m_pCore->GetSceneManager()->GetSoundSourceDesc( sourceID );
pSource->pData->AddReference();
CVABasicMotionModel::Config sourceMotionConf;
sourceMotionConf.SetDefaults();
pSource->pMotionModel = new CVASharedMotionModel(new CVABasicMotionModel(sourceMotionConf), true);
// set motion model
CVABasicMotionModel* motionInstance = dynamic_cast< CVABasicMotionModel* >( source->pMotionModel->GetInstance() );
motionInstance->SetName( std::string( "bfrend_mm_source_" + source->pData->sName ) );
CVABasicMotionModel* motionInstance = dynamic_cast< CVABasicMotionModel* >( pSource->pMotionModel->GetInstance() ); // Problem HERE***
motionInstance->SetName( std::string( "bfrend_mm_source_" + pSource->pData->sName ) );
motionInstance->Reset();
// add local reference
m_mWaveFronts.insert( std::pair< int, CVABinauralOutdoorWaveFront* >( sourceID, source ) );
m_mSources.insert( std::pair< int, CVABinauralOutdoorSource* >( sourceID, pSource ) );
// add source to clustering
m_pClusterEngine->AddWaveFront( sourceID, source );
}
void CVABinauralOutdoorNoiseRenderer::DeleteSoundSource( int sourceID )
{
// remove local source reference
std::map< int, CVABinauralOutdoorWaveFront* >::iterator it = m_mWaveFronts.find( sourceID );
CVABinauralOutdoorWaveFront* source = it->second;
m_mWaveFronts.erase( it );
std::map< int, CVABinauralOutdoorSource* >::iterator it = m_mSources.find( sourceID );
auto source = it->second;
m_mSources.erase( it );
// todo henry: how to remove path from this source?
// remove listener reference from clustering
m_pClusterEngine->RemoveWaveFront( sourceID );
source->RemoveReference();
//m_pClusterEngine->RemoveWaveFront( sourceID );
//source->RemoveReference();
}
void CVABinauralOutdoorNoiseRenderer::CreateSoundReceiver( int listenerID, const CVAReceiverState* recevierState )
......@@ -427,7 +531,7 @@ void CVABinauralOutdoorNoiseRenderer::CreateSoundReceiver( int listenerID, const
listener->pData->AddReference();
// set motion model
CVABasicMotionModel* motionInstance = dynamic_cast< CVABasicMotionModel* >( listener->pMotionModel->GetInstance() );
CVABasicMotionModel* motionInstance = dynamic_cast< CVABasicMotionModel* >( listener->pMotionModel->GetInstance() ); //foo possible error Get Instance
motionInstance->SetName( std::string( "bfrend_mm_listener_" + listener->pData->sName ) );
motionInstance->Reset();
......@@ -461,10 +565,10 @@ void CVABinauralOutdoorNoiseRenderer::DeleteSoundReceiver( int listenerID )
void CVABinauralOutdoorNoiseRenderer::UpdateMotionStates()
{
// Neue Quellendaten bernehmen
for( std::map< int, CVABinauralOutdoorWaveFront* >::iterator it = m_mWaveFronts.begin(); it != m_mWaveFronts.end(); ++it )
for( std::map< int, CVABinauralOutdoorSource* >::iterator it = m_mSources.begin(); it != m_mSources.end(); ++it )
{
int sourceID = it->first;
CVABinauralOutdoorWaveFront* source = it->second;
auto source = it->second;
CVASoundSourceState* sourceCur = ( m_pCurSceneState ? m_pCurSceneState->GetSoundSourceState( sourceID ) : nullptr );
CVASoundSourceState* sourceNew = ( m_pNewSceneState ? m_pNewSceneState->GetSoundSourceState( sourceID ) : nullptr );
......@@ -482,15 +586,17 @@ void CVABinauralOutdoorNoiseRenderer::UpdateMotionStates()
void CVABinauralOutdoorNoiseRenderer::UpdateTrajectories( double time )
{
for( auto const& sourceIt : m_mWaveFronts )
for( auto const& sourceIt : m_mSources )
{
bool isValid = true;
CVABinauralOutdoorWaveFront* source = sourceIt.second;
auto source = sourceIt.second;
source->pMotionModel->HandleMotionKeys();
/* todo trigger simulation in C++ ...
isValid &= source->pMotionModel->EstimatePosition( time, source->v3PredictedPos );
isValid &= source->pMotionModel->EstimateOrientation( time, source->predView, source->predUp );
source->hasValidTrajectory = isValid;
*/
}
for( auto const& listenerIt : m_mBinauralReceivers )
......
......@@ -19,6 +19,9 @@
// VA Includes
#include <VA.h>
#include "../../VAAudioRenderer.h"
#include <ITAThirdOctaveFilterbank.h>
// ITA includes
#include <ITADataSourceRealization.h>
......@@ -29,6 +32,7 @@
#include "../Clustering/Receiver/VABinauralClusteringDirectionReceiver.h"
class CVABinauralOutdoorWaveFront;
class CVABinauralOutdoorSource;
//! A binaural outdoor noise renderer that handles propagation paths efficiently
/**
......@@ -60,8 +64,10 @@ public:
private:
const CVAAudioRendererInitParams m_oParams;
std::map< int, CVABinauralOutdoorWaveFront* > m_mWaveFronts;
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
CVABinauralClusteringEngine* m_pClusterEngine;
......@@ -96,6 +102,14 @@ private:
void UpdateMotionStates();
void UpdateTrajectories( double dTime );
int mNumberofPaths;
std::vector<ITABase::CThirdOctaveGainMagnitudeSpectrum> mMags; //internal vector of target magnitude spectrums for IIR filter design
//vector elements correspond to the path number
std::map< int, CVABinauralOutdoorWaveFront* > m_mCurrentWaveFronts;
};
#endif // VACORE_WITH_RENDERER_BINAURAL_OUTDOOR_NOISE
......
#include "VABinauralOutdoorWaveFront.h"
#include "VABinauralOutdoorSource.h"
#include "../Clustering/VARelationMetrics.h"
#include "../Clustering/VAConfig.h"
......@@ -71,6 +73,10 @@ void CVABinauralOutdoorWaveFront::GetOutput( ITASampleBuffer* pfLeftChannel, ITA
//vdlChL->SetDelayTime( toaDistance );
//vdlChR->SetDelayTime( toaDistance );
iCursorID;
int iNumSamples;
//pSource->pVDL->Read( iCursorID, iNumSamples); // take data from VDL to be forwarded to IIR
vdlChL->Process( pData->pSignalSourceInputBuf, pfLeftChannel );
vdlChL->Process( pData->pSignalSourceInputBuf, pfRightChannel );
......@@ -85,3 +91,9 @@ void CVABinauralOutdoorWaveFront::SetClusteringPose( const VAVec3& v3Pos, const
m_v3PredictedClusteringView = v3View;
m_v3PredictedClusteringUp = v3Up;
}
void CVABinauralOutdoorWaveFront::setParameters(const CVAStruct &oInArgs) {
}
......@@ -6,6 +6,8 @@
#include <VAPoolObject.h>
#include "../Clustering/WaveFront/VABinauralWaveFront.h"
#include <ITAThirdOctaveMagnitudeSpectrum.h>
// Forwards
class CVASoundSourceState;
......@@ -13,6 +15,7 @@ class CVASoundSourceDesc;
class CVASharedMotionModel;
class CITAVariableDelayLine;
class ITASampleBuffer;
class CVABinauralOutdoorSource;
//! Represents a wave front emitted from a sound source for an outdoor scenario
/**
......@@ -22,6 +25,10 @@ class CVABinauralOutdoorWaveFront : public IVABinauralWaveFront, public CVAPoolO
{
public:
CVABinauralOutdoorSource* pSource;
int iCursorID;
bool hasValidTrajectory;
const CVABinauralWaveFrontBase::Config oConf;
......@@ -45,6 +52,8 @@ public:
void GetOutput( ITASampleBuffer* pfLeftChannel, ITASampleBuffer* pfRightChannel );
void SetClusteringPose( const VAVec3& v3Pos, const VAVec3& v3View, const VAVec3& v3Up );
void setParameters( const CVAStruct &oInArgs );
virtual bool GetValidTrajectory() const
{
......@@ -70,6 +79,8 @@ private:
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
ITABase::CThirdOctaveGainMagnitudeSpectrum fMags;
};
#endif // IW_VACORE_BINAURAL_OUTDOOR_WAVE_FRONT
......@@ -6,6 +6,8 @@ set( DirFiles
VABinauralOutdoorNoiseAudioRenderer.cpp
VABinauralOutdoorWaveFront.h
VABinauralOutdoorWaveFront.cpp
VABinauralOutdoorSource.h
VABinauralOutdoorSource.cpp
VABinauralOutdoorWaveFrontPoolFactory.h
VABinauralOutdoorWaveFrontPoolFactory.cpp
_SourceFiles.cmake
......
......@@ -484,7 +484,7 @@ void CVAPTImageSourceAudioRenderer::CalculateImageSourceImpulseResponse(ITASampl
//scale amplitude
*/
//======================================================================================================
if (pDAFFDirectivityListener) { //if there is a receiver directivity
......
......@@ -98,7 +98,9 @@ int main()
// Just name a folder with a lot ofs WAV clips
va->AddSearchPath( "../data" );
std::string sWAVCLipsFolder = "C:/Users/jonas/sciebo/ITA/Lehre/Masterarbeiten/2018 Lucas Msch/2018 MA Lucas Msch Auralization/input_files"; // no tailing '/'
//std::string sWAVCLipsFolder = "C:/Users/jonas/sciebo/ITA/Lehre/Masterarbeiten/2018 Lucas Msch/2018 MA Lucas Msch Auralization/input_files"; // no tailing '/'
std::string sWAVCLipsFolder = "C:/Users/andrew/input_files"; // no tailing '/'
va->AddSearchPath( sWAVCLipsFolder );
std::vector<std::string> vFileNames = GetFileNamesInDirectory( sWAVCLipsFolder + "/*.wav" );
......
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