VABinauralClusterEngine.cpp 2.16 KB
Newer Older
1 2 3 4 5
#include "VABinauralClusterEngine.h"

// VA includes
#include <VAObjectPool.h>

Lucas Moesch's avatar
Lucas Moesch committed
6 7 8
// Utils
#include "./VABinauralClusteringPoolFactory.h">

9

Lucas Moesch's avatar
Lucas Moesch committed
10
VABinauralClusterEngine::VABinauralClusterEngine()
11
{
Lucas Moesch's avatar
Lucas Moesch committed
12
	IVAPoolObjectFactory* clusteringFactory = new VABinauralClusteringPoolFactory();
Lucas Moesch's avatar
Lucas Moesch committed
13
	_clusteringPool = IVAObjectPool::Create(16, 2, clusteringFactory, true);
14 15 16 17 18 19 20 21 22 23
}


VABinauralClusterEngine::~VABinauralClusterEngine()
{
}

void
VABinauralClusterEngine::update()
{
Lucas Moesch's avatar
Lucas Moesch committed
24 25 26
	for (auto const& clustering : _clusterings)
	{
		clustering.second->update();
27 28 29
	}
}

30
VABinauralClustering*
Lucas Moesch's avatar
Lucas Moesch committed
31
VABinauralClusterEngine::getClustering(const int listenerID)
32
{
Lucas Moesch's avatar
Lucas Moesch committed
33 34 35
	const int id = listenerID;

	auto it = _clusterings.find(id);
36 37 38 39

	return it->second;
}

40 41 42 43 44 45 46 47
void
VABinauralClusterEngine::addSource( int sourceID, VABinauralSoundSource* source )
{
	std::map< int, VABinauralClustering* >::iterator it;
	for (it = _clusterings.begin(); it != _clusterings.end(); ++it)
	{
		it->second->addSource(sourceID, source);
	}
Lucas Moesch's avatar
Lucas Moesch committed
48 49

	_sources.insert(std::pair< int, VABinauralSoundSource* >(sourceID, source));
50 51
}

Lucas Moesch's avatar
WIP  
Lucas Moesch committed
52 53 54 55 56 57 58 59 60 61
void
VABinauralClusterEngine::removeSource(int sourceID)
{
	std::map< int, VABinauralClustering* >::iterator it;
	for (it = _clusterings.begin(); it != _clusterings.end(); ++it)
	{
		it->second->removeSource(sourceID);
	}
}

62 63 64 65 66
void 
VABinauralClusterEngine::addListener(int listenerID, VABinauralListener* listener, clusterConfig_t& conf)
{
	VABinauralClustering* clustering = dynamic_cast< VABinauralClustering* >(_clusteringPool->RequestObject()); // Reference = 1

Lucas Moesch's avatar
Lucas Moesch committed
67
	clustering->init(listenerID, listener, conf.numCluster);
68 69 70

	// add local reference
	_clusterings.insert(std::pair< int, VABinauralClustering* >(listenerID, clustering));
Lucas Moesch's avatar
Lucas Moesch committed
71
	_listeners.insert(std::pair< int, VABinauralListener* >(listenerID, listener));
72

Lucas Moesch's avatar
Lucas Moesch committed
73 74 75 76 77
	// add preexisting sources
	for (auto const& sourceIt : _sources)
	{
		clustering->addSource(sourceIt.first, sourceIt.second);
	}
78 79 80 81 82 83
}

void
VABinauralClusterEngine::removeListener(int listenerID)
{
	std::map< int, VABinauralClustering* >::iterator it = _clusterings.find(listenerID);
84
	VABinauralClustering* clustering = it->second;
85 86
	_clusterings.erase(it);

87 88
	clustering->RemoveReference();

89 90 91 92
	/*
		TODO: foreach cluster in CL delete cluster
	*/
}