VABinauralClustering.cpp 2.23 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#define NOMINMAX

#include <limits>
#include <algorithm>

#include <math.h>

// VA
#include <VAObjectPool.h>

// Utils
#include "./VABinauralClustering.h"
#include "./VABinauralClusterPoolFactory.h"

15
VABinauralClustering::VABinauralClustering()
16 17 18 19 20
{
	IVAPoolObjectFactory* clusterFactory = new VABinauralClusterPoolFactory();
	_clusterPool = IVAObjectPool::Create(16, 2, clusterFactory, true);
};

21
VABinauralClustering::~VABinauralClustering(){};
22 23 24 25 26 27 28 29 30 31 32 33 34 35

void
VABinauralClustering::addSource(int sourceID, VABinauralSoundSource* source)
{
	_unassignedSources.insert(std::pair< int, VABinauralSoundSource* >(sourceID, source));
};

void
VABinauralClustering::init(int listenerID, VABinauralListener* listener, int numClusters)
{
	_listenerID = listenerID;
	_listener = listener;
	_numClusters = numClusters;
	_threshold = cos(180. / numClusters) * cos(180. / numClusters);
36 37 38 39

	_output = new ITASampleFrame(2, listener->output->GetLength(), true);

	_curState.reset(new VABinauralClusteringState(_numClusters, _listener));
40 41
}

42
ITASampleFrame*
Lucas Moesch's avatar
WIP  
Lucas Moesch committed
43
VABinauralClustering::getOutput()
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
{	
	// --
	_output->zero();

	// swap out clustering state
	_curState.reset(_nextState.release()); //TODO: only if next State is not null!

	std::map< int, VABinauralCluster*>::const_iterator it;
	for (it = _curState->clusters.begin(); it != _curState->clusters.end(); ++it)
	{
		ITASampleFrame* clusterOutput = it->second->getOutput();

		(*_output)[0] += (*clusterOutput)[0];
		(*_output)[1] += (*clusterOutput)[1];
	}

	return _output;
Lucas Moesch's avatar
WIP  
Lucas Moesch committed
61 62
}

63 64 65
void
VABinauralClustering::update()
{
Lucas Moesch's avatar
WIP  
Lucas Moesch committed
66 67
	VABinauralClusteringState* state = new VABinauralClusteringState(*_curState);
	//VABinauralClusteringState* del = _newState;
68 69 70 71 72 73 74 75 76 77

	// update unassigned sources
	std::map< int , VABinauralSoundSource* >::iterator it;

	for (it = _unassignedSources.begin(); it != _unassignedSources.end(); ++it)
	{
		state->addSource(it->first, it->second, _threshold, 0);
	}

	// TODO: refinement
78

79 80 81 82 83 84 85
	for (it = _unassignedSources.begin(); it != _unassignedSources.end(); ++it)
	{
		_assignedSources.insert(std::pair< int, VABinauralSoundSource* >(it->first, it->second));
	}

	_unassignedSources.clear();

Lucas Moesch's avatar
WIP  
Lucas Moesch committed
86 87
	_nextState.reset(state);

88 89 90 91 92 93 94 95
	// TODO: update fixed clustertrajectories
}

void
VABinauralClustering::PreRequest(){};

void
VABinauralClustering::PreRelease(){};