From 8b5ab99357adc7000c94ae830a22decc9a8ffb41 Mon Sep 17 00:00:00 2001 From: lmoesch Date: Tue, 13 Nov 2018 22:05:35 +0100 Subject: [PATCH] WIP --- .../core/VACoreSourceManagementBenchmark.cpp | 92 +++++++++++++++---- .../VABinauralCluster.cpp | 35 +++++-- .../VABinauralClustering.cpp | 2 +- .../RealTime/VABinauralRealTimeRenderer.cpp | 56 ++++++++++- 4 files changed, 156 insertions(+), 29 deletions(-) diff --git a/benchmarks/core/VACoreSourceManagementBenchmark.cpp b/benchmarks/core/VACoreSourceManagementBenchmark.cpp index 47f8a20..26b009b 100644 --- a/benchmarks/core/VACoreSourceManagementBenchmark.cpp +++ b/benchmarks/core/VACoreSourceManagementBenchmark.cpp @@ -1,12 +1,19 @@ + +#define _USE_MATH_DEFINES + #include #include +#include #include #include +#include #include #include +#include + using namespace std; CVAStruct GetCoreConfig() @@ -14,16 +21,19 @@ CVAStruct GetCoreConfig() CVAStruct oConfig; CVAStruct oSectionDebug; - oSectionDebug["loglevel"] = 5; + oSectionDebug["loglevel"] = 0; oConfig["debug"] = oSectionDebug; CVAStruct oSectionDriver; - oSectionDriver["driver"] = "Portaudio"; + oSectionDriver["driver"] = "Virtual"; + oSectionDriver["buffersize"] = 64; + oSectionDriver["outputchannels"] = 2; oConfig["audio driver"] = oSectionDriver; CVAStruct oDevice1; - oDevice1["type"] = "HP"; + oDevice1["type"] = "Trigger"; oDevice1["channels"] = "1,2"; + oConfig["OutputDevice:MyHP"] = oDevice1; CVAStruct oOutput1; @@ -44,35 +54,79 @@ CVAStruct GetCoreConfig() return oConfig; } +CVAStruct time; +CVAStruct trigger; + int main( int, char** ) { IVAInterface* pCore = NULL; try { + pCore = VACore::CreateCoreInstance(GetCoreConfig()); + pCore->Initialize(); + int iterations = 10; + int _parallelSources = 1000; - pCore = VACore::CreateCoreInstance( GetCoreConfig()); - pCore->Initialize(); + double clock = 0; + double timestep = 64 / 44100.; + + //auto d = pCore->CreateDire + + int receiverID = pCore->CreateSoundReceiver("ITAListener"); + int directivityID = pCore->CreateDirectivityFromFile("C:/dev/VA/VACore/data/ITA_Artificial_Head_5x5_44kHz_128.v17.ir.daff", "HRTF"); + pCore->SetSoundReceiverDirectivity(receiverID, directivityID); + + pCore->LockUpdate(); + + std::vector< int > viSourceIDs(_parallelSources); + + for (int k = 0; k < _parallelSources; k++) + { - int iIterations = 100; - int iMaxNumParallelSources = 200; - for( int i = 1; i < iMaxNumParallelSources; i++ ) + viSourceIDs[k] = pCore->CreateSoundSource("BenchmarkSoundSource"); + } + pCore->UnlockUpdate(); + + for (int j = 0; j < iterations; j++) { - ITAStopWatch swIterations; - for( int j = 0; j < iIterations; j++ ) + pCore->LockUpdate(); + for (int k = 0; k < (_parallelSources); k++) { - swIterations.start(); - std::vector< int > viSourceIDs( i ); - for( int k = 0; k < i; k++ ) - viSourceIDs[ k ] = pCore->CreateSoundSource( "BenchmarkSoundSource" ); - //pCore->SetSoundSourcePosition(k, ) - for( int k = 0; k < i; k++ ) - pCore->DeleteSoundSource( viSourceIDs[ k ] ); - swIterations.stop(); + + float azimuth = ((rand() % 3600) / 1800.0) * M_PI; + float elevation = ((rand() % 1800) / 1800.0) * M_PI; + + float x = sin(elevation) * cos(azimuth) * 5; + float y = cos(elevation) * 5; + float z = sin(azimuth) * sin(elevation) * 5; + pCore->SetSoundSourcePosition(viSourceIDs[k], VAVec3(x, y, z)); } - cout << "Statistics for " << i << " parallel source: " << swIterations.ToString() << endl; + pCore->UnlockUpdate(); + _sleep(100); + } + + string audio = pCore->CreateSignalSourceBufferFromFile("X:/Sciebo/2018 MA Lucas Mösch Auralization/input_files/Schluesselbund.wav"); + pCore->SetSignalSourceBufferPlaybackAction(audio, 2); + pCore->SetSignalSourceBufferLooping(audio, true); + + for (int k = 0; k < _parallelSources; k++) + { + pCore->SetSoundSourceSignalSource(viSourceIDs[k], audio); } + _sleep(2000); + + for (int j = 0; j < iterations; j++) + { + clock += timestep; + time["time"] = clock; + pCore->CallModule("manualclock", time); + + trigger["trigger"] = true; + pCore->CallModule("virtualaudiodevice", trigger); + } + delete pCore; } diff --git a/src/Rendering/Binaural/RealTime/Utils/BinauralClusterEngine/VABinauralCluster.cpp b/src/Rendering/Binaural/RealTime/Utils/BinauralClusterEngine/VABinauralCluster.cpp index eb4b129..c2eeb49 100644 --- a/src/Rendering/Binaural/RealTime/Utils/BinauralClusterEngine/VABinauralCluster.cpp +++ b/src/Rendering/Binaural/RealTime/Utils/BinauralClusterEngine/VABinauralCluster.cpp @@ -60,9 +60,11 @@ VABinauralCluster::init(int sourceID, VABinauralSoundSource* source, VABinauralL if (_output->length() != outputLength) _output->init(2, outputLength, true); - _tmpChL.Init(listener->output->GetLength(), true); - _tmpChR.Init(listener->output->GetLength(), true); - + if (_tmpChL.length() != outputLength){ + _tmpChL.Init(outputLength, true); + _tmpChR.Init(outputLength, true); + } + maxError = getDistError(source); _sources.insert(std::pair(sourceID, source)); @@ -180,17 +182,26 @@ double VABinauralCluster::getDistError(VABinauralSoundSource* source) { VAVec3 sourceToListenerPos = source->predPos - _listenerPos; - double dotp = _clusterSourceToListenerPos.Dot(sourceToListenerPos); + VAVec3 dist; + + sourceToListenerPos.Norm(); + + dist = sourceToListenerPos - _clusterSourcePos; - return (dotp * dotp) / (_clusterSourcePos.Dot(_clusterSourcePos) * sourceToListenerPos.Dot(sourceToListenerPos)); + return dist.Dot(dist); } void VABinauralCluster::addSource(int sourceID, VABinauralSoundSource* source) { + VAVec3 sourceToListenerPos = source->predPos - _listenerPos; double err = getDistError(source); - _clusterSourcePos = (source->predPos + _clusterSourcePos * numSources) / (numSources + 1); + sourceToListenerPos.Norm(); + + _clusterSourcePos = _clusterSourcePos + (sourceToListenerPos - _clusterSourcePos) / (numSources + 1); + + _clusterSourcePos.Norm(); _clusterSourceToListenerPos = _clusterSourcePos - _listenerPos; maxError = std::max(err, maxError); @@ -206,12 +217,20 @@ VABinauralCluster::addSource(int sourceID, VABinauralSoundSource* source) void VABinauralCluster::addSource(int sourceID, VABinauralSoundSource* source, double error) { - _clusterSourcePos = (source->predPos + _clusterSourcePos * numSources) / (numSources + 1); + VAVec3 sourceToListenerPos = source->predPos - _listenerPos; + double err = getDistError(source); + + sourceToListenerPos.Norm(); + + _clusterSourcePos = _clusterSourcePos + (sourceToListenerPos - _clusterSourcePos) / (numSources + 1); + + _clusterSourcePos.Norm(); _clusterSourceToListenerPos = _clusterSourcePos - _listenerPos; - maxError = std::max(error, maxError); + maxError = std::max(err, maxError); _sources.insert(std::pair(sourceID, source)); + // -- source->AddReference(); diff --git a/src/Rendering/Binaural/RealTime/Utils/BinauralClusterEngine/VABinauralClustering.cpp b/src/Rendering/Binaural/RealTime/Utils/BinauralClusterEngine/VABinauralClustering.cpp index dac4191..95df8c2 100644 --- a/src/Rendering/Binaural/RealTime/Utils/BinauralClusterEngine/VABinauralClustering.cpp +++ b/src/Rendering/Binaural/RealTime/Utils/BinauralClusterEngine/VABinauralClustering.cpp @@ -41,7 +41,7 @@ VABinauralClustering::init(int listenerID, VABinauralListener* listener, int num _listenerID = listenerID; _listener = listener; _numClusters = numClusters; - _threshold = cos(180. / numClusters) * cos(180. / numClusters); + _threshold = 1. / numClusters; _output = new ITASampleFrame(2, listener->output->GetLength(), true); diff --git a/src/Rendering/Binaural/RealTime/VABinauralRealTimeRenderer.cpp b/src/Rendering/Binaural/RealTime/VABinauralRealTimeRenderer.cpp index c31e92d..98a8ec3 100644 --- a/src/Rendering/Binaural/RealTime/VABinauralRealTimeRenderer.cpp +++ b/src/Rendering/Binaural/RealTime/VABinauralRealTimeRenderer.cpp @@ -1,5 +1,11 @@ #include "VABinauralRealTimeRenderer.h" +#include +#include +#include +#include +#include + // VA Includes #include #include @@ -140,6 +146,19 @@ void VABinauralRealTimeRenderer::UpdateGlobalAuralizationMode(int iGlobalAuraliz void 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; + + // get ticks per second + QueryPerformanceFrequency(&frequency); + + // start timer + QueryPerformanceCounter(&t1); + + ///// ITASampleFrame* output; float* outputChL = GetWritePointer(0); float* outputChR = GetWritePointer(1); @@ -163,6 +182,17 @@ VABinauralRealTimeRenderer::ProcessStream(const ITAStreamInfo* streamInfo) fm_copy(outputChR, (*output)[1].data(), m_uiBlocklength); } + //BENCHMARK + // stop timer + QueryPerformanceCounter(&t2); + + // compute and print the elapsed time in millisec + 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(); + //// IncrementWritePointer(); return; @@ -176,6 +206,7 @@ VABinauralRealTimeRenderer::UpdateScene(CVASceneState* newSceneState) _newSceneState = newSceneState; if (_newSceneState == _curSceneState) return; + // get reference to new scene _newSceneState->AddReference(); @@ -183,6 +214,17 @@ VABinauralRealTimeRenderer::UpdateScene(CVASceneState* newSceneState) CVASceneStateDiff diff; _newSceneState->Diff(_curSceneState, &diff); + //BENCHMARK + LARGE_INTEGER frequency; // ticks per second + LARGE_INTEGER t1, t2; // ticks + double elapsedTime; + + // get ticks per second + QueryPerformanceFrequency(&frequency); + + // start timer + QueryPerformanceCounter(&t1); + // update listeners updateListeners(&diff); @@ -191,11 +233,23 @@ VABinauralRealTimeRenderer::UpdateScene(CVASceneState* newSceneState) _clusterEngine->update(); + //BENCHMARK + // stop timer + QueryPerformanceCounter(&t2); + + // compute and print the elapsed time in millisec + 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(); + // Alte Szene freigeben (dereferenzieren) if (_curSceneState) _curSceneState->RemoveReference(); _curSceneState = _newSceneState; _newSceneState = nullptr; + } /* @@ -367,7 +421,7 @@ VABinauralRealTimeRenderer::createListener(int listenerID, const CVAReceiverStat _listeners.insert(std::pair< int, VABinauralListener* >(listenerID, listener)); // add listener to clustering - VABinauralClusterEngine::clusterConfig_t config = { /*numClusters=*/ 9}; + VABinauralClusterEngine::clusterConfig_t config = { /*numClusters=*/ 128}; _clusterEngine->addListener(listenerID, listener, config); } -- GitLab