VAVBAPFreefieldAudioRenderer.h 8.17 KB
Newer Older
Jonas Stienen's avatar
Jonas Stienen committed
1
/*
2
 *  --------------------------------------------------------------------------------------------
Jonas Stienen's avatar
Jonas Stienen committed
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
 *        VVVVVV       AAA       Institute of Technical Acoustics (ITA)
 *         VVVV         AAA      RWTH Aachen University
Jonas Stienen's avatar
Jonas Stienen committed
10
 *
11
 *  --------------------------------------------------------------------------------------------
Jonas Stienen's avatar
Jonas Stienen committed
12
13
 */

14
15
#ifndef IW_VACORE_VBAPFREEFIELDAUDIORENDERER
#define IW_VACORE_VBAPFREEFIELDAUDIORENDERER
Jonas Stienen's avatar
Jonas Stienen committed
16

17
#ifdef VACORE_WITH_RENDERER_VBAP_FREE_FIELD
Jonas Stienen's avatar
Jonas Stienen committed
18
19

// VA includes
20
21
22
23
24
#include "../../../Motion/VASampleAndHoldMotionModel.h"
#include "../../../Motion/VASharedMotionModel.h"
#include "../../../Rendering/VAAudioRenderer.h"
#include "../../../Rendering/VAAudioRendererRegistry.h"
#include "../../../Scene/VAScene.h"
25
#include <VABase.h>
26
#include <VAInterface.h>
Jonas Stienen's avatar
Jonas Stienen committed
27
#include <VAObjectPool.h>
28
29
#include "../../../VASourceListenerMetrics.h"
#include "../../../VAHardwareSetup.h"
Jonas Stienen's avatar
Jonas Stienen committed
30
31

// ITA includes
32
#include <ITADataSourceRealization.h>
Jonas Stienen's avatar
Jonas Stienen committed
33
#include <ITASampleBuffer.h>
34
35
36

// Vista includes
#include <VistaBase/VistaVector3D.h>
37
#include <VistaMath/VistaGeometries.h>
Jonas Stienen's avatar
Jonas Stienen committed
38
39
40
41
42
43
44

// STL Includes
#include <list>
#include <set>

// Externe Vorwrtsdeklarationen
class CVACoreImpl;
45
class CVAVBAPFreeFieldAudioRendererConfig;
Jonas Stienen's avatar
Jonas Stienen committed
46
47
48
49
50
51
52
53
54
55
56
57

//! Vector-Base Amplitude Panning Audio Renderer
/**
  * Verwaltet Schallausbreitungspfade mit VBAP Synthese
  * fr beliebige Lautsprecheranordnungen
  *
  * Implementiert:
  *
  * - Gain-Verteilung der Lautsprecher
  * - 1/R-Gesetz
  *
  */
58
class CVAVBAPFreeFieldAudioRenderer : public IVAAudioRenderer, ITADatasourceRealizationEventHandler
Jonas Stienen's avatar
Jonas Stienen committed
59
60
{
public:
61
62
	CVAVBAPFreeFieldAudioRenderer( const CVAAudioRendererInitParams& oParams );
	virtual ~CVAVBAPFreeFieldAudioRenderer();
Jonas Stienen's avatar
Jonas Stienen committed
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

	void Init( const CVAStruct& oArgs );

	void Reset();
	
	void LoadScene( const std::string& sFilename );
	
	//! Handle a scene state change
	/**
	  * This method updates the internal representation of the VA Scene
	  * by setting up or deleting the sound path entities as well as
	  * modifying existing ones that have changed their state, i.e.
	  * pose or dataset
	  */
	void UpdateScene( CVASceneState* pNewSceneState );

	//! Handle a state change in global auralisation mode
	/**
	  * This method updates internal settings for the global auralisation
	  * mode affecting the activation/deactivation of certain components
	  * of the sound path entities
	  */
	void UpdateGlobalAuralizationMode( int iGlobalAuralizationMode );

	void HandleProcessStream( ITADatasourceRealization* pSender, const ITAStreamInfo* pStreamInfo );
	
	ITADatasource* GetOutputDatasource();

private:
	
	const CVAAudioRendererInitParams m_oParams;		//!< Create a const copy of the init params

	VAVec3 m_vUserPosVirtualScene;				//!< Position des Hoerers in der virtuellen Umgebung 
	VAVec3 m_vUserPosRealWorld;					//!< Position des Hrers in der CAVE (oder im Reproduktionssystem)
97
98
99
100
	VAVec3 m_vReproSystemVirtualPosition;		//!< Position der CAVE (oder des Reproduktionssystems) in der virtuellen Welt. Center position of loudspeaker array.
	//VAOrientYPR m_oUserYPRRealWorldRAD;		//!< Orientierung des Hoerers in der Cave (im Reproduktionssystem), Gieren, Nicken, Rollen
	//VAOrientYPR	m_oUserYPRVirtualScene;	//!< Orientierung des Hoerers in der virtuellen Umgebung, Gieren, Nicken, Rollen
	//VistaVector3D m_vRotYaw, m_vRotPitch, m_vRotRoll;	//!< Hilfsvektoren zum rotieren, um diese Achsen wird rotiert
Jonas Stienen's avatar
Jonas Stienen committed
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
	
	enum DIMENSIONS
	{
		DIM_1D = 1, //!< One-dimensional (loudspeaker on a line, curve)
		DIM_2D = 2,	//!< Two-dimensional (loudspeaker in a circle, closed curve, square)
		DIM_3D = 3, //!< Three-dimensional (loudspeaker on tetrahedron, sphere, cube)
	};

	// Loudspeaker
	class CLoudspeaker
	{
	public:
		std::string sIdentifier;
		int iIdentifier;
		int iChannel;
116
		VistaVector3D pos;
Jonas Stienen's avatar
Jonas Stienen committed
117
118
119
120
121
122
123
124
	};

	// Sections
	class CSection
	{
	public:
		int iIdentifier;
		std::vector <int> iLSIdentifier;
125
		VistaPolygon Polygon;
Jonas Stienen's avatar
Jonas Stienen committed
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
	};

	class SoundPath
	{
	public:
		SoundPath( const unsigned int iNumChannels )
		: m_vdNewGains( iNumChannels )
		, m_vdOldGains( iNumChannels )
		, bMarkDeleted( false )
		, iSourceID( -1 )
		{};
		std::vector< double > m_vdNewGains; //!< New gains for current process block
		std::vector< double > m_vdOldGains; //!< Old gains from prior process block (for crossfade)
		int iSourceID; //!< Source identifier
		ITAAtomicBool bMarkDeleted;
	};

	std::list< SoundPath > m_lSoundPaths; //!< List of active sound paths
	std::list< SoundPath > m_lNewSoundPaths; //!< List of added sound paths
	
	CVASceneState* m_pCurSceneState;		//!< Zeiger auf aktuell benutzte Scene im Renderer
	CVASceneState* m_pNewSceneState;		//!< Zeiger auf neue Scene fr den Renderer
	bool m_bResetTrigger;					//!< Bool die eins wird falls ein Reset stattfindet
	int m_iCurGlobalAuralizationMode;		//!< Der aktuelle Auralisierungsmodues, mit dem der Renderer arbeitet
	
151
152
	VistaVector3D m_vecCaveCenterPos;			//!< Mittelpunkt der CAVE Umgebung relativ zu Szene
	VistaVector3D m_vecCaveCenterOrientYPR;		//!< Mittelpunkt der CAVE Umgebung relativ zu Szene
Jonas Stienen's avatar
Jonas Stienen committed
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236

	int m_iSetupDimension;						//!< Dimension of setup, see \DIMENSIONS

	const CVAHardwareOutput* m_pOutput;		//!< Hardware output group with information on devices
	std::vector< CSection > m_voSectionList;		//!< List of all sections for the VBAP setup (DIM_3D only)
	std::vector< CLoudspeaker > m_voLoudspeaker;	//!< List of all loudspeaker for the VBAP setup
	
	ITADatasourceRealization* m_pdsOutput; //!< Output datasource
	


	//! Checks if a direction (from center point of the VBAP loudspeaker setup) is within a defined section
	//bool IsSourceDirectionWithinSection( const RG_Vector& vDirection, unsigned int uiCurrentSectionIdentifier) const;
	bool IsSourceDirectionWithinSection( const VAVec3& vDirection, const CSection& oSection ) const;
	

	//! Calculates loudspeaker gains for a 3D loudspeaker set-up
	/**
	  * Calculates loudspeaker gains using members of the class
	  *
	  * \param vSoundSource	Position of sound source
	  * \param vdLoudspeakerGains Call-by-reference loudspeaker gains, will be calculated
	  *
	  * \return False, if calculation was not possible
	  */
	bool CalculateLoudspeakerGains3D( const VAVec3& vSoundSource, std::vector< double >& vdLoudpeakerGains) const;
	
	
	//! Calculates loudspeaker gains for a 2D loudspeaker set-up
	/**
	  * Calculates loudspeaker gains using members of the class
	  *
	  * \param vSoundSource	Position of sound source
	  * \param vdLoudspeakerGains Call-by-reference loudspeaker gains, will be calculated
	  *
	  * \return False, if calculation was not possible
	  * 
	  */
	bool CalculateLoudspeakerGains2D( const VAVec3& vSoundSource, std::vector< double >& vdLoudpeakerGains) const;


	//! Helper function to retrieve real world position of a loudspeaker by identifier string
	/**
	  * \sIdentifier	Loudspeaker identifier string (has to match with hardware setup from VACore)
	  * \pSetup			VA core hardware setup pointer
	  *
	  * \return RG_Vector of loudspeaker position, zero vector if not found
	  */
	//RG_Vector GetLSPosition( const int iIdentifier, const CVAHardwareSetup* pSetup ) const;
	
	//! Helper function to retrieve channel number of a loudspeaker by identifier string
	/**
	  * \sIdentifier	Loudspeaker identifier string (has to match with hardware setup from VACore)
	  * \pSetup			VA core hardware setup pointer
	  *
	  * \return channel of loudspeaker in HardwareSetup, minus one if not found
	  */
	//int GetLSChannel( const int iIdentifier, const CVAHardwareSetup* pSetup ) const;


	//! Calculate the inverse for a three dimensional matrix
	/**
	  * \dOriginalMatrix	Original matrix array
	  * \dInverseMatrix		Target for inverse matrix
	  */
	void CalculateInverseMatrix3x3( const double *dOriginalMatrix, double *dInverseMatrix ) const;


	//! Calculate source position in relation to virtual position of CAVE
	/**
	  */
	VAVec3 GetSourcePosition( const CVAMotionState* pMotionState );


	//! Manage sound pathes
	/**
	  *
	  */
	void ManageSoundPaths( const CVASceneStateDiff* pDiff );


	void SyncInternalData();
};

237
#endif // VACORE_WITH_RENDERER_VBAP_FREE_FIELD
Jonas Stienen's avatar
Jonas Stienen committed
238

239
#endif // IW_VACORE_VBAPFREEFIELDAUDIORENDERER