Commit a9e77c3b authored by Daniel Filbert's avatar Daniel Filbert

fixing VBAP

parent 91b43829
......@@ -45,8 +45,9 @@ CVAVBAPFreeFieldAudioRenderer::CVAVBAPFreeFieldAudioRenderer( const CVAAudioRend
{
CVAConfigInterpreter conf( *oParams.pConfig );
if( !conf.OptInteger( "SetupDimension", m_iSetupDimension, 2 ) )
VA_WARN( "VBAPFreefieldRenderer", "No setup dimension given, using 2D plane (ignoring horizontal Y component)" );
//if( !conf.OptInteger( "SetupDimension", m_iSetupDimension, 2 ) )
//VA_WARN( "VBAPFreefieldRenderer", "No setup dimension given, using 2D plane (ignoring horizontal Y component)" );
m_iSetupDimension = 3;
// Hardware output setup
std::string sOutput;
......@@ -56,15 +57,19 @@ CVAVBAPFreeFieldAudioRenderer::CVAVBAPFreeFieldAudioRenderer( const CVAAudioRend
if( m_pOutput == nullptr )
VA_EXCEPT2( INVALID_PARAMETER, "Unrecognized output '" + sOutput + "' in VBAP Freefield Renderer." );
m_vecCaveCenterPos.SetValues( 0.0f, 0.0f, 0.0f );
m_vecCaveCenterPos.Set( 0.0f, 1.27f, 0.0f );
m_vecCaveCenterOrientYPR.Set(0.0f, 0.0f, 0.0f);
/*
m_vecCaveCenterOrientYPR.SetToZeroVector();
*/
// Fill loudspeaker vector
for( size_t i = 0; i < m_pOutput->vpDevices.size(); i++ )
{
const CVAHardwareDevice* pDevice( m_pOutput->vpDevices[ i ] );
CLoudspeaker oLS;
oLS.pos.SetValues( pDevice->vPos.x, pDevice->vPos.y, pDevice->vPos.z );
// oLS.pos.SetValues( pDevice->vPos.x, pDevice->vPos.y, pDevice->vPos.z );
oLS.pos.Set(pDevice->vPos.x, pDevice->vPos.y, pDevice->vPos.z);
oLS.iChannel = int( i );
oLS.iIdentifier = int( i );
oLS.sIdentifier = pDevice->sIdentifier;
......@@ -72,7 +77,7 @@ CVAVBAPFreeFieldAudioRenderer::CVAVBAPFreeFieldAudioRenderer( const CVAAudioRend
}
// Handling der Sektionen
if( m_iSetupDimension == DIM_1D )
/*if( m_iSetupDimension == DIM_1D )
{
VA_EXCEPT0( NOT_IMPLEMENTED );
}
......@@ -135,14 +140,14 @@ CVAVBAPFreeFieldAudioRenderer::CVAVBAPFreeFieldAudioRenderer( const CVAAudioRend
newSection.iIdentifier = int(j);
// Sektion der Sektionenliste hinzufgen
m_voSectionList.push_back(newSection);
*/
}
}
else
{
VA_EXCEPT2( INVALID_PARAMETER, "Unrecognizes dimension setup for VBAP renderer." );
}
*/
int iNumChannels = int( m_voLoudspeaker.size() );
double dSampleRate = oParams.pCore->GetCoreConfig()->oAudioDriverConfig.dSampleRate;
int iBlockLength = oParams.pCore->GetCoreConfig()->oAudioDriverConfig.iBuffersize;
......@@ -203,7 +208,9 @@ void CVAVBAPFreeFieldAudioRenderer::UpdateScene( CVASceneState* pNewSceneState )
m_vUserPosVirtualScene = m_pNewSceneState->GetReceiverState( iListenerID )->GetMotionState()->GetPosition();
VAVec3 p, v, u;
m_oParams.pCore->GetSoundReceiverRealWorldPositionOrientationVU( iListenerID, p, v, u );
ConvertVU2YPR_RAD( VAVec3( vx, vy, vz ), VAVec3( ux, uy, uz ), m_oUserYPRRealWorldRAD );
// convertVU2YPR( VAVec3( vx, vy, vz ), VAVec3( ux, uy, uz ), m_oUserYPRRealWorldRAD );
m_vUserPosRealWorld.Set( float( p.x ), float( p.y ), float( p.z ) );
// Define reproduction system in virtual scene
......@@ -325,18 +332,26 @@ void CVAVBAPFreeFieldAudioRenderer::HandleProcessStream( ITADatasourceRealizatio
CVASoundSourceDesc* pSourceData = m_oParams.pCore->GetSceneManager()->GetSoundSourceDesc( iID );
const ITASampleBuffer* psbInput = pSourceData->pSignalSourceInputBuf;
std::vector< int > viListenerIDs;
m_pCurSceneState->GetListenerIDs(&viListenerIDs);
const CVAMotionState* pMotionState = pState->GetMotionState();
if( pMotionState != nullptr )
if (pMotionState != nullptr && viListenerIDs.size() > 0)
{
//Quellposition relativ zum Cavemittelpunkt berechnen
VAVec3 vSoundSource = GetSourcePosition( pMotionState );
int iListenerID;
std::vector< int > viListenerIDs;
m_pCurSceneState->GetListenerIDs( &viListenerIDs );
// Use first listener as the user of VBAP system
iListenerID = viListenerIDs[ 0 ];
int iListenerID = viListenerIDs[ 0 ];
// @todo: use active listener from VA core
//int iListenerID = m_oParams.pCore->GetActiveSoundReceiver();
// @todo Create loudspeaker gains based on virtual sound receiver position (and not coordinate system origin)
CVAReceiverState* pReceiverState = m_pCurSceneState->GetReceiverState(iID);
// @todo ...
VAVec3 vSoundReceiverPos;
// Quelle und Hrer an der selben Position ... auslassen
if( vSoundSource.Length() == 0.0f )
......@@ -497,8 +512,10 @@ bool CVAVBAPFreeFieldAudioRenderer::IsSourceDirectionWithinSection( const VAVec3
return false;
}
bool CVAVBAPFreeFieldAudioRenderer::CalculateLoudspeakerGains3D( const VAVec3& vSoundSource, std::vector< double >& vdLoudspeakerGains ) const
{
/*
const CSection* pActiveSection = NULL;
for( size_t i = 0; i < m_voSectionList.size(); i++ )
{
......@@ -511,11 +528,12 @@ bool CVAVBAPFreeFieldAudioRenderer::CalculateLoudspeakerGains3D( const VAVec3& v
}
}
if( pActiveSection == nullptr )
{
return false;
}
*/
// --= calculate gains =--
......@@ -524,11 +542,63 @@ bool CVAVBAPFreeFieldAudioRenderer::CalculateLoudspeakerGains3D( const VAVec3& v
const RG_Vector &posLS1 = poly.vertices[0];
const RG_Vector &posLS2 = poly.vertices[1];
const RG_Vector &posLS3 = poly.vertices[2];
*/
// Create list of all loudspeakers which from all positions are given in relation from virtual source position
std::vector< CLoudspeaker > voLoudSpeakerFromSoundSource;
for (size_t i = 0; i < m_voLoudspeaker.size(); i++)
{
// Calculate position of loudspeaker from virtual sound source
double positionValues[3];
// m_voLoudspeaker[i].pos.GetValues(positionValues);
positionValues[0] = m_voLoudspeaker[i].pos.x;
positionValues[1] = m_voLoudspeaker[i].pos.y;
positionValues[2] = m_voLoudspeaker[i].pos.z;
VAVec3 vLoudSpeakerPos(positionValues[0], positionValues[1], positionValues[2]);
VAVec3 vPosLoudSpeakerFromSoundSource = vLoudSpeakerPos - vSoundSource - m_vecCaveCenterPos;
VAVec3 NewPosition( vPosLoudSpeakerFromSoundSource.x, vPosLoudSpeakerFromSoundSource.y, vPosLoudSpeakerFromSoundSource.z );
// Insert in new Loudspeaker list with new position in relation to virtual sound source position
voLoudSpeakerFromSoundSource.push_back(m_voLoudspeaker[i]);
voLoudSpeakerFromSoundSource[i].pos = NewPosition;
}
std::sort(voLoudSpeakerFromSoundSource.begin(), voLoudSpeakerFromSoundSource.end(), [](CLoudspeaker first, CLoudspeaker second) { return first.pos.Length() < second.pos.Length(); } );
double *pMatrix;
double *pInverse;
double Matrix[9];
double dInverseMatrix[9];
/*
double posLS1[3], posLS2[3], posLS3[3];
m_voLoudspeaker[oLoudSpeakerFromSoundSource[0].iIdentifier].pos.GetValues(posLS1);
m_voLoudspeaker[oLoudSpeakerFromSoundSource[1].iIdentifier].pos.GetValues(posLS2);
m_voLoudspeaker[oLoudSpeakerFromSoundSource[2].iIdentifier].pos.GetValues(posLS3);
VistaVector3D pos1 = m_voLoudspeaker[voLoudSpeakerFromSoundSource[0].iIdentifier].pos.GetNormalized();
VistaVector3D pos2 = m_voLoudspeaker[voLoudSpeakerFromSoundSource[1].iIdentifier].pos.GetNormalized();
VistaVector3D pos3 = m_voLoudspeaker[voLoudSpeakerFromSoundSource[2].iIdentifier].pos.GetNormalized();
*/
VAVec3 posLS1 = m_voLoudspeaker[voLoudSpeakerFromSoundSource[0].iIdentifier].pos - m_vecCaveCenterPos;
VAVec3 posLS2 = m_voLoudspeaker[voLoudSpeakerFromSoundSource[1].iIdentifier].pos - m_vecCaveCenterPos;
VAVec3 posLS3 = m_voLoudspeaker[voLoudSpeakerFromSoundSource[2].iIdentifier].pos - m_vecCaveCenterPos;
posLS1.Norm();
posLS2.Norm();
posLS3.Norm();
/*
pos1.GetValues(posLS1);
pos2.GetValues(posLS2);
pos3.GetValues(posLS3);
oLoudSpeakerFromSoundSource[0].pos.GetValues(posLS1);
oLoudSpeakerFromSoundSource[1].pos.GetValues(posLS2);
oLoudSpeakerFromSoundSource[2].pos.GetValues(posLS3);
*/
Matrix[0] = posLS1.x;
Matrix[1] = posLS1.y;
......@@ -542,6 +612,20 @@ bool CVAVBAPFreeFieldAudioRenderer::CalculateLoudspeakerGains3D( const VAVec3& v
Matrix[7] = posLS3.y;
Matrix[8] = posLS3.z;
/*
Matrix[0] = posLS1[0];
Matrix[1] = posLS1[1];
Matrix[2] = posLS1[2];
Matrix[3] = posLS2[0];
Matrix[4] = posLS2[1];
Matrix[5] = posLS2[2];
Matrix[6] = posLS3[0];
Matrix[7] = posLS3[1];
Matrix[8] = posLS3[2];
*/
dInverseMatrix[0] = 0;
dInverseMatrix[1] = 0;
dInverseMatrix[2] = 0;
......@@ -560,13 +644,24 @@ bool CVAVBAPFreeFieldAudioRenderer::CalculateLoudspeakerGains3D( const VAVec3& v
// Get loudspeaker identifier
const int &LSID1 = pActiveSection->iLSIdentifier[0];
/* const int &LSID1 = pActiveSection->iLSIdentifier[0];
const int &LSID2 = pActiveSection->iLSIdentifier[1];
const int &LSID3 = pActiveSection->iLSIdentifier[2];
vdLoudspeakerGains[LSID1] = vSoundSource.x*dInverseMatrix[0]+vSoundSource.y*dInverseMatrix[3]+vSoundSource.z*dInverseMatrix[6];
vdLoudspeakerGains[LSID2] = vSoundSource.x*dInverseMatrix[1]+vSoundSource.y*dInverseMatrix[4]+vSoundSource.z*dInverseMatrix[7];
vdLoudspeakerGains[LSID3] = vSoundSource.x*dInverseMatrix[2]+vSoundSource.y*dInverseMatrix[5]+vSoundSource.z*dInverseMatrix[8];
*/
const int &LSID1 = voLoudSpeakerFromSoundSource[0].iIdentifier;
const int &LSID2 = voLoudSpeakerFromSoundSource[1].iIdentifier;
const int &LSID3 = voLoudSpeakerFromSoundSource[2].iIdentifier;
vdLoudspeakerGains[LSID1] = vSoundSource.x * dInverseMatrix[0] + vSoundSource.y * dInverseMatrix[3] + vSoundSource.z * dInverseMatrix[6];
vdLoudspeakerGains[LSID2] = vSoundSource.x * dInverseMatrix[1] + vSoundSource.y * dInverseMatrix[4] + vSoundSource.z * dInverseMatrix[7];
vdLoudspeakerGains[LSID3] = vSoundSource.x * dInverseMatrix[2] + vSoundSource.y * dInverseMatrix[5] + vSoundSource.z * dInverseMatrix[8];
/*
VAVec3 vSoundSourcePosFromListener = vSoundSource - m_vecCaveCenterPos;
vdLoudspeakerGains[LSID1] = vSoundSourcePosFromListener.x * dInverseMatrix[0] + vSoundSourcePosFromListener.y * dInverseMatrix[3] + vSoundSourcePosFromListener.z * dInverseMatrix[6];
vdLoudspeakerGains[LSID2] = vSoundSourcePosFromListener.x * dInverseMatrix[1] + vSoundSourcePosFromListener.y * dInverseMatrix[4] + vSoundSourcePosFromListener.z * dInverseMatrix[7];
vdLoudspeakerGains[LSID3] = vSoundSourcePosFromListener.x * dInverseMatrix[2] + vSoundSourcePosFromListener.y * dInverseMatrix[5] + vSoundSourcePosFromListener.z * dInverseMatrix[8];
*/
double dCorrection = sqrt(vdLoudspeakerGains[LSID1]*vdLoudspeakerGains[LSID1]+vdLoudspeakerGains[LSID2]*vdLoudspeakerGains[LSID2]+vdLoudspeakerGains[LSID3]*vdLoudspeakerGains[LSID3]);
......@@ -574,7 +669,6 @@ bool CVAVBAPFreeFieldAudioRenderer::CalculateLoudspeakerGains3D( const VAVec3& v
vdLoudspeakerGains[LSID2]/=dCorrection;
vdLoudspeakerGains[LSID3]/=dCorrection;
*/
return true;
}
......@@ -596,8 +690,9 @@ bool CVAVBAPFreeFieldAudioRenderer::CalculateLoudspeakerGains2D( const VAVec3& v
for( size_t j = 0; j < m_voLoudspeaker.size(); j++ ) // Schleife ber LS
{
// Entfernung berechnen
VistaVector3D vDifference = m_voLoudspeaker[ j ].pos - VistaVector3D( vSoundSource.comp );
double dDistance = vDifference.GetLength();
// VistaVector3D vDifference = m_voLoudspeaker[ j ].pos - VistaVector3D( vSoundSource.comp );
VAVec3 vDifference = m_voLoudspeaker[j].pos - vSoundSource;
double dDistance = vDifference.Length();
if( dDistance < *max_element( vdMinValues.begin(), vdMinValues.end() ) )
{
......@@ -611,21 +706,29 @@ bool CVAVBAPFreeFieldAudioRenderer::CalculateLoudspeakerGains2D( const VAVec3& v
int iLS1 = viMinIDs[ 0 ];
int iLS2 = viMinIDs[ 1 ];
const VistaVector3D &posLS1 = m_voLoudspeaker[ iLS1 ].pos;
const VistaVector3D &posLS2 = m_voLoudspeaker[ iLS2 ].pos;
/*
const VistaVector3D &posLS1 = m_voLoudspeaker[iLS1].pos;
const VistaVector3D &posLS2 = m_voLoudspeaker[iLS2].pos;
*/
const VAVec3 &posLS1 = m_voLoudspeaker[ iLS1 ].pos;
const VAVec3 &posLS2 = m_voLoudspeaker[ iLS2 ].pos;
if( ( viMinIDs[ 0 ] == -1 ) || ( viMinIDs[ 1 ] == -1 ) )
return false;
// Berechnung der Gains ber die Inverse
/*
double dDetA = ( -posLS1[ 2 ] * posLS2[ 0 ] ) - ( -posLS2[ 2 ] * posLS1[ 0 ] );
*/
double dDetA = (-posLS1.z * posLS2.x) - (-posLS2.z * posLS1.x);
if( dDetA == 0.0f )
return false;
// Berechnung der Gains nach Pulkki
vdLoudspeakerGains[ viMinIDs[ 0 ] ] = ( 1 / dDetA*( ( -vSoundSource.z*posLS2[ 0 ] ) + ( vSoundSource.x*posLS2[ 2 ] ) ) );
vdLoudspeakerGains[ viMinIDs[ 1 ] ] = ( 1 / dDetA*( ( -vSoundSource.z*-posLS1[ 0 ] ) + ( vSoundSource.x*-posLS1[ 2 ] ) ) );
vdLoudspeakerGains[ viMinIDs[ 0 ] ] = ( 1 / dDetA*( ( -vSoundSource.z*posLS2.x ) + ( vSoundSource.x*posLS2.z ) ) );
vdLoudspeakerGains[ viMinIDs[ 1 ] ] = ( 1 / dDetA*( ( -vSoundSource.z*-posLS1.x ) + ( vSoundSource.x*-posLS1.z ) ) );
// Normalisierung nach Pulkki
double dCorrection = sqrt( vdLoudspeakerGains[ viMinIDs[ 0 ] ] * vdLoudspeakerGains[ viMinIDs[ 0 ] ] + vdLoudspeakerGains[ viMinIDs[ 1 ] ] * vdLoudspeakerGains[ viMinIDs[ 1 ] ] );
......@@ -638,22 +741,22 @@ bool CVAVBAPFreeFieldAudioRenderer::CalculateLoudspeakerGains2D( const VAVec3& v
VAVec3 CVAVBAPFreeFieldAudioRenderer::GetSourcePosition( const CVAMotionState* pMotionState )
{
VAVec3 vSoundSource;
vSoundSource.x = ( pMotionState->GetPosition().x - m_vReproSystemVirtualPosition.x );
vSoundSource.y = ( pMotionState->GetPosition().y - m_vReproSystemVirtualPosition.y );
vSoundSource.z = ( pMotionState->GetPosition().z - m_vReproSystemVirtualPosition.z );
VAVec3 vRotYaw( m_vRotYaw[ 0 ], m_vRotYaw[ 1 ], m_vRotYaw[ 2 ] );
vSoundSource.x = (pMotionState->GetPosition().x - m_vReproSystemVirtualPosition.x - m_vecCaveCenterPos.x);
vSoundSource.y = (pMotionState->GetPosition().y - m_vReproSystemVirtualPosition.y - m_vecCaveCenterPos.y);
vSoundSource.z = (pMotionState->GetPosition().z - m_vReproSystemVirtualPosition.z - m_vecCaveCenterPos.z);
/* VAVec3 vRotYaw( m_vRotYaw[ 0 ], m_vRotYaw[ 1 ], m_vRotYaw[ 2 ] );
VAVec3 vRotPitch( m_vRotPitch[ 0 ], m_vRotPitch[ 1 ], m_vRotPitch[ 2 ] );
VAVec3 vRotRoll( m_vRotRoll[ 0 ], m_vRotRoll[ 1 ], m_vRotRoll[ 2 ] );
vSoundSource.rotatedAround( vRotYaw, float( m_oUserYPRRealWorldRAD.yaw ) );
vSoundSource.rotatedAround( vRotYaw, float( m_oUserYPRRealWorldRAD.yaw ) ); // rotated around msste in VAVec3 implementiert werden
vSoundSource.rotatedAround( vRotPitch, float( m_oUserYPRRealWorldRAD.pitch ) );
vSoundSource.rotatedAround( vRotRoll, float( m_oUserYPRRealWorldRAD.roll ) );
vSoundSource.rotatedAround( vRotYaw, float( -m_oUserYPRVirtualScene.yaw ) );
vSoundSource.rotatedAround( vRotPitch, float( -m_oUserYPRVirtualScene.pitch ) );
vSoundSource.rotatedAround( vRotRoll, float( -m_oUserYPRVirtualScene.roll ) );
*/
return VAVec3( vSoundSource.x, vSoundSource.y, vSoundSource.z );
}
......
......@@ -88,6 +88,7 @@ public:
ITADatasource* GetOutputDatasource();
private:
const CVAAudioRendererInitParams m_oParams; //!< Create a const copy of the init params
......@@ -95,9 +96,9 @@ private:
VAVec3 m_vUserPosVirtualScene; //!< Position des Hoerers in der virtuellen Umgebung
VAVec3 m_vUserPosRealWorld; //!< Position des Hrers in der CAVE (oder im Reproduktionssystem)
VAVec3 m_vReproSystemVirtualPosition; //!< Position der CAVE (oder des Reproduktionssystems) in der virtuellen Welt. Center position of loudspeaker array.
//VAOrientYPR m_oUserYPRRealWorldRAD; //!< Orientierung des Hoerers in der Cave (im Reproduktionssystem), Gieren, Nicken, Rollen
//VAOrientYPR m_oUserYPRRealWorldRAD; //!< Orientierung des Hoerers in der Cave (im Reproduktionssystem), Gieren, Nicken, Rollen
//VAOrientYPR m_oUserYPRVirtualScene; //!< Orientierung des Hoerers in der virtuellen Umgebung, Gieren, Nicken, Rollen
//VistaVector3D m_vRotYaw, m_vRotPitch, m_vRotRoll; //!< Hilfsvektoren zum rotieren, um diese Achsen wird rotiert
VAVec3 m_vRotYaw, m_vRotPitch, m_vRotRoll; //!< Hilfsvektoren zum rotieren, um diese Achsen wird rotiert
enum DIMENSIONS
{
......@@ -113,7 +114,7 @@ private:
std::string sIdentifier;
int iIdentifier;
int iChannel;
VistaVector3D pos;
VAVec3 pos;
};
// Sections
......@@ -148,8 +149,8 @@ private:
bool m_bResetTrigger; //!< Bool die eins wird falls ein Reset stattfindet
int m_iCurGlobalAuralizationMode; //!< Der aktuelle Auralisierungsmodues, mit dem der Renderer arbeitet
VistaVector3D m_vecCaveCenterPos; //!< Mittelpunkt der CAVE Umgebung relativ zu Szene
VistaVector3D m_vecCaveCenterOrientYPR; //!< Mittelpunkt der CAVE Umgebung relativ zu Szene
VAVec3 m_vecCaveCenterPos; //!< Mittelpunkt der CAVE Umgebung relativ zu Szene
VAVec3 m_vecCaveCenterOrientYPR; //!< Mittelpunkt der CAVE Umgebung relativ zu Szene
int m_iSetupDimension; //!< Dimension of setup, see \DIMENSIONS
......@@ -232,6 +233,7 @@ private:
void SyncInternalData();
};
#endif // VACORE_WITH_RENDERER_VBAP_FREE_FIELD
......
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