Commit bb7f2ad7 authored by lmoesch's avatar lmoesch

Pre final

parent f2aaa7dc
#define NOMINMAX
#include <stdlib.h>
#include <math.h>
#include "VABinauralCluster.h"
......@@ -20,42 +21,21 @@ VABinauralCluster::VABinauralCluster()
{
_output = new ITASampleFrame(2, VAConfig::blockLength, true);
_tempHRIR = new ITASampleFrame(2, VAConfig::hrirLength, true);
// initialize left channel convolver for each cluster
_FIRConvolverChL = new ITAUPConvolution(VAConfig::blockLength, VAConfig::hrirLength);
_FIRConvolverChL->SetFilterExchangeFadingFunction(ITABase::FadingFunction::COSINE_SQUARE);
_FIRConvolverChL->SetFilterCrossfadeLength((std::min)(VAConfig::blockLength, 32));
_FIRConvolverChL->SetGain(1.0f, true);
ITAUPFilter* HRIRFilterChL = _FIRConvolverChL->RequestFilter();
HRIRFilterChL->identity();
_FIRConvolverChL->ExchangeFilter(HRIRFilterChL);
// initialize right channel convolver for each cluster
_FIRConvolverChR = new ITAUPConvolution(VAConfig::blockLength, VAConfig::hrirLength);
_FIRConvolverChR->SetFilterExchangeFadingFunction(ITABase::FadingFunction::COSINE_SQUARE);
_FIRConvolverChR->SetFilterCrossfadeLength((std::min)(VAConfig::blockLength, 32));
_FIRConvolverChR->SetGain(1.0f, true);
ITAUPFilter* HRIRFilterChR = _FIRConvolverChR->RequestFilter();
HRIRFilterChR->identity();
_FIRConvolverChR->ExchangeFilter(HRIRFilterChR);
}
VABinauralCluster::~VABinauralCluster()
{}
void
VABinauralCluster::init(int sourceID, VABinauralSoundSource* source, VABinauralListener* listener)
VABinauralCluster::init(int sourceID, VABinauralSoundSource* source, VABinauralListener* listener, ITAUPConvolution* firL, ITAUPConvolution* firR)
{
_listener = listener;
_listenerPos = listener->predPos;
_clusterSourcePos = _clusterSourcePos + source->predPos;
_clusterSourceToListenerPos = _clusterSourcePos - _listenerPos;
_clusterSourcePos = source->predPos - listener->predPos;
_clusterSourcePos.Norm();
_FIRConvolverChL = firL;
_FIRConvolverChR = firR;
int outputLength = listener->output->GetLength();
if (_output->length() != outputLength) _output->init(2, outputLength, true);
......@@ -79,9 +59,7 @@ void
VABinauralCluster::init(VABinauralCluster* cluster)
{
_listener = cluster->_listener;
_listenerPos = _listener->predPos;
_clusterSourcePos = cluster->_clusterSourcePos;
_clusterSourceToListenerPos = _clusterSourcePos - _listenerPos;
int outputLength = _listener->output->GetLength();
......@@ -90,16 +68,7 @@ VABinauralCluster::init(VABinauralCluster* cluster)
_tmpChL.Init(_listener->output->GetLength(), true);
_tmpChR.Init(_listener->output->GetLength(), true);
maxError = cluster->maxError;
std::map< int, VABinauralSoundSource*>::const_iterator it;
for (it = cluster->_sources.begin(); it != cluster->_sources.end(); ++it)
{
_sources.insert(std::pair<int, VABinauralSoundSource*>(it->first, it->second));
it->second->AddReference();
}
numSources = cluster->numSources;
numSources = 0;
}
ITASampleFrame*
......@@ -110,10 +79,13 @@ VABinauralCluster::getOutput()
// get cluster HRTF TOA
VARelationMetrics clusterSourceMetrics;
clusterSourceMetrics.calc(_listener->predPos, _listener->predView, _listener->predUp, _clusterSourcePos);
clusterSourceMetrics.calc(_listener->predPos, _listener->predView, _listener->predUp, _listener->predPos + _clusterSourcePos);
// double toaHRTFChL = _listener->toaEstimator->getTOALeft(clusterSourceMetrics.phi, clusterSourceMetrics.theta);
// double toaHRTFChR = _listener->toaEstimator->getTOARight(clusterSourceMetrics.phi, clusterSourceMetrics.theta);
double toaHRTFChL = _listener->toaEstimator->getTOALeft(clusterSourceMetrics.phi, clusterSourceMetrics.theta);
double toaHRTFChR = _listener->toaEstimator->getTOARight(clusterSourceMetrics.phi, clusterSourceMetrics.theta);
double toaHRTFChL = _listener->toaEstimator->getTOA(VAVec3(-1, 0, 0), _clusterSourcePos);
double toaHRTFChR = _listener->toaEstimator->getTOA(VAVec3(1, 0, 0), _clusterSourcePos);
// set VDL Values
std::map<int, VABinauralSoundSource*>::const_iterator it;
......@@ -126,13 +98,19 @@ VABinauralCluster::getOutput()
sourceMetrics.calc(_listener->predPos, _listener->predView, _listener->predUp, source->predPos);
double toaDistance = sourceMetrics.dist / 343; // TODO: Medium Propagation....
double toaSourceChL = _listener->toaEstimator->getTOALeft(sourceMetrics.phi, sourceMetrics.theta);
double toSourceaChR = _listener->toaEstimator->getTOARight(sourceMetrics.phi, sourceMetrics.theta);
//double toaSourceChL = _listener->toaEstimator->getTOALeft(sourceMetrics.phi, sourceMetrics.theta);
//double toSourceaChR = _listener->toaEstimator->getTOARight(sourceMetrics.phi, sourceMetrics.theta);
double toaSourceChL = _listener->toaEstimator->getTOA(VAVec3(-1, 0, 0), source->predPos -_listener->predPos);
double toaSourceChR = _listener->toaEstimator->getTOA(VAVec3(1, 0, 0), source->predPos - _listener->predPos);
float gain = float(1/sourceMetrics.dist * source->state->GetVolume(VAConfig::amplitudeCalibration));
float gain = float((1/sourceMetrics.dist) * source->state->GetVolume(VAConfig::amplitudeCalibration));
source->vdlChL->SetDelayTime(toaDistance + toaSourceChL - toaHRTFChL);
source->vdlChR->SetDelayTime(toaDistance + toSourceaChR - toaHRTFChR);
// source->vdlChL->SetDelayTime(std::max(0., toaDistance + toaSourceChL - toaHRTFChL));
// source->vdlChR->SetDelayTime(std::max(0., toaDistance + toaSourceChR - toaHRTFChR));
source->vdlChL->SetDelayTime(toaDistance);
source->vdlChR->SetDelayTime(toaDistance);
source->vdlChL->Process(input, &(_tmpChL));
source->vdlChR->Process(input, &(_tmpChR));
......@@ -150,17 +128,25 @@ VABinauralCluster::getOutput()
ITAUPFilter* HRIRFilterChL = _FIRConvolverChL->GetFilterPool()->RequestFilter();
ITAUPFilter* HRIRFilterChR = _FIRConvolverChR->GetFilterPool()->RequestFilter();
HRIRFilterChL->Zeros();
HRIRFilterChR->Zeros();
if (HRIR){
int index = -1;
int filterLength = 0;
filterLength = HRIR->GetProperties()->iFilterLength;
_tempHRIR->init(2, filterLength, true);
if (_tempHRIR->length() != filterLength)
{
_tempHRIR->init(2, filterLength, false);
}
float phi = clusterSourceMetrics.phi * 180 / ITAConstants::PI_F;
float theta = clusterSourceMetrics.theta * 180 / ITAConstants::PI_F;
HRIR->GetHRIR(_tempHRIR, clusterSourceMetrics.phi * 180 / ITAConstants::PI_F, clusterSourceMetrics.theta * 180 / ITAConstants::PI_F, clusterSourceMetrics.dist);
HRIRFilterChL->Load((*_tempHRIR)[0].data(), filterLength);
......@@ -181,7 +167,7 @@ VABinauralCluster::getOutput()
double
VABinauralCluster::getDistError(VABinauralSoundSource* source)
{
VAVec3 sourceToListenerPos = source->predPos - _listenerPos;
VAVec3 sourceToListenerPos = source->predPos - _listener->predPos;
VAVec3 dist;
sourceToListenerPos.Norm();
......@@ -202,7 +188,6 @@ VABinauralCluster::addSource(int sourceID, VABinauralSoundSource* source)
_clusterSourcePos = _clusterSourcePos + (sourceToListenerPos - _clusterSourcePos) / (numSources + 1);
_clusterSourcePos.Norm();
_clusterSourceToListenerPos = _clusterSourcePos - _listenerPos;
maxError = std::max(err, maxError);
......
......@@ -23,7 +23,7 @@ public:
~VABinauralCluster();
void
init(int sourceID, VABinauralSoundSource* source, VABinauralListener* listener);
init(int sourceID, VABinauralSoundSource* source, VABinauralListener* listener, ITAUPConvolution* firL, ITAUPConvolution* firR);
void
init(VABinauralCluster* cluster);
......@@ -57,7 +57,7 @@ private:
ITASampleFrame* _tempHRIR;
VABinauralListener* _listener;
ITAUPConvolution* _FIRConvolverChL;
ITAUPConvolution* _FIRConvolverChR;
......
......@@ -2,7 +2,7 @@
#include <limits>
#include <algorithm>
#include <memory>
#include <math.h>
// VA
......@@ -12,6 +12,7 @@
#include <ITAUPFilter.h>
// Utils
#include "../Config/VAConfig.h"
#include "./VABinauralClustering.h"
#include "./VABinauralClusterPoolFactory.h"
......@@ -41,11 +42,44 @@ VABinauralClustering::init(int listenerID, VABinauralListener* listener, int num
_listenerID = listenerID;
_listener = listener;
_numClusters = numClusters;
_threshold = 1. / numClusters;
_threshold = 4. / numClusters;
_output = new ITASampleFrame(2, listener->output->GetLength(), true);
_curState.reset(new VABinauralClusteringState(_numClusters, _listener, clusterPool));
for (int i = 0; i < numClusters; ++i)
{
// initialize left channel convolver for each cluster
ITAUPConvolution * _FIRConvolverChL = new ITAUPConvolution(VAConfig::blockLength, VAConfig::hrirLength);
_FIRConvolverChL->SetFilterExchangeFadingFunction(ITABase::FadingFunction::COSINE_SQUARE);
_FIRConvolverChL->SetFilterCrossfadeLength((std::min)(VAConfig::blockLength, 32));
_FIRConvolverChL->SetGain(1.0f, true);
ITAUPFilter* HRIRFilterChL = _FIRConvolverChL->RequestFilter();
HRIRFilterChL->identity();
_FIRConvolverChL->ExchangeFilter(HRIRFilterChL);
_FIRConvolverChL->ReleaseFilter(HRIRFilterChL);
FIRConvolversL.insert(std::pair< int, ITAUPConvolution* >(i, _FIRConvolverChL));
// initialize right channel convolver for each cluster
ITAUPConvolution * _FIRConvolverChR = new ITAUPConvolution(VAConfig::blockLength, VAConfig::hrirLength);
_FIRConvolverChR->SetFilterExchangeFadingFunction(ITABase::FadingFunction::COSINE_SQUARE);
_FIRConvolverChR->SetFilterCrossfadeLength((std::min)(VAConfig::blockLength, 32));
_FIRConvolverChR->SetGain(1.0f, true);
ITAUPFilter* HRIRFilterChR = _FIRConvolverChR->RequestFilter();
HRIRFilterChR->identity();
_FIRConvolverChR->ExchangeFilter(HRIRFilterChR);
_FIRConvolverChR->ReleaseFilter(HRIRFilterChR);
FIRConvolversR.insert(std::pair< int, ITAUPConvolution* >(i, _FIRConvolverChR));
}
_curState.reset(new VABinauralClusteringState(_numClusters, _listener, clusterPool, &FIRConvolversL, &FIRConvolversR));
_prevState = _curState;
}
ITASampleFrame*
......@@ -54,7 +88,7 @@ VABinauralClustering::getOutput()
_output->zero();
// swap out clustering state
if (_nextState != nullptr){
_curState.reset(_nextState.release());
_curState = _nextState;
};
std::map< int, VABinauralCluster*>::const_iterator clusterIt;
......@@ -76,8 +110,10 @@ VABinauralClustering::update()
// if (_nextState == nullptr)
// {
VABinauralClusteringState* state = new VABinauralClusteringState(_numClusters, _listener, clusterPool); //new VABinauralClusteringState(*_curState);
//VABinauralClusteringState* state = new VABinauralClusteringState(_numClusters, _listener, clusterPool, FIRConvolversL, FIRConvolversR); //new VABinauralClusteringState(*_curState);
//std::shared_ptr<VABinauralClusteringState> state = std::make_shared<VABinauralClusteringState>(*_prevState);
std::shared_ptr<VABinauralClusteringState> state = std::make_shared<VABinauralClusteringState>(_numClusters, _listener, clusterPool, &FIRConvolversL, &FIRConvolversR);
// remove removed sources
std::set< int >::const_iterator it;
......@@ -118,7 +154,8 @@ VABinauralClustering::update()
//_unassignedSources.clear();
_nextState.reset(state);
_nextState = state;
_prevState = _nextState;
// }
}
......
......@@ -7,6 +7,9 @@
#include <VA.h>
#include <VAPoolObject.h>
// Ita includes
#include <ITAUPConvolution.h>
// Utils
#include "VABinauralCluster.h"
#include "VABinauralClusteringState.h"
......@@ -40,6 +43,9 @@ public:
void
removeSource(int sourceID);
std::map<int, ITAUPConvolution* > FIRConvolversL;
std::map<int, ITAUPConvolution* > FIRConvolversR;
private:
int _listenerID;
......@@ -51,8 +57,9 @@ private:
std::set< int > _delSourceIDs;
std::unique_ptr<VABinauralClusteringState> _curState;
std::unique_ptr<VABinauralClusteringState> _nextState;
std::shared_ptr<VABinauralClusteringState> _curState;
std::shared_ptr<VABinauralClusteringState> _prevState;
std::shared_ptr<VABinauralClusteringState> _nextState;
std::map< int, VABinauralSoundSource* > _unassignedSources;
std::map< int, VABinauralSoundSource* > _assignedSources;
......
......@@ -10,10 +10,12 @@
#include "./VABinauralClusterPoolFactory.h"
VABinauralClusteringState::VABinauralClusteringState(int numClusters, VABinauralListener* listener, IVAObjectPool* clusterPool) :
VABinauralClusteringState::VABinauralClusteringState(int numClusters, VABinauralListener* listener, IVAObjectPool* clusterPool, std::map<int, ITAUPConvolution* > *FIRConvolversL, std::map<int, ITAUPConvolution* > *FIRConvolversR) :
numClusters(numClusters),
listener(listener),
_clusterPool(clusterPool)
_clusterPool(clusterPool),
_FIRConvolversL(FIRConvolversL),
_FIRConvolversR(FIRConvolversR)
{
for (int i = numClusters - 1; i >= 0; --i)
......@@ -27,7 +29,9 @@ VABinauralClusteringState::VABinauralClusteringState(const VABinauralClusteringS
listener(state.listener),
sourceClusterReference(state.sourceClusterReference),
freeClusterIDs(state.freeClusterIDs),
_clusterPool(state._clusterPool)
_clusterPool(state._clusterPool),
_FIRConvolversL(state._FIRConvolversL),
_FIRConvolversR(state._FIRConvolversR)
{
std::map< int, VABinauralCluster* >::const_iterator it;
......@@ -104,7 +108,7 @@ VABinauralClusteringState::createCluster(int sourceID, VABinauralSoundSource* s
int clusterID = freeClusterIDs.front();
VABinauralCluster* cluster = dynamic_cast< VABinauralCluster* >(_clusterPool->RequestObject()); // Reference = 1
cluster->init(sourceID, source, listener);
cluster->init(sourceID, source, listener, _FIRConvolversL->find(clusterID)->second, _FIRConvolversR->find(clusterID)->second);
clusters.insert(std::pair< int, VABinauralCluster* >(clusterID, cluster));
freeClusterIDs.pop();
......
......@@ -24,9 +24,12 @@ public:
std::map< int, int> sourceClusterReference;
std::map< int, VABinauralCluster* > clusters;
std::map<int, ITAUPConvolution* > *_FIRConvolversL;
std::map<int, ITAUPConvolution* > *_FIRConvolversR;
VABinauralListener* listener;
VABinauralClusteringState(int numClusters, VABinauralListener* listener, IVAObjectPool* clusterPool);
VABinauralClusteringState(int numClusters, VABinauralListener* listener, IVAObjectPool* clusterPool, std::map<int, ITAUPConvolution* > *FIRConvolversL, std::map<int, ITAUPConvolution* > *FIRConvolversR);
VABinauralClusteringState(const VABinauralClusteringState& state);
......
......@@ -4,8 +4,8 @@
VABinauralSoundSource::VABinauralSoundSource(const config_t& conf) :
conf( conf )
{
vdlChL = new CITAVariableDelayLine(conf.sampleRate, conf.blockLength, 3. * conf.sampleRate, CITAVariableDelayLine::SWITCH);
vdlChR = new CITAVariableDelayLine(conf.sampleRate, conf.blockLength, 3. * conf.sampleRate, CITAVariableDelayLine::SWITCH);
vdlChL = new CITAVariableDelayLine(conf.sampleRate, conf.blockLength, 3. * conf.sampleRate, CITAVariableDelayLine::CUBIC_SPLINE_INTERPOLATION);
vdlChR = new CITAVariableDelayLine(conf.sampleRate, conf.blockLength, 3. * conf.sampleRate, CITAVariableDelayLine::CUBIC_SPLINE_INTERPOLATION);
}
......
#define _USE_MATH_DEFINES
#define SPEEDOFSOUND 343
#define HEADRADIUS 0.06
#define HEADRADIUS 0.09
#define DELAY (HEADRADIUS / SPEEDOFSOUND)
#include <VA.h>
#include "VABinauralTOAEstimator.h"
#include <math.h>
......@@ -18,6 +20,27 @@ VABinauralTOAEstimator::~VABinauralTOAEstimator()
{
}
double
VABinauralTOAEstimator::getTOA(VAVec3 &ear, VAVec3 & source)
{
VAVec3 _ear = VAVec3(ear);
VAVec3 _source = VAVec3(source);
_ear.Norm();
_source.Norm();
double alpha = std::acos(_ear.Dot(_source));
if (alpha <= M_PI)
{
return DELAY * (1 - cos(alpha));
}
else
{
return DELAY * (1 + alpha - M_PI / 2);
}
}
double
VABinauralTOAEstimator::getTOALeft(double phi, double theta)
{
......
#ifndef IW_VACORE_BINAURALTIMEOFARRIVALESTIMATOR
#define IW_VACORE_BINAURALTIMEOFARRIVALESTIMATOR
#include <VA.h>
class VABinauralTOAEstimator
{
public:
......@@ -10,6 +12,9 @@ public:
double
getTOALeft(double phi, double theta);
double
getTOA(VAVec3 &ear, VAVec3 & source);
double
getTOARight(double phi, double theta);
};
......
......@@ -148,15 +148,15 @@ VABinauralRealTimeRenderer::ProcessStream(const ITAStreamInfo* streamInfo)
{
//BENCHMARK
//auto start = std::chrono::high_resolution_clock::now();
LARGE_INTEGER frequency; // ticks per second
LARGE_INTEGER t1, t2; // ticks
double elapsedTime;
//LARGE_INTEGER frequency; // ticks per second
//LARGE_INTEGER t1, t2; // ticks
//double elapsedTime;
// get ticks per second
QueryPerformanceFrequency(&frequency);
//QueryPerformanceFrequency(&frequency);
// start timer
QueryPerformanceCounter(&t1);
//QueryPerformanceCounter(&t1);
/////
ITASampleFrame* output;
......@@ -169,7 +169,7 @@ VABinauralRealTimeRenderer::ProcessStream(const ITAStreamInfo* streamInfo)
const CVAAudiostreamState* streamState = dynamic_cast< const CVAAudiostreamState* >(streamInfo);
double time = streamState->dSysTime;
updateTrajectories(time);
//updateTrajectories(time);
// -- create output for every listener
for (auto const& clusteringIt : _clusterEngine->_clusterings)
......@@ -184,14 +184,14 @@ VABinauralRealTimeRenderer::ProcessStream(const ITAStreamInfo* streamInfo)
//BENCHMARK
// stop timer
QueryPerformanceCounter(&t2);
//QueryPerformanceCounter(&t2);
// compute and print the elapsed time in millisec
elapsedTime = (t2.QuadPart - t1.QuadPart) * 1000.0 / frequency.QuadPart;
//elapsedTime = (t2.QuadPart - t1.QuadPart) * 1000.0 / frequency.QuadPart;
std::ofstream outfile("X:/Sciebo/master-thesis/data/benchmarks/Stream_128.txt", std::fstream::app);
outfile << elapsedTime << std::endl;
outfile.close();
//std::ofstream outfile("X:/Sciebo/master-thesis/data/benchmarks/Stream_128.txt", std::fstream::app);
//outfile << elapsedTime << std::endl;
//outfile.close();
////
IncrementWritePointer();
......@@ -215,15 +215,15 @@ VABinauralRealTimeRenderer::UpdateScene(CVASceneState* newSceneState)
_newSceneState->Diff(_curSceneState, &diff);
//BENCHMARK
LARGE_INTEGER frequency; // ticks per second
LARGE_INTEGER t1, t2; // ticks
double elapsedTime;
//LARGE_INTEGER frequency; // ticks per second
//LARGE_INTEGER t1, t2; // ticks
//double elapsedTime;
// get ticks per second
QueryPerformanceFrequency(&frequency);
//QueryPerformanceFrequency(&frequency);
// start timer
QueryPerformanceCounter(&t1);
//QueryPerformanceCounter(&t1);
// update listeners
updateListeners(&diff);
......@@ -235,14 +235,14 @@ VABinauralRealTimeRenderer::UpdateScene(CVASceneState* newSceneState)
//BENCHMARK
// stop timer
QueryPerformanceCounter(&t2);
//QueryPerformanceCounter(&t2);
// compute and print the elapsed time in millisec
elapsedTime = (t2.QuadPart - t1.QuadPart) * 1000.0 / frequency.QuadPart;
//elapsedTime = (t2.QuadPart - t1.QuadPart) * 1000.0 / frequency.QuadPart;
std::ofstream outfile("X:/Sciebo/master-thesis/data/benchmarks/UpdateScene_128.txt", std::fstream::app);
outfile << elapsedTime << std::endl;
outfile.close();
//std::ofstream outfile("X:/Sciebo/master-thesis/data/benchmarks/UpdateScene_128.txt", std::fstream::app);
//outfile << elapsedTime << std::endl;
//outfile.close();
// Alte Szene freigeben (dereferenzieren)
if (_curSceneState) _curSceneState->RemoveReference();
......@@ -302,20 +302,18 @@ VABinauralRealTimeRenderer::updateSources( CVASceneStateDiff* diff )
{
source->motionModel->InputMotionKey(motionNew);
// Dirty Hack
if (!source->hasValidTrajectory)
{
VAVec3 pos = motionNew->GetPosition();
VAVec3 pos = motionNew->GetPosition();
if (pos != VAVec3(0, 0, 0))
{
VAVec3 view = motionNew->GetView();
VAVec3 up = motionNew->GetUp();
source->predPos = pos;
source->predView = view;
source->predUp = up;
source->hasValidTrajectory = true;
}
if (pos != VAVec3(0, 0, 0))
{
VAVec3 view = motionNew->GetView();
VAVec3 up = motionNew->GetUp();
source->predPos = pos;
source->predView = view;
source->predUp = up;
source->hasValidTrajectory = true;
}
}
}
......@@ -355,6 +353,20 @@ VABinauralRealTimeRenderer::updateListeners( CVASceneStateDiff* diff )
if (motionNew && (motionNew != motionCur))
{
listener->motionModel->InputMotionKey(motionNew);
// Dirty Hack
VAVec3 pos = motionNew->GetPosition();
if (pos != VAVec3(0, 0, 0))
{
VAVec3 view = motionNew->GetView();
VAVec3 up = motionNew->GetUp();
listener->predPos = pos;
listener->predView = view;
listener->predUp = up;
listener->hasValidTrajectory = true;
}
}
if (listenerNew != nullptr)
......@@ -421,7 +433,7 @@ VABinauralRealTimeRenderer::createListener(int listenerID, const CVAReceiverStat
_listeners.insert(std::pair< int, VABinauralListener* >(listenerID, listener));
// add listener to clustering
VABinauralClusterEngine::clusterConfig_t config = { /*numClusters=*/ 128};
VABinauralClusterEngine::clusterConfig_t config = { /*numClusters=*/ 12};
_clusterEngine->addListener(listenerID, listener, config);
}
......
#define _USE_MATH_DEFINES
#include <Windows.h>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <iostream>
#include <VA.h>
#include <VACore.h>
#include <VistaBase/VistaTimeUtils.h>
IVAInterface* va = NULL;
CVAStruct time;
CVAStruct trigger;
int nSources = 100;
CVAStruct GetCoreConfig()
{
CVAStruct oConfig;
std::vector<std::string> ssIDs;
std::vector< int > viSourceIDs(nSources);
CVAStruct oSectionDebug;
oSectionDebug["loglevel"] = 5;
oConfig["debug"] = oSectionDebug;
std::vector<std::string> GetFileNamesInDirectory(std::string directory) {
std::vector<std::string> files;
WIN32_FIND_DATA fileData;
HANDLE hFind;
if (!((hFind = FindFirstFile(directory.c_str(), &fileData)) == INVALID_HANDLE_VALUE)) {
while (FindNextFile(hFind, &fileData)) {
files.push_back(fileData.cFileName);
}
}
CVAStruct oSectionDriver;
oSectionDriver["driver"] = "Portaudio";
oConfig["audio driver"] = oSectionDriver;
FindClose(hFind);
return files;
}
CVAStruct oDevice1;
oDevice1["type"] = "HP";
oDevice1["channels"] = "1,2";
oConfig["OutputDevice:MyHP"] = oDevice1;
void SetupScene()
{
for (int i = 0; i < nSources; ++i)
{
float azimuth = ((rand() % 3600) / 1800.0) * M_PI;
float elevation = ((rand() % 900) / 1800.0) * M_PI;
CVAStruct oOutput1;
oOutput1["devices"] = "MyHP";
oConfig["Output:MyDesktopHP"] = oOutput1;
float x = sin(elevation) * cos(azimuth) * 5;
float y = cos(elevation) * 5;
float z = sin(azimuth) * sin(elevation) * 5;
CVAStruct oReproduction1;
oReproduction1["class"] = "Talkthrough";
oReproduction1["outputs"] = "MyDesktopHP";
oConfig["Reproduction:Talkthrough"] = oReproduction1;
std::string source_name = "itaVA_Source_" + std::to_string(i);
viSourceIDs[i] = va->CreateSoundSource(source_name);
CVAStruct oRenderer1;
oRenderer1["class"] = "BinauralRealTime";
oRenderer1["Reproductions"] = "MyTalkthroughHeadphones";
oConfig["Renderer:BRT_CoreTest"] = oRenderer1;
va->SetSoundSourceSignalSource(viSourceIDs[i], ssIDs[rand() % ssIDs.size()]);
va->SetSoundSourcePosition(viSourceIDs[i], VAVec3(x, 1.7 + y, z));
}
return oConfig;
}
class EventBasedGenericRenderingController : public IVAEventHandler
void Scene2()
{
public:
inline void HandleVAEvent(const CVAEvent* pEvent)
for (int i = 0; i < nSources; ++i)
{
if (pEvent->iEventType & CVAEvent::SOUND_RECEIVER_CHANGED_POSE)
float z = static_cast <float> (rand()) / (static_cast <float> (RAND_MAX / 24));
std::string source_name = "itaVA_Source_" + std::to_string(i);
viSourceIDs[i] = va->CreateSoundSource(source_name);
va->SetSoundSourceSignalSource(viSourceIDs[i], ssIDs[rand() % ssIDs.size()]);