core.h 27.8 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_VA_CORE_IMPL
#define IW_VA_CORE_IMPL
Jonas Stienen's avatar
Jonas Stienen committed
16 17 18

#include <ITAAtomicPrimitives.h>
#include <ITACriticalSection.h>
19
#include <ITAStreamProbe.h>
20
#include <ITAStreamDetector.h>
Jonas Stienen's avatar
Jonas Stienen committed
21

22
#include <VAInterface.h>
23 24
#include <VAObject.h>
#include <VAObjectRegistry.h>
Jonas Stienen's avatar
Jonas Stienen committed
25

26 27 28 29 30 31 32
#include "../VACoreConfig.h"
#include "../VAObjectContainer.h"
#include "../VAProfiler.h"
#include "../Scene/VASceneState.h"
#include "../Rendering/VAAudioRenderer.h"

#include "../Medium/VAHomogeneousMedium.h"
33

Jonas Stienen's avatar
Jonas Stienen committed
34
#include <VistaInterProcComm/Concurrency/VistaMutex.h>
35
#include <VistaInterProcComm/Concurrency/VistaTicker.h>
Jonas Stienen's avatar
Jonas Stienen committed
36 37 38 39

#include <list>
#include <memory>

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

// VA base
#include <VACoreFactory.h>

// VA includes
#include "../Audiosignals/VAAudioSignalSourceManager.h"
#include "../Audiosignals/VAAudiofileSignalSource.h"
#include "../Audiosignals/VAAudiofileSignalSource.h"
#include "../Audiosignals/VAEngineSignalSource.h"
#include "../Audiosignals/VAMachineSignalSource.h"
#include "../Audiosignals/VASequencerSignalSource.h"
#include "../directivities/VADirectivityManager.h"
#include "../Rendering/VAAudioRenderer.h"
#include "../Rendering/VAAudioRendererRegistry.h"
#include "../Reproduction/VAAudioReproduction.h"
#include "../Reproduction/VAAudioReproductionRegistry.h"
#include "../Scene/VAScene.h"
#include "../Scene/VASoundSourceDesc.h"
#include "../Scene/VAListenerDesc.h"
#include "../Utils/VADebug.h"
#include "../Utils/VAUtils.h"
#include "../VAAudiostreamTracker.h"
#include "../VALog.h"
#include "../VACoreEventManager.h"
#include "../VACoreThread.h"
#include "../VASourceListenerMetrics.h"

#include "../Drivers/Audio/VAAudioDriverBackend.h"
#include "../Drivers/Audio/VAAudioDriverConfig.h"

#ifdef VACORE_WITH_AUDIO_BACKEND_ASIO
#include "../Drivers/Audio/VAASIOBackend.h"
#endif
#ifdef VACORE_WITH_AUDIO_BACKEND_PORTAUDIO
#include "../Drivers/Audio/VAPortaudioBackend.h"
#endif
#ifdef VACORE_WITH_AUDIO_BACKEND_VIRTUAL
#include "../Drivers/Audio/VAVirtualAudioDriverBackend.h"
#endif

// ITA includes
#include <ITAASCIITable.h>
#include <ITAClock.h>
#include <ITAException.h>
#include <ITAFileSystemUtils.h>
#include <ITAFunctors.h>
#include <ITAStreamDetector.h>
#include <ITASoundSample.h>
#include <ITASoundSampler.h>
#include <ITASoundSamplePool.h>
#include <ITAStreamAmplifier.h>
#include <ITAStreamPatchBay.h>
#include <ITAStreamProbe.h>
#include <ITAStringUtils.h>

// Vista includes
#include <VistaTools/VistaFileSystemFile.h>
#include <VistaTools/VistaFileSystemDirectory.h>

// 3rdParty includes
#include <DAFF.h>

// STL includes
#include <algorithm>
#include <iomanip>
#include <iostream>


// We know about unreferenced formal parameters. There are a lot of unused methods for future use.
#pragma warning( disable : 4100 )

/*

	Informationen
	=-=-=-=-=-=-=

	Thread-safety & locking

	Alle durch die Schnittstelle nach aussen angebotenen Funktionen, werden
	gegen Reentrance grob-granular mittels eines kritischen Bereiches gesperrt.
	Damit sind auch parallele Calls auf unterschiedliche Methoden der Klasse
	unterbunden. Sollte dies zu Performance-Problemen fhren, kann ein
	verfeinerter Locking-Mechanismus entwickelt werden. Zunchst mal aber so.


	TODO: berall sicherstellen, das ITAExceptions zu VAExceptions umgebaut werden!!!

	*/


// --= Hilfsmakros =--

// berprfung ob Initialisiert
#define VA_CHECK_INITIALIZED \
{ if (m_iState != VA_CORESTATE_READY) VA_EXCEPT2(MODAL_ERROR, "Core not initialized"); }

// Mutex-Lock welches parallelen Methoden-Mehrfracheintritt (reentrance) im Methoden-Scope verhindert
#define VA_NO_REENTRANCE \
ITACriticalSectionLock oReentranceLock(m_csReentrance)

// Manuelles das Lock gegen parallelen Methoden-Mehrfracheintritt (reentrance) holen
#define VA_LOCK_REENTRANCE \
m_csReentrance.enter()

// Manuelle das Lock gegen parallelen Methoden-Mehrfracheintritt (reentrance) freigeben 
#define VA_UNLOCK_REENTRANCE \
m_csReentrance.leave()

/*

	Sichere Ausnahmebehandlung

	Problem: Intern knnen auch andere Typen von Ausnahmen als
	CVAException geworfen werden. Nach aussen hin drfen
	aber NUR CVAExceptions geworfen werden (Konsistent)

	Lsung: TRY-/CATCH-Makros fr abgesicherte Bereiche in allen Methoden
	der externen Schnittstelle. Zweistufiger Aufbau.
	1. (innen) Fange alle Exception-Typen und konvertiere sie in CVAExceptions
	2. (aussen) Fange die einzig mgl. CVAExceptions und biete
	gemeinsamen Catch-Weg zur Problemlsung (Aufrumen) an

	try {
	try {
	// Code ...
	} catch (ITAException& e) {
	// Konvertiere zu CVAException
	} catch (VistaExceptionBase& e) {
	// Konvertiere zu CVAException
	} catch (...)
	// Generiere unerwartete CVAException
	}
	} catch (CVAException& e) {
	// Gemeinsames Aufrumen
	}

	Beispiel:

	VA_TRY {
	// Code ..
	} VA_CATCH {
	// Mach was ...
	}

	Hinweis: Initiale/finale Geschweifte Klammer fehlen, da diese hinter die Makros geschrieben werden

	*/

#define VA_TRY \
try { try

#define VA_CATCH(EXPR) \
catch( CVAException& e ) { throw e; } \
catch( ITAException& e ) { throw convert2VAException( e ); } \
catch( VistaExceptionBase& e ) { throw convert2VAException( e ); } \
catch( ... ) { throw getDefaultUnexpectedVAException(); } \
} catch( CVAException& EXPR )

#define VA_FINALLY \
catch( CVAException& e ) { throw e; } \
catch( ITAException& e ) { throw convert2VAException( e ); } \
catch( VistaExceptionBase& e ) { throw convert2VAException(e); } \
catch( ... ) { throw getDefaultUnexpectedVAException(); } \
} catch( ... )

#define VA_RETHROW \
catch( CVAException& e ) { throw e; } \
catch( ITAException& e ) { throw convert2VAException( e ); } \
catch( VistaExceptionBase& e ) { throw convert2VAException( e ); } \
catch( ... ) { throw getDefaultUnexpectedVAException(); } \
} catch( ... ) { throw; }


Jonas Stienen's avatar
Jonas Stienen committed
213

214

215
class CVACoreImpl : public IVAInterface, public CVAObject, public VistaTicker::AfterPulseFunctor
Jonas Stienen's avatar
Jonas Stienen committed
216 217
{
public:
218
	CVACoreImpl( const CVAStruct& oArgs, std::ostream* pos );
Jonas Stienen's avatar
Jonas Stienen committed
219 220
	virtual ~CVACoreImpl();

221
	void SetOutputStream( std::ostream* pos );
222
	void GetVersionInfo( CVAVersionInfo* ) const;
Jonas Stienen's avatar
Jonas Stienen committed
223 224 225 226 227 228 229 230

	int GetState() const;
	void Initialize();
	void Finalize();
	void Reset();

	void Tidyup();

231 232
	void AttachEventHandler( IVAEventHandler* pCoreEventHandler );
	void DetachEventHandler( IVAEventHandler* pCoreEventHandler );
233 234 235 236

	void RegisterModule( CVAObject* pObject );
	void GetModules( std::vector< CVAModuleInfo >& m_viModuleInfos ) const;
	CVAStruct CallModule( const std::string& sModuleName, const CVAStruct& oArgs );
237
	CVAStruct GetSearchPaths() const;
238 239 240
	CVAStruct GetCoreConfiguration( const bool ) const;
	CVAStruct GetHardwareConfiguration() const;
	CVAStruct GetFileList( const bool bRecursive = true, const std::string& sFileSuffixFilter = "*" ) const;
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

	// Directivities
	int CreateDirectivityFromParameters( const CVAStruct& oParams, const std::string& sName = "" );
	bool DeleteDirectivity( const int iID );
	CVADirectivityInfo GetDirectivityInfo( const int iID ) const;
	void GetDirectivityInfos( std::vector< CVADirectivityInfo >& voDest ) const;
	void SetDirectivityName( const int iID, const std::string& sName );
	std::string GetDirectivityName( const int iID ) const;
	void SetDirectivityParameters( const int iID, const CVAStruct& oParams );
	CVAStruct GetDirectivityParameters( const int iID, const CVAStruct& oParams ) const;

	// Acoustic materials
	int CreateAcousticMaterial( const CVAAcousticMaterial& oMaterial, const std::string& sName = "" );
	int CreateAcousticMaterialFromParameters( const CVAStruct& oParams, const std::string& sName = "" );
	bool DeleteAcousticMaterial( const int iID );
	CVAAcousticMaterial GetAcousticMaterialInfo( const int iID ) const;
	void GetAcousticMaterialInfos( std::vector< CVAAcousticMaterial >& voDest ) const;
	void SetAcousticMaterialName( const int iID, const std::string& sName );
	std::string GetAcousticMaterialName( const int iID ) const;
	void SetAcousticMaterialParameters( const int iID, const CVAStruct& oParams );
	CVAStruct GetAcousticMaterialParameters( const int iID, const CVAStruct& oParams ) const;

	// Geometry meshes
	int CreateGeometryMesh( const CVAGeometryMesh& oMesh, const std::string& sName = "" );
	int CreateGeometryMeshFromParameters( const CVAStruct& oParams, const std::string& sName = "" );
	bool DeleteGeometryMesh( const int iID );
	CVAGeometryMesh GetGeometryMesh( const int iID ) const;
	void GetGeometryMeshIDs( std::vector< int >& viIDs ) const;
	void SetGeometryMeshName( const int iID, const std::string& sName );
	std::string GetGeometryMeshName( const int iID ) const;
	void SetGeometryMeshParameters( const int iID, const CVAStruct& oParams );
	CVAStruct GetGeometryMeshParameters( const int iID, const CVAStruct& oParams ) const;
	void SetGeometryMeshEnabled( const int iID, const bool bEnabled = true );
	bool GetGeometryMeshEnabled( const int iID ) const;

	// Signal sources
	std::string CreateSignalSourceBufferFromParameters( const CVAStruct& oParams, const std::string& sName = "" );
	std::string CreateSignalSourceTextToSpeech( const std::string& sName = "" );
	std::string CreateSignalSourceSequencer( const std::string& sName = "" );
	std::string CreateSignalSourceNetworkStream( const std::string& sInterface, const int iPort, const std::string& sName = "" );
	std::string CreateSignalSourceEngine( const CVAStruct& oParams, const std::string& sName = "" );
	std::string CreateSignalSourceMachine( const CVAStruct& oParams, const std::string& sName = "" );
283 284 285 286
	bool DeleteSignalSource( const std::string& sID );
	std::string RegisterSignalSource( IVAAudioSignalSource* pSignalSource, const std::string& sName = "" );
	bool UnregisterSignalSource( IVAAudioSignalSource* pSignalSource );
	CVASignalSourceInfo GetSignalSourceInfo( const std::string& sSignalSourceID ) const;
287 288 289 290 291 292
	void GetSignalSourceInfos( std::vector< CVASignalSourceInfo >& voInfos ) const;
	int GetSignalSourceBufferPlaybackState( const std::string& sSignalSourceID ) const;
	void SetSignalSourceBufferPlaybackAction( const std::string& sSignalSourceID, const int iPlaybackAction );
	void SetSignalSourceBufferPlaybackPosition( const std::string& sSignalSourceID, const double dPlaybackPosition );
	void SetSignalSourceBufferLooping( const std::string& sSignalSourceID, const bool bLooping = true );
	bool GetSignalSourceBufferLooping( const std::string& sSignalSourceID ) const;
Jonas Stienen's avatar
Jonas Stienen committed
293 294
	void SetSignalSourceParameters( const std::string& sSignalSourceID, const CVAStruct& oParams );
	CVAStruct GetSignalSourceParameters( const std::string& sSignalSourceID, const CVAStruct& oParams ) const;
295 296 297
	int AddSignalSourceSequencerSample( const std::string& sSignalSourceID, const CVAStruct& oArgs );
	int AddSignalSourceSequencerPlayback( const std::string& sSignalSourceID, const int iSoundID, const int iFlags, const double dTimeCode );
	void RemoveSignalSourceSequencerSample( const std::string& sSignalSourceID, const int iSoundID );
Jonas Stienen's avatar
Jonas Stienen committed
298

299
	// Synced updates
300 301 302
	bool GetUpdateLocked() const;
	void LockUpdate();
	int UnlockUpdate();
Jonas Stienen's avatar
Jonas Stienen committed
303

304 305 306 307 308 309 310 311 312 313 314 315
	// Sound sources
	int CreateSoundSource( const std::string& sName = "" );
	void GetSoundSourceIDs( std::vector< int >& viSoundSourceIDs );
	CVASoundSourceInfo GetSoundSourceInfo( const int iID ) const;
	int CreateSoundSourceExplicitRenderer( const std::string& sRendererID, const std::string& sName = "" );
	int DeleteSoundSource( const int iID );
	void SetSoundSourceEnabled( const int iID, const bool bEnabled = true );
	bool GetSoundSourceEnabled( const int iID ) const;
	std::string GetSoundSourceName( const int iID ) const;
	void SetSoundSourceName( const int iID, const std::string& sName );
	std::string GetSoundSourceSignalSource( const int iID ) const;
	int GetSoundSourceGeometryMesh( const int iID ) const;
316
	void SetSoundSourceGeometryMesh( const int iSoundSourceID, const int iGeometryMeshID );
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368
	void SetSoundSourceSignalSource( const int iSoundSourceID, const std::string& sSignalSourceID );
	int GetSoundSourceAuralizationMode( const int iID ) const;
	void SetSoundSourceAuralizationMode( const int iSoundSourceID, const int iAuralizationMode );
	void SetSoundSourceParameters( const int iID, const CVAStruct& oParams );
	CVAStruct GetSoundSourceParameters( const int iID, const CVAStruct& oParams ) const;
	int GetSoundSourceDirectivity( const int iID ) const;
	void SetSoundSourceDirectivity( const int iSoundSourceID, const int iDirectivityID );
	double GetSoundSourceSoundPower( const int iID ) const;
	void SetSoundSourceSoundPower( const int iSoundSourceID, const double dSoundPower );
	bool GetSoundSourceMuted( const int iID ) const;
	void SetSoundSourceMuted( const int iID, const bool bMuted = true );
	void GetSoundSourcePose( const int iID, VAVec3& vPos, VAQuat& qOrient ) const;
	void SetSoundSourcePose( const int iID, const VAVec3& vPos, const VAQuat& qOrient );
	VAVec3 GetSoundSourcePosition( const int iID ) const;
	void SetSoundSourcePosition( const int iID, const VAVec3& v3Pos );
	VAQuat GetSoundSourceOrientation( const int iID ) const;
	void SetSoundSourceOrientation( const int iID, const VAQuat& qOrient );
	void GetSoundSourceOrientationVU( const int iID, VAVec3& v3View, VAVec3& v3Up ) const;
	void SetSoundSourceOrientationVU( const int iID, const VAVec3& v3View, const VAVec3& v3Up );

	// Sound receiver
	void GetSoundReceiverIDs( std::vector< int >& viIDs ) const;
	int CreateSoundReceiver( const std::string& sName = "" );
	int CreateSoundReceiverExplicitRenderer( const std::string& sRendererID, const std::string& sName = "" );
	int DeleteSoundReceiver( const int iID );
	CVASoundReceiverInfo GetSoundReceiverInfo( const int iID ) const;
	void SetSoundReceiverEnabled( const int iID, const bool bEnabled = true );
	bool GetSoundReceiverEnabled( const int iID ) const;
	std::string GetSoundReceiverName( const int iID ) const;
	void SetSoundReceiverName( const int iID, const std::string& sName );
	int GetSoundReceiverAuralizationMode( const int iID ) const;
	void SetSoundReceiverAuralizationMode( const int iSoundReceiverID, const int iAuralizationMode );
	void SetSoundReceiverParameters( const int iID, const CVAStruct& oParams );
	CVAStruct GetSoundReceiverParameters( const int iID, const CVAStruct& oArgs ) const;
	int GetSoundReceiverDirectivity( const int iID ) const;
	void SetSoundReceiverDirectivity( const int iSoundReceiverID, const int iDirectivityID );
	int GetSoundReceiverGeometryMesh( const int iID ) const;
	void SetSoundReceiverGeometryMesh( const int iSoundReceiverID, const int iGeometryMeshID );
	void GetSoundReceiverPose( const int iID, VAVec3& vPos, VAQuat& qOrient ) const;
	void SetSoundReceiverPose( const int iID, const VAVec3& vPos, const VAQuat& qOrient );
	VAVec3 GetSoundReceiverPosition( const int iID ) const;
	void SetSoundReceiverPosition( const int iID, const VAVec3& v3Pos );
	void GetSoundReceiverOrientationVU( const int iID, VAVec3& vView, VAVec3& vUp ) const;
	void SetSoundReceiverOrientationVU( const int iID, const VAVec3& vView, const VAVec3& vUp );
	VAQuat GetSoundReceiverOrientation( const int iID ) const;
	void SetSoundReceiverOrientation( const int iID, const VAQuat& qOrient );
	VAQuat GetSoundReceiverHeadAboveTorsoOrientation( const int iID ) const;
	void SetSoundReceiverHeadAboveTorsoOrientation( const int iID, const VAQuat& qOrient );
	void GetSoundReceiverRealWorldPositionOrientationVU( const int iID, VAVec3& v3Pos, VAVec3& v3View, VAVec3& v3Up ) const;
	void SetSoundReceiverRealWorldPositionOrientationVU( const int iID, const VAVec3& v3Pos, const VAVec3& v3View, const VAVec3& v3Up );
	void GetSoundReceiverRealWorldPose( const int iID, VAVec3& v3Pos, VAQuat& qOrient ) const;
	void SetSoundReceiverRealWorldPose( const int iID, const VAVec3& v3Pos, const VAQuat& qOrient );
369 370
	VAQuat GetSoundReceiverRealWorldHeadAboveTorsoOrientation( const int iID ) const;
	void SetSoundReceiverRealWorldHeadAboveTorsoOrientation( const int iID, const VAQuat& qOrient );
371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409


	// Homogeneous medium
	void SetHomogeneousMediumSoundSpeed( const double dSoundSpeed );
	double GetHomogeneousMediumSoundSpeed() const;
	void SetHomogeneousMediumTemperature( const double dDegreesCentigrade );
	double GetHomogeneousMediumTemperature() const;
	void SetHomogeneousMediumStaticPressure( const double dPressurePascal );
	double GetHomogeneousMediumStaticPressure() const;
	void SetHomogeneousMediumRelativeHumidity( const double dRelativeHumidityPercent );
	double GetHomogeneousMediumRelativeHumidity();
	void SetHomogeneousMediumShiftSpeed( const VAVec3& v3TranslationSpeed );
	VAVec3 GetHomogeneousMediumShiftSpeed() const;
	void SetHomogeneousMediumParameters( const CVAStruct& oParams );
	CVAStruct GetHomogeneousMediumParameters( const CVAStruct& oArgs );

	//! Scenes
	std::string CreateScene( const CVAStruct& oParams, const std::string& sName = "" );
	void GetSceneIDs( std::vector< std::string >& vsIDs ) const;
	CVASceneInfo GetSceneInfo( const std::string& sID ) const;
	std::string GetSceneName( const std::string& sID ) const;
	void SetSceneName( const std::string& sID, const std::string& sName );
	void SetSceneEnabled( const std::string& sID, const bool bEnabled = true );
	bool GetSceneEnabled( const std::string& sID ) const;

	// Sound portals
	int CreateSoundPortal( const std::string& sName = "" );
	void GetSoundPortalIDs( std::vector< int >& viIDs );
	CVASoundPortalInfo GetSoundPortalInfo( const int iID ) const;
	std::string GetSoundPortalName( const int iID ) const;
	void SetSoundPortalName( const int iID, const std::string& sName );
	void SetSoundPortalMaterial( const int iSoundPortalID, const int iMaterialID );
	int GetSoundPortalMaterial( const int iSoundPortalID ) const;
	void SetSoundPortalNextPortal( const int iSoundPortalID, const int iNextSoundPortalID );
	int GetSoundPortalNextPortal( const int iSoundPortalID ) const;
	void SetSoundPortalSoundReceiver( const int iSoundPortalID, const int iSoundReceiverID );
	int GetSoundPortalSoundReceiver( const int iSoundPortalID ) const;
	void SetSoundPortalSoundSource( const int iSoundPortalID, const int iSoundSourceID );
	int GetSoundPortalSoundSource( const int iSoundPortalID ) const;
410
	CVAStruct GetSoundPortalParameters( const int iID, const CVAStruct& oArgs ) const;
411 412 413 414 415 416 417
	void SetSoundPortalParameters( const int iID, const CVAStruct& oParams );
	void SetSoundPortalPosition( const int iSoundPortalID, const VAVec3& vPos );
	VAVec3 GetSoundPortalPosition( const int iSoundPortalID ) const;
	void SetSoundPortalOrientation( const int iSoundPortalID, const VAQuat& qOrient );
	VAQuat GetSoundPortalOrientation( const int iSoundPortalID ) const;
	void SetSoundPortalEnabled( const int iSoundPortalID, const bool bEnabled = true );
	bool GetSoundPortalEnabled( const int iSoundPortalID ) const;
Jonas Stienen's avatar
Jonas Stienen committed
418 419

	// Rendering
420
	void GetRenderingModules( std::vector< CVAAudioRendererInfo >&, const bool ) const;
Jonas Stienen's avatar
Jonas Stienen committed
421
	double GetRenderingModuleGain( const std::string& sModuleID ) const;
422
	void SetRenderingModuleGain( const std::string& sModuleID, const double dGain );
423
	bool GetRenderingModuleMuted( const std::string& sModuleID ) const;
424 425 426 427 428
	void SetRenderingModuleMuted( const std::string& sModuleID, const bool bMuted );
	void SetRenderingModuleParameters( const std::string& sModuleID, const CVAStruct& oParams );
	CVAStruct GetRenderingModuleParameters( const std::string& sModuleID, const CVAStruct& oParams ) const;
	int GetRenderingModuleAuralizationMode( const std::string& sModuleID ) const;
	void SetRenderingModuleAuralizationMode( const std::string& sModuleID, const int iAuralizationMode );
Jonas Stienen's avatar
Jonas Stienen committed
429 430

	// Reproduction
431 432
	void GetReproductionModules( std::vector< CVAAudioReproductionInfo >&, const bool ) const;
	void SetReproductionModuleMuted( const std::string& sModuleID, const bool bMuted );
Jonas Stienen's avatar
Jonas Stienen committed
433
	double GetReproductionModuleGain( const std::string& sModuleID ) const;
434
	void SetReproductionModuleGain( const std::string& sModuleID, const double dGain );
435
	bool GetReproductionModuleMuted( const std::string& sModuleID ) const;
436 437
	void SetReproductionModuleParameters( const std::string& sModuleID, const CVAStruct& oParams );
	CVAStruct GetReproductionModuleParameters( const std::string& sModuleID, const CVAStruct& oParams ) const;
Jonas Stienen's avatar
Jonas Stienen committed
438

439 440 441
	// Global controls
	bool GetInputMuted() const;
	void SetInputMuted( const bool bMuted );
Jonas Stienen's avatar
Jonas Stienen committed
442
	double GetInputGain() const;
443
	void SetInputGain( const double dGain );
Jonas Stienen's avatar
Jonas Stienen committed
444
	double GetOutputGain() const;
445 446 447
	void SetOutputGain( const double dGain );
	bool GetOutputMuted() const;
	void SetOutputMuted( const bool bMuted );
Jonas Stienen's avatar
Jonas Stienen committed
448
	int GetGlobalAuralizationMode() const;
449
	void SetGlobalAuralizationMode( const int iAuralizationMode );
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
450 451 452 453
	int GetActiveSoundReceiver() const;
	void SetActiveSoundReceiver( const int iSoundReceiverID );
	int GetActiveSoundReceiverExplicitRenderer( const std::string& sRendererID ) const;
	void SetActiveSoundReceiverExplicitRenderer( const int iSoundReceiverID, const std::string& sRendererID );
Jonas Stienen's avatar
Jonas Stienen committed
454
	double GetCoreClock() const;
455 456
	void SetCoreClock( const double dSeconds );

457
	std::string SubstituteMacros( const std::string& sStr ) const;
Jonas Stienen's avatar
Jonas Stienen committed
458 459 460
	std::string FindFilePath( const std::string& sFilePath ) const;

	CVAObjectInfo GetObjectInfo() const;
461
	CVAStruct CallObject( const CVAStruct& oArgs );
462

463 464
	// Ticker callback
	bool operator()();
Jonas Stienen's avatar
Jonas Stienen committed
465 466 467 468 469 470 471

	const CVACoreConfig* GetCoreConfig() const;
	const CVASceneManager* GetSceneManager() const;
	const CVAAudioSignalSourceManager* GetSignalSourceManager() const;

	bool IsStreaming() const;

472
	CVAHomogeneousMedium oHomogeneousMedium;
473 474


Jonas Stienen's avatar
Jonas Stienen committed
475
private:
476 477 478 479 480 481
	ITACriticalSection m_csReentrance;  //!< Lock for reentrance check
	ITACriticalSection m_csSyncMod;		//!< Lock fr synchronisierte Szene-Modifikationen
	VistaMutex m_mxSyncModLock;			//!< Synchronisierungs-Token
	ITAAtomicLong m_lSyncModOwner;		//!< ID des Thread der Synchronisierungs-Token hat
	long m_lSyncModSpinCount;			//!< Spin count der Locks auf das Synchronisierungs-Token
	double m_dSyncEntryTime;			//!< Time when beginsync was entered
Jonas Stienen's avatar
Jonas Stienen committed
482

483
	CVAObjectRegistry m_oModules;		//!< Komponenten Registrierung
Jonas Stienen's avatar
Jonas Stienen committed
484 485

	ITAAtomicInt m_iGlobalAuralizationMode;
486
	VistaTicker* m_pTicker;
Jonas Stienen's avatar
Jonas Stienen committed
487 488 489

	void InitializeAudioDriver();
	void FinalizeAudioDriver();
490 491
	void FinalizeRenderingModules();
	void FinalizeReproductionModules();
Jonas Stienen's avatar
Jonas Stienen committed
492 493 494

	IVAAudioDriverBackend* m_pAudioDriverBackend;
	ITAStreamAmplifier* m_pInputAmp;
495 496
	ITAStreamPatchbay* m_pR2RPatchbay;		//!< Patchbay linking audio renderers to audio reproduction modules
	ITAStreamPatchbay* m_pOutputPatchbay;	//!< Patchbay linking audio reproduction modules to hardware outputs
Michael Kohnen's avatar
merging  
Michael Kohnen committed
497

498 499
	ITAStreamDetector* m_pInputStreamDetector;
	ITAStreamDetector* m_pOutputStreamDetector;
Michael Kohnen's avatar
merging  
Michael Kohnen committed
500

Jonas Stienen's avatar
Jonas Stienen committed
501 502 503 504
	CVAAudiostreamTracker* m_pOutputTracker;

	// --= Signal sources and sounds =----------------------------------

505
	CVAAudioSignalSourceManager* m_pSignalSourceManager;
Jonas Stienen's avatar
Jonas Stienen committed
506 507 508 509 510
	ITASoundSamplePool* m_pGlobalSamplePool;
	ITASoundSampler* m_pGlobalSampler;	// Sequencer fr ambient sounds

	// --= Directivity & HRIRs =----------------------------------------

511
	CVADirectivityManager* m_pDirectivityManager;
Jonas Stienen's avatar
Jonas Stienen committed
512 513 514

	// --= Rendering & Reproduction =-----------------------------------

515
	class CVAAudioRendererDesc : public CVAAudioRendererInfo
Jonas Stienen's avatar
Jonas Stienen committed
516 517
	{
	public:
518
		IVAAudioRenderer* pInstance;
Jonas Stienen's avatar
Jonas Stienen committed
519 520
		int iR2RPatchBayInput;							//!< Input on the renderer-reproduction patch bay
		std::vector< std::string > vsOutputs;			//!< Target reproduction modules
521
		ITAStreamProbe* pOutputRecorder; //!< If a non-nullptr recorder is set, it will be deleted on destruction
522
		ITAStreamDetector* pOutputDetector; //!< If a non-nullptr detector is set, it will be deleted on destruction
Jonas Stienen's avatar
Jonas Stienen committed
523

524 525
		inline CVAAudioRendererDesc( IVAAudioRenderer* pInstance )
			: pInstance( pInstance )
526
			, pOutputRecorder( NULL )
527
			, pOutputDetector( NULL )
528 529
		{
		};
530 531 532 533

		inline void Finalize()
		{
			delete pInstance;
534
			delete pOutputRecorder;
535 536
			delete pOutputDetector;
		};
Jonas Stienen's avatar
Jonas Stienen committed
537
	};
538
	std::vector< CVAAudioRendererDesc > m_voRenderers;
Jonas Stienen's avatar
Jonas Stienen committed
539

540
	class CVAAudioReproductionModuleDesc : public CVAAudioReproductionInfo
Jonas Stienen's avatar
Jonas Stienen committed
541 542
	{
	public:
543
		IVAAudioReproduction* pInstance;
Jonas Stienen's avatar
Jonas Stienen committed
544 545 546
		int iR2RPatchBayOutput;				//! Output channel on the renderer-reproduction patch bay
		int iOutputPatchBayInput;			//! Input channel on the output patchbay
		std::vector< const CVAHardwareOutput* > vpOutputs;
547 548
		ITAStreamDetector* pInputDetector; //!< If a non-nullptr detector is set, it will be deleted on destruction
		ITAStreamDetector* pOutputDetector; //!< If a non-nullptr detector is set, it will be deleted on destruction
549 550
		ITAStreamProbe* pInputRecorder; //!< If a non-nullptr recorder is set, it will be deleted on destruction
		ITAStreamProbe* pOutputRecorder; //!< If a non-nullptr recorder is set, it will be deleted on destruction
Jonas Stienen's avatar
Jonas Stienen committed
551

552
		inline CVAAudioReproductionModuleDesc( IVAAudioReproduction* pInstance )
553
			: pInstance( pInstance )
554 555 556 557 558 559 560 561
			, pInputDetector( NULL )
			, pOutputDetector( NULL )
			, pInputRecorder( NULL )
			, pOutputRecorder( NULL )
		{
		};

		inline void Finalize()
562
		{
563 564 565 566 567
			delete pInstance;
			delete pInputDetector;
			delete pOutputDetector;
			delete pInputRecorder;
			delete pOutputRecorder;
568
		};
Jonas Stienen's avatar
Jonas Stienen committed
569
	};
570
	std::vector< CVAAudioReproductionModuleDesc > m_voReproductionModules;
Jonas Stienen's avatar
Jonas Stienen committed
571 572 573

	// --= Scene =------------------------------------------------------

574
	CVASceneManager* m_pSceneManager;
Jonas Stienen's avatar
Jonas Stienen committed
575 576
	CVASceneState* m_pNewSceneState;	//! Neuer Szenezustand fr nderungen

Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
577 578 579
	ITAAtomicInt m_iCurActiveSoundReceiver;	// Aktueller aktiver Hrer im Core-Thread
	ITAAtomicInt m_iNewActiveSoundReceiver;	// Neuer aktiver Hrer fr den Core-Thread
	ITAAtomicInt m_iUpdActiveSoundReceiver;	// Neuer aktiver Hrer (Puffer fr nderung)
Jonas Stienen's avatar
Jonas Stienen committed
580 581 582 583 584 585 586 587 588 589

	// --= Progress =---------------------------------------------------

	ITACriticalSection m_csProgress;
	CVAProgress m_Progress;	// Fortschritt der momentan durchgefhrten Aktion

	// --= Core-Thread =------------------------------------------------

	CVACoreThread* m_pCoreThread;

590 591
	class CVACoreThreadData
	{
Jonas Stienen's avatar
Jonas Stienen committed
592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607
	public:
		int iSceneStateID;					// Szene-Zustand (ID)

	};

	CVACoreThreadData m_xCoreThreadData;
	CVASceneState* m_pCurSceneState;

	// --= Other =------------------------------------------------------

	CVACoreConfig m_oCoreConfig;
	ITAAtomicInt m_iState;					// Modaler Zustand (siehe core states)
	double m_dOutputGain, m_dInputGain;
	bool m_bOutputMuted, m_bInputMuted;

	ITAStreamProbe* m_pStreamProbeDeviceInput;
608
	ITAStreamProbe* m_pStreamProbeDeviceOutput;
Jonas Stienen's avatar
Jonas Stienen committed
609 610 611 612 613 614 615

	ITAClock* m_pClock;
	double m_dStreamClockOffset;			// Offset des Stream-Starts
	ITAAtomicFloat m_fCoreClockOffset;		// Offset der Core-Clock

	// --= Profiling =--

616
	CVAProfilerMeasure m_oCoreThreadLoopTotalDuration;
Jonas Stienen's avatar
Jonas Stienen committed
617 618 619

	// -------------------------------------------------

620
	void InitProgress( const std::string& sAction, const std::string& sSubaction, const int iMaxStep );
Jonas Stienen's avatar
Jonas Stienen committed
621

622
	void SetProgress( const std::string& sAction, const std::string& sSubaction, const int iCurrentStep );
Jonas Stienen's avatar
Jonas Stienen committed
623 624 625

	void FinishProgress();

626
	CVACoreEventManager* m_pEventManager;
Jonas Stienen's avatar
Jonas Stienen committed
627 628 629 630 631 632 633

	// Diese Hilfsmethoden bedienen die Locks um die serielle Ausfhrung
	// externer Methoden zu gewhrleisten und die Reentrance zu blockieren
	// (siehe externe Methoden).

	// Schleifen-Funktion des Kern-Threads
	void CoreThreadLoop();
634

635 636 637 638 639 640 641 642
	//!< Sends detector values to clients
	void SendAudioDeviceDetectorUpdateEvent();

	//!< Sends rendering detector values to clients
	void SendRenderingModuleOutputDetectorsUpdateEvents();

	//!< Sends reproduction detector values to clients
	void SendReproductionModuleOIDetectorsUpdateEvents();
643

Jonas Stienen's avatar
Jonas Stienen committed
644 645 646 647 648 649 650 651 652 653 654
	//! Initialize rendering modules
	void InitializeAudioRenderers();

	//! Initialize reproduction modules
	void InitializeReproductionModules();

	//! Patch renderer and reproduction modules
	void PatchRendererToReproductionModules();

	//! Patch reproduction modules and output
	void PatchReproductionModulesToOutput();
655

656 657 658 659 660
	//! Recursive file search
	void RecursiveFileList( const std::string& sBasePath, CVAStruct&, const std::string sFileSuffixMask ) const;
	void FileList( const std::string& sBasePath, std::vector< std::string >& vsFileList, const std::string& sFileSuffixMask ) const;
	void FolderList( const std::string& sBasePath, std::vector< std::string >& vsFolderList ) const;

Jonas Stienen's avatar
Jonas Stienen committed
661 662 663 664
	friend class CVACoreThread;
	friend class CVAAudioSignalSourceManager;
};

665
#endif // IW_VA_CORE_IMPL