VAOutdoorNoiseAudioRenderer.h 9.58 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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
121
122
123
124
125
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
151
152
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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
/*
 *  --------------------------------------------------------------------------------------------
 *
 *    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_VACORE_OUTDOOR_NOISE_AUDIO_RENDERER
#define IW_VACORE_OUTDOOR_NOISE_AUDIO_RENDERER

// VA includes
#include <VA.h>
#include <VAObjectPool.h>

#include "VAAudioRenderer.h"
#include "../../../Motion/VAMotionModelBase.h"
#include "../../../Motion/VASharedMotionModel.h"
#include "../../../Scene/VAScene.h"
#include "../../../VASourceListenerMetrics.h"
#include "../../../VACoreImpl.h"

// ITA includes
#include <ITADataSourceRealization.h>
#include <ITASampleBuffer.h>
#include <ITAVariableDelayLine.h>

// 3rdParty includes
#include <tbb/concurrent_queue.h>

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

// VA forwards
class CVASceneState;
class CVASceneStateDiff;
class CVASignalSourceManager;
class CVASoundSourceDesc;

// Internal forward declarations
class CVABATNSoundPath;
class CVABATNSoundPathFactory;


//! Outdoor Noise Audio Renderer (base class with generic receiver signals)
/**
  * Manages sound pathes from sound sources to a
  * generic receiver including multiple audio effects:
  *		- Directivity
  *		- Doppler-Shifts
  *		- Air-Absorption
  *		- 1/r-Distance-Law
  *     - Reflection
  *     - Diffraction
  *
  */
class CVAOutdoorNoiseAudioRenderer : public IVAAudioRenderer
{
public:
	CVAOutdoorNoiseAudioRenderer( const CVAAudioRendererInitParams& oParams );
	virtual ~CVAOutdoorNoiseAudioRenderer();

	//! Reset scene
	void Reset();

	//! Dummy
	inline void LoadScene( const std::string& ) {};

	//! 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 );

	//! Render incidence sample blocks for receivers
	/**
	  * This method renders the sound propagation based on the binaural approach
	  * by evaluating motion and events that are retarded in time, i.e. it switches
	  * filter parts and magnitudes of the HRIR or Directivity. It also considers
	  * the effective auralisation mode.
	  */
	void Process( const double dReceiverTime );

	void GetIncidenceDirectionIDs( const int iReceiverID, const std::vector< int >& viIncidenceDirectionIDs ) const;

	void GetReceiverIncidenceBuffer( const int iReceiverID, const int iIncidenceDirectionID, const ITASampleBuffer* pSamples ) const;

	CVAStruct GetParameters( const CVAStruct& oArgs );
	void SetParameters( const CVAStruct& oArgs );

protected:

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

	//! Interne Beschreibung einer Schallquelle
	class CVAONSoundSource : public CVAPoolObject
	{
	public:
		class Config
		{
		public:
			double dMotionModelWindowSize;
			double dMotionModelWindowDelay;

			int iMotionModelNumHistoryKeys;
		};

		inline CVAONSoundSource( const Config& oConf_ )
			: oConf( oConf_ )
		{};

		const Config oConf;
		CVASoundSourceDesc* pData;			//!< (Unversioned) Source description
		CVASharedMotionModel* pMotionModel;
		bool bDeleted;
		VAVec3 vPredPos;				//!< Estimated position
		VAVec3 vPredView;				//!< Estimated Orientation (View-Vektor)
		VAVec3 vPredUp;					//!< Estimated Orientation (Up-Vektor)
		bool bValidTrajectoryPresent;	//!< Estimation possible -> valid trajectory present

		// Pool-Konstruktor
		inline void PreRequest()
		{
			pData = nullptr;

			CVABasicMotionModel::Config oDefaultConfig;
			oDefaultConfig.dWindowDelay = oConf.dMotionModelWindowDelay;
			oDefaultConfig.dWindowSize = oConf.dMotionModelWindowSize;
			oDefaultConfig.iNumHistoryKeys = oConf.iMotionModelNumHistoryKeys;
			pMotionModel = new CVASharedMotionModel( new CVABasicMotionModel( oDefaultConfig ), true );

			bValidTrajectoryPresent = false;
		};

		inline void PreRelease()
		{
			delete pMotionModel;
			pMotionModel = nullptr;
		};

		inline double GetCreationTimestamp() const
		{
			return m_dCreationTimeStamp;
		};

	private:
		double m_dCreationTimeStamp;  //!< Date of creation within streaming context
	};


	//! Internal receiver representation
	class CVAONSoundReceiver : public CVAPoolObject
	{
	public:
		class Config
		{
		public:
			double dMotionModelWindowSize;
			double dMotionModelWindowDelay;

			int iMotionModelNumHistoryKeys;
		};

		inline CVAONSoundReceiver( CVACoreImpl* pCore, const Config& oConf )
			: pCore( pCore ), oConf( oConf )
		{};

		CVACoreImpl* pCore;
		const Config oConf;

		CVAListenerDesc* pData;				//!< (Unversioned) Listener description
		CVASharedMotionModel* pMotionModel;
		bool bDeleted;
		VAVec3 vPredPos;				//!< Estimated position
		VAVec3 vPredView;				//!< Estimated Orientation (View-Vektor)
		VAVec3 vPredUp;					//!< Estimated Orientation (Up-Vektor)
		bool bValidTrajectoryPresent;	//!< Estimation possible -> valid trajectory present

		//! Abstract spatial audio stream representation for receiver point
		class CIncidenceDirection
		{
		public:
			int iID;
			VAQuat qDirectionFromReceiver;
			ITASampleBuffer* psbBuffer;
			inline CIncidenceDirection() : iID( -1 ), psbBuffer( NULL ) {};
		};

		std::vector< CIncidenceDirection > voIncidenceDirections; //!< Abstract directional data at receiver point

		inline void PreRequest()
		{
			pData = nullptr;

			CVABasicMotionModel::Config oListenerMotionConfig;
			oListenerMotionConfig.dWindowDelay = oConf.dMotionModelWindowDelay;
			oListenerMotionConfig.dWindowSize = oConf.dMotionModelWindowSize;
			oListenerMotionConfig.iNumHistoryKeys = oConf.iMotionModelNumHistoryKeys;
			pMotionModel = new CVASharedMotionModel( new CVABasicMotionModel( oListenerMotionConfig ), true );

			bValidTrajectoryPresent = false;
		};

		// Pool-Destruktor
		inline void PreRelease()
		{
			delete pMotionModel;
			pMotionModel = nullptr;
		};
	};

protected:

	CVACoreImpl* m_pCore;					//!< Pointer to VACore

	CVASceneState* m_pCurSceneState;
	CVASceneState* m_pNewSceneState;

	int m_iCurGlobalAuralizationMode;

	IVAObjectPool* m_pSoundPathPool;
	CVABATNSoundPathFactory* m_pSoundPathFactory;
	std::list< CVABATNSoundPath* > m_lSoundPaths;

	IVAObjectPool* m_pSourcePool;
	IVAObjectPool* m_pListenerPool;

	std::map< int, CVAONSoundSource* > m_mSources;
	std::map< int, CVAONSoundReceiver* > m_mReceivers;

	int m_iDefaultVDLSwitchingAlgorithm;

	CVAONSoundReceiver::Config m_oDefaultReceiverConf; //!< Default listener config for factory object creation
	CVAONSoundSource::Config m_oDefaultSourceConf; //!< Default source config for factory object creation

	class CVABATNUpdateMessage : public CVAPoolObject
	{
	public:
		std::list< CVAONSoundSource* > vNewSources;
		std::list< CVAONSoundSource* > vDelSources;
		std::list< CVAONSoundReceiver* > vNewListeners;
		std::list< CVAONSoundReceiver* > vDelListeners;
		std::list< CVABATNSoundPath* > vNewPaths;
		std::list< CVABATNSoundPath* > vDelPaths;

		inline void PreRequest()
		{
			vNewSources.clear();
			vDelSources.clear();
			vNewListeners.clear();
			vDelListeners.clear();
			vNewPaths.clear();
			vDelPaths.clear();
		}
	};

	IVAObjectPool* m_pUpdateMessagePool; // really necessary?
	CVABATNUpdateMessage* m_pUpdateMessage;

	//! Data in context of audio process
	struct
	{
		tbb::concurrent_queue< CVABATNUpdateMessage* > m_qpUpdateMessages;	//!< Update messages list
		std::list< CVABATNSoundPath* > m_lSoundPaths;	//!< List of sound paths
		std::list< CVABATNSource* > m_lSources;			//!< List of sources
		std::list< CVABATNSoundReceiver* > m_lListener;		//!< List of listeners
		ITASampleBuffer m_sbTempBufD;	//!< Temporally used buffer to store a block of samples during processing (direct sound)
		ITASampleBuffer m_sbTempBufR;	//!< Temporally used buffer to store a block of samples during processing (reflected sound)
		ITAAtomicInt m_iResetFlag;	//!< Reset status flag: 0=normal_op, 1=reset_request, 2=reset_ack
		ITAAtomicInt m_iStatus;		//!< Current status flag: 0=stopped, 1=running
	} ctxAudio;

	void Init( const CVAStruct& oArgs );

	void ManageSoundPaths( const CVASceneState* pCurScene, const CVASceneState* pNewScene, const CVASceneStateDiff* pDiff );
	void UpdateSources();
	CVABATNSoundReceiver* CreateSoundReceiver( int iID, const CVAReceiverState* );
	void DeleteListener( int iID );
	CVABATNSource* CreateSoundSource( int iID, const CVASoundSourceState* );
	void DeleteSource( int iID );
	CVABATNSoundPath* CreateSoundPath( CVABATNSource*, CVABATNSoundReceiver* );
	void DeleteSoundPath( CVABATNSoundPath* );

	void UpdateTrajectories();
	void UpdateSoundPaths();

	void SampleTrajectoriesInternal( double dTime );

	void SyncInternalData();
	void ResetInternalData();

	friend class CVABATNSoundPath;
	friend class CVABATNSoundReceiverPoolFactory;
	friend class CVABATNSourcePoolFactory;

	//! Not for use, avoid C4512
	inline CVABinauralAirTrafficNoiseAudioRenderer operator=( const CVABinauralAirTrafficNoiseAudioRenderer & ) { VA_EXCEPT_NOT_IMPLEMENTED; };
};

#endif // IW_VACORE_OUTDOOR_NOISE_AUDIO_RENDERER