VACoreConfig.cpp 5.71 KB
Newer Older
1 2 3 4 5 6
/*
 *  --------------------------------------------------------------------------------------------
 *
 *    VVV        VVV A           Virtual Acoustics (VA) | http://www.virtualacoustics.org
 *     VVV      VVV AAA          Licensed under the Apache License, Version 2.0
 *      VVV    VVV   AAA
7
 *       VVV  VVV     AAA        Copyright 2015-2018
8 9 10 11 12 13
 *        VVVVVV       AAA       Institute of Technical Acoustics (ITA)
 *         VVVV         AAA      RWTH Aachen University
 *
 *  --------------------------------------------------------------------------------------------
 */

Jonas Stienen's avatar
Jonas Stienen committed
14 15
#include "VACoreConfig.h"

16
#include "Reproduction/VAAudioReproduction.h"
Jonas Stienen's avatar
Jonas Stienen committed
17 18 19
#include "Utils/VAUtils.h"
#include "VALog.h"

20
#include <VABase.h>
Jonas Stienen's avatar
Jonas Stienen committed
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
#include <VAException.h>
#include <VAStruct.h>

// ITA includes
#include <ITAStringUtils.h>

#include <VistaTools/VistaFileSystemDirectory.h>

// STL includes
#include <set>
#include <iostream>

void CVACoreConfig::Init( const CVAStruct& oData )
{
	m_oData = oData;

	CVAConfigInterpreter conf( oData );

39
	// Get debug level first, will affect further config parsing outputs
Jonas Stienen's avatar
Jonas Stienen committed
40
	int iVALogLevel;
41
	conf.OptInteger( "Debug/LogLevel", iVALogLevel, VACORE_DEFAULT_LOG_LEVEL );
Jonas Stienen's avatar
Jonas Stienen committed
42 43
	VALog_SetLogLevel( iVALogLevel );

44
	conf.OptInteger( "Debug/TriggerUpdateMilliseconds", iTriggerUpdateMilliseconds, 100 );
Jonas Stienen's avatar
Jonas Stienen committed
45

46
	VA_TRACE( "Config", oData );
47

Jonas Stienen's avatar
Jonas Stienen committed
48 49 50 51 52 53 54 55 56 57
	CVAStruct oMacroStruct( conf.OptStruct( "Macros" ) );
	CVAStruct::const_iterator cit = oMacroStruct.Begin();
	while( cit != oMacroStruct.End() )
	{
		const std::string& sMacroName( cit->first );
		const CVAStructValue& oMacroValue( cit->second );
		if( oMacroValue.IsString() )
		{
			std::string sMacroValue = mMacros.SubstituteMacros( oMacroValue );
			mMacros.AddMacro( "$(" + sMacroName + ")", sMacroValue );
58
			VA_VERBOSE( "Config", "Added macro $(" + sMacroName + ") = " + sMacroValue );
Jonas Stienen's avatar
Jonas Stienen committed
59 60 61 62
		}
		cit++;
	}

63

Jonas Stienen's avatar
Jonas Stienen committed
64
	CVAStruct oPathsStruct( conf.OptStruct( "Paths" ) );
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84

	std::string sWorkingDirectory = VistaFileSystemDirectory::GetCurrentWorkingDirectory();
	VA_INFO( "Core", "Current working directory: '" << sWorkingDirectory << "'" );
	if( oPathsStruct.HasKey( "WorkingDirectory" ) )
	{
		std::string sPath = oPathsStruct[ "WorkingDirectory" ];
		VistaFileSystemDirectory oDir( sPath );
		if( oDir.Exists() )
		{
			VistaFileSystemDirectory::SetCurrentWorkingDirectory( sPath );
			std::string sWorkingDirectory = VistaFileSystemDirectory::GetCurrentWorkingDirectory();
			VA_INFO( "Config", "Found valid working directory path entry, switching to: '" << sWorkingDirectory << "'" );
		}
		else
		{
			std::string sWorkingDirectory = VistaFileSystemDirectory::GetCurrentWorkingDirectory();
			VA_WARN( "Config", "Requested working directory path '" << sPath << "' not found, will fall back to '" << sWorkingDirectory << "'" );
		}
	}

Jonas Stienen's avatar
Jonas Stienen committed
85 86 87 88 89 90 91
	cit = oPathsStruct.Begin();
	while( cit != oPathsStruct.End() )
	{
		const std::string& sPathName( cit->first );
		const CVAStructValue& oPathValue( cit++->second );
		if( oPathValue.IsString() )
		{
92 93 94
			if( toLowercase( sPathName ) == "workingdirectory" )
				continue;

Jonas Stienen's avatar
Jonas Stienen committed
95 96
			std::string sPath = oPathValue;
			VistaFileSystemDirectory oDir( sPath );
97

Jonas Stienen's avatar
Jonas Stienen committed
98 99 100 101
			if( oDir.Exists() )
			{
				vsSearchPaths.push_back( sPath );
				mMacros.AddMacro( "$(" + sPathName + ")", sPath );
102
				VA_INFO( "Config", "Added search path '" + sPath + "'" );
Jonas Stienen's avatar
Jonas Stienen committed
103 104 105
			}
			else
			{
106
				VA_INFO( "Config", "Could not find path '" + sPath + "', removed from search path list." );
Jonas Stienen's avatar
Jonas Stienen committed
107 108 109 110
			}
		}
		else
		{
111
			VA_WARN( "Config", "Path with key '" + sPathName + "' is not a string value, skipping." );
Jonas Stienen's avatar
Jonas Stienen committed
112 113 114
		}
	}

115
	oAudioDriverConfig.Init( conf.OptStruct( "Audio driver" ) );
Jonas Stienen's avatar
Jonas Stienen committed
116 117 118

	oHardwareSetup.Init( oData );

119 120 121 122 123 124 125 126 127 128 129
	conf.OptBool( "Audio device/RecordInputEnabled", bRecordDeviceInputEnabled, false );
	conf.OptString( "Audio device/RecordInputFileName", sRecordDeviceInputFileName, "device_in.wav" );
	sRecordDeviceInputFileName = mMacros.SubstituteMacros( sRecordDeviceInputFileName );
	conf.OptString( "Audio device/RecordInputBaseFolder", sRecordDeviceInputBaseFolder, "recordings/device" );
	sRecordDeviceInputBaseFolder = mMacros.SubstituteMacros( sRecordDeviceInputBaseFolder );

	conf.OptBool( "Audio device/RecordOutputEnabled", bRecordDeviceOutputEnabled, false );
	conf.OptString( "Audio device/RecordOutputFileName", sRecordDeviceOutputFileName, "device_out.wav" );
	sRecordDeviceOutputFileName = mMacros.SubstituteMacros( sRecordDeviceOutputFileName );
	conf.OptString( "Audio device/RecordOutputBaseFolder", sRecordDeviceOutputBaseFolder, "recordings/device" );
	sRecordDeviceOutputBaseFolder = mMacros.SubstituteMacros( sRecordDeviceOutputBaseFolder );
130 131 132 133 134

	conf.OptNumber( "HomogeneousMedium/DefaultRelativeHumidity", oInitialHomogeneousMedium.dRelativeHumidityPercent, g_dDefaultRelativeHumidity );
	conf.OptNumber( "HomogeneousMedium/DefaultSoundSpeed", oInitialHomogeneousMedium.dSoundSpeed, g_dDefaultSpeedOfSound );
	conf.OptNumber( "HomogeneousMedium/DefaultStaticPressure", oInitialHomogeneousMedium.dStaticPressurePascal, g_dDefaultStaticPressure );
	conf.OptNumber( "HomogeneousMedium/DefaultTemperature", oInitialHomogeneousMedium.dTemperatureDegreeCentigrade, g_dDefaultTemperature );
135 136 137 138 139 140

	std::string sDefaultAmplitudeCalibrationMode;
	conf.OptString( "Calibration/DefaultAmplitudeCalibrationMode", sDefaultAmplitudeCalibrationMode, "94dB" );
	dDefaultAmplitudeCalibration = g_dSoundPower_94dB_SPL_1m;
	if( sDefaultAmplitudeCalibrationMode == "124dB" )
		dDefaultAmplitudeCalibration = g_dSoundPower_128dB_SPL_1m;
141

142
	conf.OptNumber( "Calibration/DefaultMinimumDistance", dDefaultMinimumDistance, 0.25f ); // translates to max +12 dB SPL
143
	conf.OptNumber( "Calibration/DefaultDistance", dDefaultDistance, 2.0f ); // translates to -6 dB SPL
Dipl.-Ing. Jonas Stienen's avatar
WIP  
Dipl.-Ing. Jonas Stienen committed
144 145 146


	conf.OptBool( "RemoteShutdownAllowed", bRemoteShutdownAllowed, true );
Jonas Stienen's avatar
Jonas Stienen committed
147 148 149 150 151 152
}

const CVAStruct& CVACoreConfig::GetStruct() const
{
	return m_oData;
}