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

#ifndef IW_VABASE
#define IW_VABASE

#include <VABaseDefinitions.h>

19 20
#include <VAStruct.h>

21 22 23 24
#include <string>
#include <vector>
#include <cmath>

25 26 27 28
static const double g_dSoundPower_94dB_SPL_1m = 1.0f; // [W] Sound power that results in 94 dB SPL re 20uPa @ 1m for spherical spreading
static const double g_dDefaultSoundPower_128dB_SPL_1m = 1.0f; // [W] Sound power that results in 124 dB SPL re 20uPa @ 1m for spherical spreading
static const double g_dDefaultSpeedOfSound = 344.0f; // [m/s]
static const double g_dDefaultStaticPressure = 101125; // [Pa]
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44

//! 3-element Vector (double precision), in a geometrical context in meters (if not stated otherwise)
class VABASE_API VAVec3
{
public:
	union
	{
		double comp[ 3 ];
		struct
		{
			double x, y, z;
		};
	};

	inline VAVec3() : x( 0 ), y( 0 ), z( 0 ) {};
	inline VAVec3( const VAVec3& v ) : x( v.x ), y( v.y ), z( v.z ) {};
45
	inline VAVec3( const double x, const double y, const double z ) : x( x ), y( y ), z( z ) {};
46 47 48 49 50 51 52
	inline virtual ~VAVec3() {};

	inline virtual double Length() const
	{
		return sqrt( x*x + y*y + z*z );
	};

53
	inline virtual void Set( const double x_, const double y_, const double z_ )
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
	{
		x = x_;
		y = y_;
		z = z_;
	};

	inline VAVec3 Cross( const VAVec3& vCrossProduct ) const
	{
		VAVec3 vCrossResult;
		vCrossResult.x = y * vCrossProduct.z - z * vCrossProduct.y;
		vCrossResult.y = z * vCrossProduct.x - x * vCrossProduct.z;
		vCrossResult.z = x * vCrossProduct.y - y * vCrossProduct.x;
		return vCrossResult;
	};

	inline double Dot( const VAVec3& vDotProduct ) const
	{
		return ( x * vDotProduct.x + y * vDotProduct.y + z * vDotProduct.z );
	};

	inline void Norm()
	{
		const double l = Length();
		x /= l;
		y /= l;
		z /= l;
	};
};

inline VABASE_API bool operator==( const VAVec3& a, const VAVec3& b )
{
	return ( ( a.x == b.x ) && ( a.y == b.y ) && ( a.z == b.z ) );
};

inline VABASE_API bool operator!=( const VAVec3& a, const VAVec3& b )
{
	return !( a == b );
};

inline VABASE_API VAVec3 operator+( const VAVec3& oSummand1, const VAVec3& oSummand2 )
{
	VAVec3 vSum;
	vSum.x = oSummand1.x + oSummand2.x;
	vSum.y = oSummand1.y + oSummand2.y;
	vSum.z = oSummand1.z + oSummand2.z;
	return vSum;
};


inline VABASE_API VAVec3 operator-( const VAVec3& oSummand1, const VAVec3& oSummand2 )
{
	VAVec3 vDiff;
	vDiff.x = oSummand1.x - oSummand2.x;
	vDiff.y = oSummand1.y - oSummand2.y;
	vDiff.z = oSummand1.z - oSummand2.z;
	return vDiff;
};

inline VABASE_API VAVec3 operator*( const VAVec3& oVec, double dScalar )
{
	VAVec3 vScaledVector = oVec;
	vScaledVector.x *= dScalar;
	vScaledVector.y *= dScalar;
	vScaledVector.z *= dScalar;
	return vScaledVector;
};

121 122
//! Stream output operator for VAVec3
// Output format: "< x, y, z >"
123 124
VABASE_API std::ostream& operator<<( std::ostream& os, const VAVec3& oVec );

125 126 127 128


//! 4-element Quaternion (double precision)
class VABASE_API VAQuat
129 130
{
public:
131 132 133 134 135 136 137 138
	union
	{
		double comp[ 4 ];
		struct
		{
			double x, y, z, w;
		};
	};
139

140 141 142 143
	inline VAQuat() : x( 0 ), y( 0 ), z( 0 ), w( 1.0f ) {};
	inline VAQuat( const VAQuat& v ) : x( v.x ), y( v.y ), z( v.z ), w( v.w ) {};
	inline VAQuat( const double x, const double y, const double z ) : x( x ), y( y ), z( z ), w( w ) {};
	inline virtual ~VAQuat() {};
144

145
	inline virtual void Set( const double x_, const double y_, const double z_, const double w_ )
146
	{
147 148 149 150
		x = x_;
		y = y_;
		z = z_;
		w = w_;
151 152 153
	};
};

154 155 156
//! Stream output operator for Quaternion
// Output format: "< x, y, z, 'w' >"
VABASE_API std::ostream& operator<<( std::ostream& os, const VAQuat& oOrient );
157 158 159


//! Data class describing callable and registrable objects
160 161 162 163 164
/**
  * In VA, anything can be an object. If an object is registered,
  * it can also be listed and called over the VA interface. Then, it
  * is called a module, @sa CVAModuleInfo, GetModules
  */
165 166 167 168 169
struct VABASE_API CVAObjectInfo
{
	int iID;			//!< Object ID
	std::string sName;	//!< Object name
	std::string sDesc;	//!< Object description
170 171 172 173

	inline CVAObjectInfo()
		: iID( -1 )
	{};
174 175 176 177
};


//! Pure data class describing modules of the core
178 179 180
/**
  *
  */
181 182 183 184
struct VABASE_API CVAModuleInfo
{
	std::string sName;	//!< Module name
	std::string sDesc;	//!< Module description
185
	CVAStruct oParams; //!< Parameters
186 187 188 189 190 191 192 193 194
};

//! Struct describing an audio renderer
struct VABASE_API CVAAudioRendererInfo
{
	std::string sID;	//!< Renderer identifier
	std::string sClass; //!< Renderer class
	std::string sDescription; //!< Renderer description
	bool bEnabled; //!< Availability during runtime
195 196 197 198 199 200 201 202 203 204 205
	bool bOutputDetectorEnabled; //!< Indicates if output detector is enabled
	bool bOutputRecordingEnabled; //!< Indicates if output detector is enabled
	std::string sOutputRecordingFilePath; //!< Output recording file path
	CVAStruct oParams; //!< Additional parameters, may be changed during runtime

	//! Constructor with default init values
	inline CVAAudioRendererInfo()
		: bEnabled( false )
		, bOutputDetectorEnabled( false )
		, bOutputRecordingEnabled( false )
	{};
206 207 208 209 210 211 212 213 214
};

//! Struct describing an audio reproduction module
struct VABASE_API CVAAudioReproductionInfo
{
	std::string sID;	//!< Reproduction module identifier
	std::string sClass; //!< Reproduction module class
	std::string sDescription; //!< Reproduction module description
	bool bEnabled; //!< Availability during runtime
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230
	bool bInputDetectorEnabled; //!< Indicates if output detector is enabled
	bool bInputRecordingEnabled; //!< Indicates if output detector is enabled
	std::string sInputRecordingFilePath; //!< Output recording file path
	bool bOutputDetectorEnabled; //!< Indicates if output detector is enabled
	bool bOutputRecordingEnabled; //!< Indicates if output detector is enabled
	std::string sOutputRecordingFilePath; //!< Output recording file path
	CVAStruct oParams; //!< Additional parameters, may be changed during runtime

	//! Constructor with default init values
	inline CVAAudioReproductionInfo()
		: bEnabled( false )
		, bInputDetectorEnabled( false )
		, bInputRecordingEnabled( false )
		, bOutputDetectorEnabled( false )
		, bOutputRecordingEnabled( false )
	{};
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249
};

//! Describes the current state of a progress
/**
  * This data class is used to describe the current state of a
  * running process (progress). It is intended for the purpose
  * of displaying the progress of an action that takes some time
  * to be shown in a user interface (i.e. the initialisation of
  * a core)
  */
class VABASE_API CVAProgress
{
public:
	int iCurrentStep;		//!< Current step number (0 = nothing happened yet)
	int iMaxStep;			//!< Maximum step number (end)
	std::string sAction;	//!< Currently performed action (top level)
	std::string sSubaction;	//!< Currently performed sub action

	//! Constructor
250
	inline CVAProgress()
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273
		: iCurrentStep( 0 )
		, iMaxStep( 0 )
	{
	};
};


//! Data class describing integer literals within the core interface (reflexions)
class VABASE_API CVAIntLiteral
{
public:
	std::string sScope;		//!< Interface name (e.g. IVACore)
	std::string sName;		//!< Literal name (e.g. 'VA_AURAMODE_DIRECT_SOUND')
	int iValue;				//!< Literal integer value

	//! Constructor
	/**
	  * Create an integer literal.
	  *
	  * \param sTheScope Scope of the literal, i.e. IVACore
	  * \param sTheName Name string of the integer literal, i.e. 'VA_AURAMOD_DEFAULT'
	  * \param iTheValue Value of the integer
	  */
274
	inline CVAIntLiteral( const std::string& sTheScope, const std::string& sTheName, const int iTheValue )
275 276 277 278 279
		: sScope( sTheScope )
		, sName( sTheName )
		, iValue( iTheValue )
	{
	};
280 281 282
private:
	//! No default construction
	inline CVAIntLiteral() {};
283 284
};

285 286 287 288 289 290 291 292 293 294 295
//! Data class containing information on directivities of sound sources and sound receivers
/**
  * This class describes a directivity: the sound changes depending on the directional component
  * of a sending or receiving entity. It may also include distance-dependent data.
  *
  * There are certain classes available, that will be recognized by most renderers. However,
  * you might want to use the PROTOTYPE class if you are testing new types that are not part
  * of the VA base interface.
  *
  * Special parameters are stores in the parameter struct.
  */
296 297 298
class VABASE_API CVADirectivityInfo
{
public:
299
	enum DirectivityClass
300
	{
301 302 303
		UNSPECIFIED = -1,
		PROTOTYPE = 0,
		IMPULSE_RESPONSE,
304 305
		TRANSFER_FUNCTION,
		ENERGETIC_BAND_SPECTRUM,
306 307
	};

308 309 310 311
	int iID;					//!< Identifier
	int iClass;					//!< Class identifier
	std::string sName;			//!< Name
	std::string sDesc;			//!< Verbose description
312
	int iReferences;			//!< Number of references
313
	CVAStruct oParams; 			//!< Special parameters (including file path etc.)
314 315

	//! Default constructor
316
	inline CVADirectivityInfo()
317
		: iID( -1 )
318
		, iClass( UNSPECIFIED )
319 320 321 322 323 324
		, iReferences( 0 )
	{
	};

	//! Initializing constructor
	/**
325 326 327 328 329 330
	  * @param[in] iID Identifier
	  * @param[in] iClass Directivity class
	  * @param[in] sName Name of directivity
	  * @param[in] sDesc Brief description of the directivity
	  * @param[in] iReferences Usage reference count of directivity data
	  * @param[in] oParams Special parameters
331
	  */
332 333 334 335 336 337 338
	inline CVADirectivityInfo( const int iID, const int iClass, const std::string& sName, const std::string& sDesc, const int iReferences, const CVAStruct& oParams )
		: iID( iID )
		, iClass( iClass )
		, sName( sName )
		, sDesc( sDesc )
		, iReferences( iReferences )
		, oParams( oParams )
339 340 341 342 343 344 345 346 347
	{
	};
};


//! Data class for signal source information
class VABASE_API CVASignalSourceInfo
{
public:
348 349 350 351 352 353 354 355 356 357 358 359
	//! Signal source type
	enum Type
	{
		UNSPECIFIED = -1,
		FILE = 0,
		SAMPLER,
		DEVICE_INPUT,
		NETSTREAM,
		MACHINE,
		ENGINE
	};

360
	std::string	sID;			//!< ID (i.e. "af1")
361 362
	int	iType;					//!< Type
	std::string sName;			//!< Name (i.e. "Blue horn 2")
363 364 365 366 367
	std::string sDesc;			//!< Description
	std::string sState;			//!< State description
	int iReferences;			//!< Reference counter

	//! Default constructor
368 369 370 371 372 373
	inline CVASignalSourceInfo()
		: iReferences( 0 )
		, iType( UNSPECIFIED )
	{};

	virtual inline ~CVASignalSourceInfo() {};
374 375 376 377

	//! Initializing constructor
	/**
	  * \param sID Identifier string
378
	  * \param iType
379 380 381 382 383
	  * \param sName Name of signal source info
	  * \param sDesc Brief description of signal source info
	  * \param sState State description of signal source info
	  * \param iReference Usage reference counter
	  */
384 385 386 387 388 389 390
	inline CVASignalSourceInfo( const std::string& sID, const int iType, const std::string& sName, const std::string& sDesc, const std::string& sState, const int iReferences )
		: sID( sID )
		, iType( iType )
		, sName( sName )
		, sDesc( sDesc )
		, sState( sState )
		, iReferences( iReferences )
391
	{
392
	};
393 394 395
};


396
//! Data class containing information of a virtual acoustic scene
397 398 399
class VABASE_API CVASceneInfo
{
public:
400 401 402 403 404
	std::string sID;	//!< Scene identifier
	std::string sName;	//!< Scene name
	CVAStruct oParams; //!< Scene parameters

	inline virtual ~CVASceneInfo() {};
405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437
};


//! Data class describing states of audio streams
class VABASE_API CVAAudiostreamState
{
public:
	int64_t	i64Sample;	//!< Index of the first sample since last clock reset
	double dSysTime;	//!< Associated system time in time [s] (internal core clock) of the first sample of the requested output block.
	double dCoreTime;	//!< Associated playback time in core clock time [s] (world time) of the first sample of the requested output block.
	bool bTimeReset;	//!<  Flag that indicates a discontinous change of the playback time (world time)

	//!< Synchronise commands on the stream
	/**  Flag that indicates, that a synchronized
	  * sequence of atomic commands is executed on
	  * elements of the stream. If this flag is true
	  * the source shall handle parameter
	  * changes and buffer them internally, but
	  * first apply them for the stream, if the
	  * flag is set to false again.
	  * Example: Synchronized start/stop of file sources
	  */
	bool bSyncMod;

	//! Destructor
	inline virtual ~CVAAudiostreamState() {};
};


//! Data class containing information of a sound source (acoustic actuator)
class VABASE_API CVASoundSourceInfo
{
public:
438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457
	int iID;				//!< ID
	std::string sName;		//!< Displayed name
	VAVec3 v3Pos;			//!< Position vector of location between ears [m]
	VAVec3 v3View, v3Up;	//!< Orientation of ears/eyes (view and up vectors in OpenGL convention)
	VAQuat qOrient;			//!< Orientation of ears/eyes (quaternion)
	double dSpoundPower;	//!< Sound power [W]
	bool bMuted;			//!< Muted?
	int iSignalSourceID;	//!< ID of assigned signal source (-1 => none)
	int iDirectivityID;		//!< ID of assigned directivity (-1 => none)
	int iAuraMode;			//!< Auralization mode (flags)
	CVAStruct oParams;		//!< Special parameters

	inline CVASoundSourceInfo()
		: iID( -1 )
		, bMuted( false )
		, dSpoundPower( g_dSoundPower_94dB_SPL_1m )
		, iSignalSourceID( -1 )
		, iDirectivityID( -1 )
		, iAuraMode( -1 )
	{};
458 459

	virtual inline ~CVASoundSourceInfo() {};
460 461 462 463
};


//! Data class containing information of a listener (acoustic receiver)
464
class VABASE_API CVASoundReceiverInfo
465 466
{
public:
467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482
	int iID;				//!< ID
	std::string sName;		//!< Displayed name
	VAVec3 v3Pos;			//!< Position vector of location between ears [m]
	VAVec3 v3View, vUp;		//!< Orientation of ears/eyes (view and up vectors in OpenGL convention)
	VAQuat qOrient;			//!< Orientation of ears/eyes (quaternion)
	VAVec3 v3HeadAboveTorsoOrientation;	//!< Orientation of head above torso
	int iDirectivityID;		//!< ID of assigned directivity (-1 => none)
	int iAuraMode;			//!< Auralization mode (flags)
	double dSensivitity;	//!< Sensitivity of receiving entity

	inline CVASoundReceiverInfo()
		: iID( -1 )
		, iDirectivityID( -1 )
		, iAuraMode( -1 )
		, dSensivitity( 1.0f )
	{};
483 484

	virtual inline ~CVASoundReceiverInfo() {};
485 486 487
};


488 489
//! Data class containing information of a sound portal (acoustic portal)
class VABASE_API CVASoundPortalInfo
490 491
{
public:
492 493 494 495
	int iID;			//!< ID
	std::string sName;	//!< Displayed name (optional)
	VAVec3 vPos;		//!< Position vector [m]
	VAVec3 vView, vUp;	//!< View-/Up-vector
496
	VAQuat qOrient;		//!< Orientation (quaternion)
497 498 499 500
	int iMaterialID; //!< Material ID with transmission data
	int iNextPortalID;
	int iSoundReceiverID;
	int iSoundSourceID;
501 502
	CVAStruct oParams; 	//!< Special parameters

503
	inline CVASoundPortalInfo()
504
		: iID( -1 )
505 506 507 508
		, iNextPortalID( -1 )
		, iSoundSourceID( -1 )
		, iSoundReceiverID( -1 )
		, iMaterialID( -1 )
509
	{};
510

511
	virtual inline ~CVASoundPortalInfo() {};
512 513 514
};


515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570
//! Data class containing information of a sound portal (acoustic portal)
class VABASE_API CVAAcousticMaterial
{
public:
	enum Type
	{
		UNSPECIFIED = -1,
		PROTOTYPE = 0,
		ENERGETIC_BAND_FILTER_WHOLE_OCTAVE,
		ENERGETIC_BAND_FILTER_THIRD_OCTAVE,
	};

	int iID;			//!< ID
	int iType;
	CVAStruct oParams;
	std::vector< float > vfValues;

	inline CVAAcousticMaterial()
		: iID( -1 )
	{};
};



//! Geometry mesh class
/**
  * This is only intended to be used as an exchange
  * format of the simplest mesh structure. Renderers
  * use more elaborate representations.
  *
  * It can be used for rudimentary rooms and dynamic geometry objects.
  */
class VABASE_API CVAGeometryMesh
{
	class CVAVertex
	{
	public:
		int iID;
		VAVec3 v3Point;
		CVAVertex() : iID( -1 ) {};
	};

	class CVAFace
	{
		int iID;
		int iMaterialID; //!< Assigned material
		std::vector< int > viVertexList;
		CVAFace() : iID( -1 ), iMaterialID( -1 ) {};
	};

	int iID;
	std::vector< CVAVertex > voVertices; //!< List of available vertices
	std::vector< CVAFace > voFaces; //!< List of faces defined by vertices
	CVAStruct oParams; //!< Additional parameters
};

571
#endif // IW_VABASE