VABase.h 17 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
	{
		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;
	};
81 82 83 84 85 86 87 88 89

	inline CVAStruct GetAsStruct() const
	{
		CVAStruct oVec;
		oVec[ "x" ] = x;
		oVec[ "y" ] = y;
		oVec[ "z" ] = z;
		return oVec;
	};
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 121 122 123 124 125 126 127 128 129
};

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;
};

130 131
//! Stream output operator for VAVec3
// Output format: "< x, y, z >"
132 133
VABASE_API std::ostream& operator<<( std::ostream& os, const VAVec3& oVec );

134 135 136 137


//! 4-element Quaternion (double precision)
class VABASE_API VAQuat
138 139
{
public:
140 141 142 143 144 145 146 147
	union
	{
		double comp[ 4 ];
		struct
		{
			double x, y, z, w;
		};
	};
148

149 150
	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 ) {};
151
	inline VAQuat( const double x, const double y, const double z, const double w = 1.0f ) : x( x ), y( y ), z( z ), w( w ) {};
152
	inline virtual ~VAQuat() {};
153

154
	inline virtual void Set( const double x_, const double y_, const double z_, const double w_ )
155
	{
156 157 158 159
		x = x_;
		y = y_;
		z = z_;
		w = w_;
160
	};
161 162 163 164 165 166 167 168 169 170
	
	inline CVAStruct GetAsStruct() const
	{
		CVAStruct oOrient;
		oOrient[ "x" ] = x;
		oOrient[ "y" ] = y;
		oOrient[ "z" ] = z;
		oOrient[ "w" ] = w;
		return oOrient;
	};
171 172
};

173 174 175
//! Stream output operator for Quaternion
// Output format: "< x, y, z, 'w' >"
VABASE_API std::ostream& operator<<( std::ostream& os, const VAQuat& oOrient );
176 177 178


//! Data class describing callable and registrable objects
179 180 181 182 183
/**
  * 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
  */
184 185 186 187 188
struct VABASE_API CVAObjectInfo
{
	int iID;			//!< Object ID
	std::string sName;	//!< Object name
	std::string sDesc;	//!< Object description
189 190 191 192

	inline CVAObjectInfo()
		: iID( -1 )
	{};
193 194 195 196
};


//! Pure data class describing modules of the core
197 198 199
/**
  *
  */
200 201 202 203
struct VABASE_API CVAModuleInfo
{
	std::string sName;	//!< Module name
	std::string sDesc;	//!< Module description
204
	CVAStruct oParams; //!< Parameters
205 206 207 208 209 210 211 212 213
};

//! 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
214 215 216 217 218 219 220 221 222 223 224
	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 )
	{};
225 226 227 228 229 230 231 232 233
};

//! 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
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249
	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 )
	{};
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268
};

//! 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
269
	inline CVAProgress()
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292
		: 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
	  */
293
	inline CVAIntLiteral( const std::string& sTheScope, const std::string& sTheName, const int iTheValue )
294 295 296 297 298
		: sScope( sTheScope )
		, sName( sTheName )
		, iValue( iTheValue )
	{
	};
299 300 301
private:
	//! No default construction
	inline CVAIntLiteral() {};
302 303
};

304 305 306 307 308 309 310 311 312 313 314
//! 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.
  */
315 316 317
class VABASE_API CVADirectivityInfo
{
public:
318
	enum DirectivityClass
319
	{
320 321 322
		UNSPECIFIED = -1,
		PROTOTYPE = 0,
		IMPULSE_RESPONSE,
323 324
		TRANSFER_FUNCTION,
		ENERGETIC_BAND_SPECTRUM,
325 326
	};

327 328 329 330
	int iID;					//!< Identifier
	int iClass;					//!< Class identifier
	std::string sName;			//!< Name
	std::string sDesc;			//!< Verbose description
331
	int iReferences;			//!< Number of references
332
	CVAStruct oParams; 			//!< Special parameters (including file path etc.)
333 334

	//! Default constructor
335
	inline CVADirectivityInfo()
336
		: iID( -1 )
337
		, iClass( UNSPECIFIED )
338 339 340 341 342 343
		, iReferences( 0 )
	{
	};

	//! Initializing constructor
	/**
344 345 346 347 348 349
	  * @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
350
	  */
351 352 353 354 355 356 357
	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 )
358 359 360 361 362 363 364 365 366
	{
	};
};


//! Data class for signal source information
class VABASE_API CVASignalSourceInfo
{
public:
367 368 369 370 371 372 373 374 375 376 377 378
	//! Signal source type
	enum Type
	{
		UNSPECIFIED = -1,
		FILE = 0,
		SAMPLER,
		DEVICE_INPUT,
		NETSTREAM,
		MACHINE,
		ENGINE
	};

379
	std::string	sID;			//!< ID (i.e. "af1")
380 381
	int	iType;					//!< Type
	std::string sName;			//!< Name (i.e. "Blue horn 2")
382 383 384 385 386
	std::string sDesc;			//!< Description
	std::string sState;			//!< State description
	int iReferences;			//!< Reference counter

	//! Default constructor
387 388 389 390 391 392
	inline CVASignalSourceInfo()
		: iReferences( 0 )
		, iType( UNSPECIFIED )
	{};

	virtual inline ~CVASignalSourceInfo() {};
393 394 395 396

	//! Initializing constructor
	/**
	  * \param sID Identifier string
397
	  * \param iType
398 399 400 401 402
	  * \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
	  */
403 404 405 406 407 408 409
	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 )
410
	{
411
	};
412 413 414
};


415
//! Data class containing information of a virtual acoustic scene
416 417 418
class VABASE_API CVASceneInfo
{
public:
419 420
	std::string sID;	//!< Scene identifier
	std::string sName;	//!< Scene name
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
421 422
	bool bEnabled;

423 424
	CVAStruct oParams; //!< Scene parameters

Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
425 426 427 428 429 430 431 432
	inline CVASceneInfo()
		: bEnabled( true )
	{
	};

	inline virtual ~CVASceneInfo()
	{
	};
433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465
};


//! 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:
466 467 468 469 470 471 472
	int iID;				//!< ID
	std::string sName;		//!< Displayed name
	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)
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
473 474 475 476 477

	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)

478 479 480 481 482 483 484 485 486 487
	CVAStruct oParams;		//!< Special parameters

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

	virtual inline ~CVASoundSourceInfo() {};
490 491 492
};


Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
493
//! Data class containing information of a sound receiver (acoustic receiver)
494
class VABASE_API CVASoundReceiverInfo
495 496
{
public:
497 498
	int iID;				//!< ID
	std::string sName;		//!< Displayed name
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
499 500 501 502 503
	int iDirectivityID;		//!< ID of assigned directivity (-1 => none)
	int iAuraMode;			//!< Auralization mode (flags)
	double dSensivitity;	//!< Sensitivity of receiving entity
	bool bEnabled; 			//!< Enabled/disable from processing

504
	VAVec3 v3Pos;			//!< Position vector of location between ears [m]
Dipl.-Ing. Jonas Stienen's avatar
Style  
Dipl.-Ing. Jonas Stienen committed
505
	VAVec3 v3View;//!< Orientation of ears/eyes (view and up vectors in OpenGL convention)
506
	VAVec3 v3Up;		//!< Orientation of ears/eyes (view and up vectors in OpenGL convention)
507
	VAQuat qOrient;			//!< Orientation of ears/eyes (quaternion)
508
	VAQuat qHeadAboveTorsoOrientation;	//!< Orientation of head above torso relative to ears
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
509 510

	VAVec3 v3RealWorldPos;					//!< Position vector of location between ears [m] in real world (from tracking)
511 512
	VAVec3 v3RealWorldView; //!< Orientation of ears/eyes (view and up vectors in OpenGL convention) in real world (from tracking)
	VAVec3 v3RealWorldUp;	//!< Orientation of ears/eyes (view and up vectors in OpenGL convention) in real world (from tracking)
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
513
	VAQuat qRealWorldOrient;				//!< Orientation of ears/eyes (quaternion) in real world (from tracking)
514
	VAQuat qRealWorldHeadAboveTorsoOrientation;	//!< Orientation of head above torso in real world (from tracking) relative to ears
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
515 516

	CVAStruct oParams; 	//!< Special parameters
517 518 519 520 521 522

	inline CVASoundReceiverInfo()
		: iID( -1 )
		, iDirectivityID( -1 )
		, iAuraMode( -1 )
		, dSensivitity( 1.0f )
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
523
		, bEnabled( true )
524
	{};
525 526

	virtual inline ~CVASoundReceiverInfo() {};
527 528 529
};


530 531
//! Data class containing information of a sound portal (acoustic portal)
class VABASE_API CVASoundPortalInfo
532 533
{
public:
534 535
	int iID;			//!< ID
	std::string sName;	//!< Displayed name (optional)
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
536 537
	bool bEnabled;

538 539 540 541
	int iMaterialID; //!< Material ID with transmission data
	int iNextPortalID;
	int iSoundReceiverID;
	int iSoundSourceID;
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
542

543 544
	VAVec3 v3Pos;		//!< Position vector [m]
	VAVec3 v3View, v3Up;	//!< View-/Up-vector
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
545 546
	VAQuat qOrient;		//!< Orientation (quaternion)

547 548
	CVAStruct oParams; 	//!< Special parameters

549
	inline CVASoundPortalInfo()
550
		: iID( -1 )
551 552 553 554
		, iNextPortalID( -1 )
		, iSoundSourceID( -1 )
		, iSoundReceiverID( -1 )
		, iMaterialID( -1 )
555
	{};
556

557
	virtual inline ~CVASoundPortalInfo() {};
558 559 560
};


561 562 563 564 565 566 567 568 569 570 571 572 573 574
//! 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;
575
	std::string sName;
576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595
	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
{
596
public:
597 598 599 600 601
	class CVAVertex
	{
	public:
		int iID;
		VAVec3 v3Point;
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
602
		inline CVAVertex() : iID( -1 ) {};
603 604 605 606
	};

	class CVAFace
	{
607
	public:
608 609 610
		int iID;
		int iMaterialID; //!< Assigned material
		std::vector< int > viVertexList;
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
611
		inline CVAFace() : iID( -1 ), iMaterialID( -1 ) {};
612 613 614
	};

	int iID;
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
615
	bool bEnabled;
616 617 618
	std::vector< CVAVertex > voVertices; //!< List of available vertices
	std::vector< CVAFace > voFaces; //!< List of faces defined by vertices
	CVAStruct oParams; //!< Additional parameters
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
619 620 621 622 623

	inline CVAGeometryMesh()
		: iID( -1 )
		, bEnabled( true )
	{};
624 625
};

626
#endif // IW_VABASE