Commit ce499537 authored by Pascal Palenda's avatar Pascal Palenda
Browse files

Fix ravenegg

parent 72fed278
......@@ -25,10 +25,15 @@
#ifndef __GNU_LIBRARY__
#define __GNU_LIBRARY__
#endif
#include <conio.h>
#include "getopt.h"
#include <ITASimulationScheduler/Raven/Simulator.h>
#include <ITASimulationScheduler/Utils.h>
#include <ITA/simulation_scheduler/types.h>
#include <ITA/simulation_scheduler/room_acoustics/raven/simulator.h>
#include <ITA/simulation_scheduler/room_acoustics/raven/simulation_task.h>
#include <ITA/simulation_scheduler/room_acoustics/raven/raven_simulation_result.h>
#include <ITA/simulation_scheduler/profiler/profiler.h>
#include <RG_Vector.h>
#include <ITAAudiofileWriter.h>
......@@ -49,12 +54,19 @@
using namespace std;
using namespace ITA::simulation_scheduler;
using namespace room_acoustics;
using namespace raven;
void normalize_0dB( ITASampleFrame* );
void LoadTask ( CSimulationTask& oTask, const std::string& sPath );
FieldOfDuty ParseSimulationType ( const std::string& sShortSimType );
void syntax_error()
{
cout << "Syntax: ravenegg -d DATABASEPATH -t TASKFILE -r RESULTFILE [-n (normalize)]" << endl;
cout << "Syntax: ravenegg -i RPFFILE -t TASKFILE -r RESULTFILE [-n (normalize)]" << endl;
cout << "Scene of task file may only include a single source and a single receiver" << endl;
}
......@@ -67,16 +79,16 @@ int main( int argc, char* argv[] )
return 255;
}
string sRavenDataBasePath, sTaskPath, sResultPath;
string sRPFFile, sTaskPath, sResultPath;
bool bNormalize = false;
int c;
while( ( c = getopt( argc, argv, "d:nr:t:" ) ) != -1 )
while( ( c = getopt( argc, argv, "i:nr:t:" ) ) != -1 )
{
switch( c )
{
case 'd':
sRavenDataBasePath = optarg;
case 'i':
sRPFFile = optarg;
break;
case 'n':
bNormalize = true;
......@@ -96,70 +108,52 @@ int main( int argc, char* argv[] )
return 255;
}
}
if( doesDirectoryExist( sRavenDataBasePath ) == false )
{
cerr << "Given Raven data base path '" << sRavenDataBasePath << "' not found on this machine" << endl;
return 255;
}
try
{
cout << "Raven data base path is set to '" << sRavenDataBasePath << "'" << endl;
auto pRavenSimulator = std::make_shared< ITASimulationScheduler::RAVEN::CRavenSimulator >( sRavenDataBasePath );
ITASimulationScheduler::CSimulationTask oTask;
ITASimulationScheduler::CSimulationResult oResult;
CSimulationTask oTask;
CRavenSimulationResult oResult;
cout << "Loading task from file with path '" << sTaskPath << "'" << endl;
LoadTask( oTask, sTaskPath );
if( oTask.oScene.m_mSources.size() != 1 )
if( oTask.oScene.getSourceMap().size() != 1 )
{
cerr << "[ERROR] Please provide a single source in task file" << endl;
return 255;
}
if( oTask.oScene.m_mReceivers.size() != 1 )
if( oTask.oScene.getReceiverMap().size() != 1 )
{
cerr << "[ERROR] Please provide a single receiver in task file, portals are not supported by simulator yet" << endl;
return 255;
}
if( oTask.oScene.m_mPortals.size() != 0 )
{
cerr << "[ERROR] Please do not provide portals in task file" << endl;
return 255;
}
cout << "Task acknowledged" << endl;
cout << " --- Task configuration: " << endl << oTask.oConfig.ToString() << endl;
cout << " --- Task scene: " << endl << oTask.oScene.ToString() << endl;
cout << " --- Task scene: " << endl << oTask.oScene.toString() << endl;
auto pRavenSimulator = std::make_shared< CSimulator > ( oTask.eSimulationType, sRPFFile );
int iDifference = 0;
if( ( iDifference = oTask.oConfig.Validate() ) > 0 )
cout << "[WARNING] Detected odd configuration settings in Task1, bit vector was " << iDifference << endl;
cout << "Performing simulation" << endl;
pRavenSimulator->Compute( &oTask, &oResult );
pRavenSimulator->compute( &oTask, &oResult );
cout << "Exporting result to '" << sResultPath << "'" << endl;
if( bNormalize )
normalize_0dB( oResult.vcspResult[0]->psfResult );
if( oTask.iSimulationType | ITASimulationScheduler::CSimulationTask::SIM_DS )
cout << "Direct sound was " << ( oResult.vcspResult[0]->bDirectSoundAudible ? "audible" : "inaudible" ) << endl;
if( oTask.iSimulationType != ITASimulationScheduler::CSimulationTask::SIM_DS )
writeAudiofile( sResultPath, oResult.vcspResult[ 0 ]->psfResult, oTask.oConfig.oSimulationSettings.dSampleRate );
normalize_0dB( oResult.vcspResult[ 0 ]->psfResult.get() );
writeAudiofile( sResultPath, oResult.vcspResult[ 0 ]->psfResult.get(), 44100.0 );
if( oResult.vcspResult[0]->bEntitiesInSameRoom )
cout << "Entities (source and receiver) were in the same room." << endl;
else
cout << "Entities (source and receiver) were not in the same room." << endl;
ITASimulationScheduler::ISimulationInterface::CProfiler oStatus;
pRavenSimulator->GetProfilerStatus( oStatus );
cout << "Raven simulation profiler: " << oStatus << endl;
cout << "Store Profile data";
int c = _getch ( );
if ( c == 'y' )
storeProfilerData ( "SimulationProfile.json" );
}
catch( ITAException& err )
{
......@@ -185,3 +179,27 @@ void normalize_0dB( ITASampleFrame* p )
if( fGlobalPeak != 0.0f )
p->mul_scalar( 1/fGlobalPeak );
}
void LoadTask ( CSimulationTask& oTask, const std::string& sPath )
{
oTask.uiID = INIFileReadUInt ( sPath, "Task", "ID", 0 );
oTask.uiReferenceID = INIFileReadUInt ( sPath, "Task", "ReferenceID", 0 );
std::string sSimulationType = INIFileReadString ( sPath, "Task", "Simulation", "DS+ER_IS+DD_RT" );
auto eSimulationType = ParseSimulationType ( sSimulationType );
oTask.eSimulationType = eSimulationType;
oTask.oScene.loadFormINI( sPath );
return;
}
FieldOfDuty ParseSimulationType ( const std::string& sShortSimType )
{
if ( sShortSimType == "DS" )
return FieldOfDuty::directSound;
else if ( sShortSimType == "ER_IS" )
return FieldOfDuty::earlyReflections;
else if ( sShortSimType == "DD_RT" )
return FieldOfDuty::diffuseDecay;
ITA_EXCEPT_INVALID_PARAMETER ( "Simulation Type not supported." );
}
Supports Markdown
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