Commit 172dbc8c authored by Lucas Moesch's avatar Lucas Moesch

Fixed assertion bugs.

parent 188a745c
......@@ -57,6 +57,31 @@ VABinauralCluster::init(int sourceID, VABinauralSoundSource* source, VABinauralL
++numSources;
}
void
VABinauralCluster::init(VABinauralCluster* cluster)
{
_listener = cluster->_listener;
_listenerPos = _listener->predPos;
_clusterSourcePos = cluster->_clusterSourcePos;
_clusterSourceToListenerPos = _clusterSourcePos - _listenerPos;
_output = new ITASampleFrame(2, _listener->output->GetLength(), true);
_tmpChL.Init(_listener->output->GetLength(), true);
_tmpChR.Init(_listener->output->GetLength(), true);
maxError = cluster->maxError;
std::map< int, VABinauralSoundSource*>::const_iterator it;
for (it = cluster->_sources.begin(); it != cluster->_sources.end(); ++it)
{
_sources.insert(std::pair<int, VABinauralSoundSource*>(it->first, it->second));
it->second->AddReference();
}
numSources = cluster->numSources;
}
ITASampleFrame*
VABinauralCluster::getOutput()
{
......
......@@ -24,6 +24,9 @@ public:
void
init(int sourceID, VABinauralSoundSource* source, VABinauralListener* listener);
void
init(VABinauralCluster* cluster);
ITASampleFrame*
getOutput();
......
......@@ -3,10 +3,14 @@
// VA includes
#include <VAObjectPool.h>
// Utils
#include "./VABinauralClusteringPoolFactory.h">
VABinauralClusterEngine::VABinauralClusterEngine()
{
IVAPoolObjectFactory* clusteringFactory = new VABinauralClusteringPoolFactory();
_clusteringPool = IVAObjectPool::Create(16, 2, clusteringFactory, true);
}
......@@ -17,10 +21,15 @@ VABinauralClusterEngine::~VABinauralClusterEngine()
void
VABinauralClusterEngine::update()
{
std::map< int, VABinauralClustering* >::iterator it;
/* std::map< int, VABinauralClustering* >::iterator it;
for (it = _clusterings.begin(); it != _clusterings.end(); ++it)
{
it->second->update();
}*/
for (auto const& clustering : _clusterings)
{
clustering.second->update();
}
}
......
......@@ -52,7 +52,7 @@ VABinauralClustering::getOutput()
_output->zero();
// swap out clustering state
_curState.reset(_nextState.release()); //TODO: only if next State is not null!
if (_nextState != nullptr) _curState.reset(_nextState.release());
std::map< int, VABinauralCluster*>::const_iterator it;
for (it = _curState->clusters.begin(); it != _curState->clusters.end(); ++it)
......@@ -102,9 +102,9 @@ VABinauralClustering::update()
// TODO: refinement
// update source status
for (sourceIt = _unassignedSources.begin(); sourceIt != _unassignedSources.end(); ++it)
for (auto const& assignedSources: _assignedSources)
{
_assignedSources.insert(std::pair< int, VABinauralSoundSource* >(sourceIt->first, sourceIt->second));
_assignedSources.insert(std::pair< int, VABinauralSoundSource* >(assignedSources.first, assignedSources.second));
}
_unassignedSources.clear();
......
......@@ -18,6 +18,9 @@ VABinauralClusteringState::VABinauralClusteringState(int numClusters, VABinaural
{
freeClusterIDs.push(i);
}
IVAPoolObjectFactory* clusterFactory = new VABinauralClusterPoolFactory();
_clusterPool = IVAObjectPool::Create(16, 2, clusterFactory, true);
}
......@@ -28,15 +31,17 @@ VABinauralClusteringState::~VABinauralClusteringState()
VABinauralClusteringState::VABinauralClusteringState(const VABinauralClusteringState& state) :
numClusters(state.numClusters),
listener(state.listener),
sourceClusterReference(state.sourceClusterReference)
sourceClusterReference(state.sourceClusterReference),
freeClusterIDs(state.freeClusterIDs)
{
IVAPoolObjectFactory* clusterFactory = new VABinauralClusterPoolFactory();
_clusterPool = IVAObjectPool::Create(16, 2, clusterFactory, true);
std::map< int, VABinauralCluster* >::const_iterator it;
for (it = state.clusters.begin(); it != state.clusters.end(); ++it)
{
int clusterID = it->first;
VABinauralCluster* cluster = new VABinauralCluster(*(it->second));
clusters.insert(std::pair< int, VABinauralCluster* >(clusterID, cluster));
createCluster(it->first, it->second);
}
}
......@@ -107,6 +112,17 @@ VABinauralClusteringState::createCluster(int sourceID, VABinauralSoundSource* s
return std::pair< int, VABinauralCluster* >(clusterID, cluster);
}
std::pair< int, VABinauralCluster*>
VABinauralClusteringState::createCluster(int clusterID, VABinauralCluster* cluster)
{
VABinauralCluster* _cluster = dynamic_cast< VABinauralCluster* >(_clusterPool->RequestObject());
_cluster->init(cluster);
clusters.insert(std::pair<int, VABinauralCluster* >(clusterID, _cluster));
return std::pair< int, VABinauralCluster* >(clusterID, _cluster);
}
double
VABinauralClusteringState::getMaxError()
......
......@@ -38,6 +38,9 @@ public:
std::pair< int, VABinauralCluster*>
createCluster(int sourceID, VABinauralSoundSource* source);
std::pair< int, VABinauralCluster*>
createCluster(int clusterID, VABinauralCluster* cluster);
double getMaxError();
private:
......
......@@ -150,12 +150,14 @@ VABinauralRealTimeRenderer::ProcessStream(const ITAStreamInfo* streamInfo)
for (it = _listeners.begin(); it != _listeners.end(); ++it)
{
VABinauralClustering* clustering = _clusterEngine.getClustering(it->first);
output = clustering->getOutput();
fm_copy(outputChL, (*output)[0].data(), m_uiBlocklength);
fm_copy(outputChR, (*output)[1].data(), m_uiBlocklength);
}
if (clustering){
output = clustering->getOutput();
fm_copy(outputChL, (*output)[0].data(), m_uiBlocklength);
fm_copy(outputChR, (*output)[1].data(), m_uiBlocklength);
}
}
IncrementWritePointer();
......@@ -198,14 +200,14 @@ VABinauralRealTimeRenderer::updateSources( CVASceneStateDiff* diff )
typedef std::vector< int >::const_iterator icit_t;
// Delete sources
for (icit_t it = diff->viDelSoundSourceIDs.begin(); it != diff->viDelSoundSourceIDs.end(); ++it)
for (icit_t it = diff->viDelSoundSourceIDs.begin(); it != diff->viDelSoundSourceIDs.end();)
{
const int& iID(*it++);
deleteSource(iID);
}
// Add sources
for (icit_t it = diff->viNewSoundSourceIDs.begin(); it != diff->viNewSoundSourceIDs.end(); ++it)
for (icit_t it = diff->viNewSoundSourceIDs.begin(); it != diff->viNewSoundSourceIDs.end();)
{
const int& iID(*it++);
createSource(iID, _newSceneState->GetSoundSourceState(iID));
......@@ -220,7 +222,7 @@ VABinauralRealTimeRenderer::updateSources( CVASceneStateDiff* diff )
VABinauralSoundSource* source = it->second;
CVASoundSourceState* sourceCur = (_curSceneState ? _curSceneState->GetSoundSourceState(sourceID) : nullptr);
CVASoundSourceState* sourceNew = (_newSceneState ? _curSceneState->GetSoundSourceState(sourceID) : nullptr);
CVASoundSourceState* sourceNew = (_newSceneState ? _newSceneState->GetSoundSourceState(sourceID) : nullptr);
const CVAMotionState* motionCur = (sourceCur ? sourceCur->GetMotionState() : nullptr);
const CVAMotionState* motionNew = (sourceNew ? sourceNew->GetMotionState() : nullptr);
......@@ -240,14 +242,14 @@ VABinauralRealTimeRenderer::updateListeners( CVASceneStateDiff* diff )
typedef std::vector< int >::const_iterator icit_t;
// Delete listeners
for (icit_t it = diff->viDelReceiverIDs.begin(); it != diff->viDelReceiverIDs.end(); ++it)
for (icit_t it = diff->viDelReceiverIDs.begin(); it != diff->viDelReceiverIDs.end();)
{
const int& iID(*it++);
deleteListener(iID);
}
// Add listeners
for (icit_t it = diff->viNewReceiverIDs.begin(); it != diff->viNewReceiverIDs.end(); ++it)
for (icit_t it = diff->viNewReceiverIDs.begin(); it != diff->viNewReceiverIDs.end();)
{
const int& iID(*it++);
createListener(iID, _newSceneState->GetReceiverState(iID));
......
......@@ -3,6 +3,8 @@
#include <VistaBase/VistaTimeUtils.h>
IVAInterface* va = NULL;
CVAStruct GetCoreConfig()
{
CVAStruct oConfig;
......@@ -30,20 +32,61 @@ CVAStruct GetCoreConfig()
oConfig["Reproduction:Talkthrough"] = oReproduction1;
CVAStruct oRenderer1;
oRenderer1["class"] = "BinauralFreeField";
oRenderer1["class"] = "BinauralRealTime";
oRenderer1["Reproductions"] = "MyTalkthroughHeadphones";
oConfig["Renderer:BFF_CoreTest"] = oRenderer1;
oConfig["Renderer:BRT_CoreTest"] = oRenderer1;
CVAStruct oRenderer2;
oRenderer2["class"] = "PrototypeGenericPath";
oRenderer2["numchannels"] = 2;
oRenderer2["Reproductions"] = "MyTalkthroughHeadphones";
oConfig["Renderer:PTGP_CoreTest"] = oRenderer2;
return oConfig;
}
IVAInterface* va = NULL;
class EventBasedGenericRenderingController : public IVAEventHandler
{
public:
inline void HandleVAEvent(const CVAEvent* pEvent)
{
if (pEvent->iEventType & CVAEvent::SOUND_RECEIVER_CHANGED_POSE)
{
std::cout << "[ListenerUpdate] " << pEvent->ToString();
// Determine new file path for filter update
std::string sNewFilePath;
VAVec3 vNewListenerView = pEvent->vView;
VAVec3 vNewListenerUp = pEvent->vUp;
if (true) // Some geometric expression
sNewFilePath = "$(VADataDir)/rooms/shoebox_room_brir_azi020_ele000.wav";
CVAStruct oArgs, oReturn;
oArgs["COMMAND"] = "UPDATE";
oArgs["TYPE"] = "FILE"; // or DATA that sends ITASampleFrame from this controller context
oArgs["FilePath"] = sNewFilePath;
oArgs["ListenerID"] = pEvent->iObjectID;
oArgs["SourceID"] = 1;
try
{
oReturn = va->CallModule("GenericPath:MyGenericRenderer", oArgs);
}
catch (CVAException& e)
{
std::cerr << e << std::endl;
}
}
}
};
EventBasedGenericRenderingController rendering_controller;
void SetupScene()
{
int iListenerID = va->CreateSoundReceiver("MyListener");
va->SetSoundReceiverAuralizationMode(iListenerID, IVAInterface::VA_AURAMODE_ALL);
va->SetSoundReceiverOrientationVU(iListenerID, VAVec3(0.7172f, 0.0f, -0.7172f), VAVec3(0, 1, 0));
//va->SetSoundReceiverDirectivity(iListenerID, 1);
va->SetActiveSoundReceiver(iListenerID);
int iSoundSource = va->CreateSoundSource("MySoundSource");
va->SetSoundSourcePosition(iSoundSource, VAVec3(-2.0f, 0, 0));
}
int main(int, char**)
{
......@@ -51,22 +94,28 @@ int main(int, char**)
{
va = VACore::CreateCoreInstance(GetCoreConfig());
va->AttachEventHandler(&rendering_controller);
va->Initialize();
VistaTimeUtils::Sleep(60000);
va->AddSearchPath("../data");
va->Finalize();
SetupScene();
//va->Finalize();
}
catch (CVAException& e)
{
std::cerr << "Error: " << e << std::endl;
int iErrorCode = e.GetErrorCode();
delete va;
VistaTimeUtils::Sleep(60000);
return iErrorCode;
}
delete va;
VistaTimeUtils::Sleep(10000);
return 0;
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment