Commit 190890c1 authored by Michael Kohnen's avatar Michael Kohnen

wip

parent 72ad73b6
......@@ -79,7 +79,7 @@ CVAAmbisonicsBinauralMixdownReproduction::CVAAmbisonicsBinauralMixdownReproducti
conf.OptInteger("HRIRFilterLength", m_iHRIRFilterLength, 512);
conf.OptInteger("TrackedListenerID", m_iListenerID, 1);
conf.OptString("RotationMode", m_sRotationMode, "BFormat"); //Set calculation of rotations to "ViewUp" or "Quaternion" or "BFormat"
std::string sDefaultHRIRPathRAW;
conf.OptString("DefaultHRIR", sDefaultHRIRPathRAW);
......@@ -92,7 +92,7 @@ CVAAmbisonicsBinauralMixdownReproduction::CVAAmbisonicsBinauralMixdownReproducti
if (sReproCenterPos == "AUTO")
{
VA_WARN(this, "Ambisonics reproduction center set to 0 0 0");
m_v3ReproductionCenterPos.Set(0,0,0);
m_v3ReproductionCenterPos.Set(0, 0, 0);
}
else
{
......@@ -100,7 +100,7 @@ CVAAmbisonicsBinauralMixdownReproduction::CVAAmbisonicsBinauralMixdownReproducti
assert(vsPosComponents.size() == 3);
m_v3ReproductionCenterPos.Set(StringToFloat(vsPosComponents[0]), StringToFloat(vsPosComponents[1]), StringToFloat(vsPosComponents[2]));
}
if (!sDefaultHRIRPathRAW.empty())
{
......@@ -151,10 +151,10 @@ CVAAmbisonicsBinauralMixdownReproduction::CVAAmbisonicsBinauralMixdownReproducti
m_pDecoderMatrixPatchBay->AddOutput(GetNumVirtualLoudspeaker());
m_pdsStreamFilter = new CMixdownStreamFilter(GetNumVirtualLoudspeaker(), dSampleRate, iBlockLength, m_iHRIRFilterLength);
m_pdsStreamFilter->pdsInput = m_pDecoderMatrixPatchBay->GetOutputDatasource(0);
Eigen::MatrixXd matY(m_pVirtualOutput->vpDevices.size(), (m_iAmbisonicsTruncationOrder + 1)*(m_iAmbisonicsTruncationOrder + 1));
// TODO Center Position aus Config?
VAVec3 va3Origin(0, 0, 0);
......@@ -166,18 +166,18 @@ CVAAmbisonicsBinauralMixdownReproduction::CVAAmbisonicsBinauralMixdownReproducti
VistaVector3D vvView = VistaVector3D(va3View.x, va3View.y, va3View.z);
VistaVector3D vvUp = VistaVector3D(va3Up.x, va3Up.y, va3Up.z);
std::vector<double> vdYParts;
double dAzimuth, dElevation;
// Gather matrix with loudspeaker position as (N_LS x 3);
for (int k = 0; k < m_pVirtualOutput->vpDevices.size(); k++)
{
const CVAHardwareDevice* pDevice = m_pVirtualOutput->vpDevices[k];
//There is no option for BFormat rotation in this application
if (m_sRotationMode == "Quaternion" || m_sRotationMode == "BFormat") {
if (m_sRotationMode == "Quaternion" || m_sRotationMode == "BFormat") {
//Virtual Speaker position: Cast VAVec to VistaVector to build a VistaQuaternion for the rotation
VistaVector3D vvDevicePos = VistaVector3D(pDevice->vPos.x, pDevice->vPos.y, pDevice->vPos.z);
......@@ -212,8 +212,8 @@ CVAAmbisonicsBinauralMixdownReproduction::CVAAmbisonicsBinauralMixdownReproducti
dElevation = pitch; //pitch --> Elevation
*/
//This function is enough to Rotate around STANDARD va3ORIGIN;va3VIEW;va3UP
VistaQuaternion qRot(VistaVector3D(0, 0, -1), vvDevicePos);
......@@ -253,8 +253,8 @@ CVAAmbisonicsBinauralMixdownReproduction::CVAAmbisonicsBinauralMixdownReproducti
// Matrix
for (int i = 0; i < GetNumInputChannels(); i++)
{
int iCurrentOrder = (int) floor(sqrt(i));
for( int j=0; j < GetNumVirtualLoudspeaker(); j++ )
int iCurrentOrder = (int)floor(sqrt(i));
for (int j = 0; j < GetNumVirtualLoudspeaker(); j++)
{
double dGain = m_matYinv(i, j)*m_vdRemaxWeights[iCurrentOrder];
m_pDecoderMatrixPatchBay->ConnectChannels(0, i, 0, j, dGain);
......@@ -388,20 +388,20 @@ void calcRotationMatrix(Eigen::MatrixXd* m_orderMatrices, const int order, doubl
auto ca = std::cos(dYaw);
auto cb = std::cos(dPitch);
auto cy = std::cos(dRoll);
auto sa = std::sin(dYaw);
auto sb = std::sin(dPitch);
auto sy = std::sin(dRoll);
auto sy = std::sin(dRoll);
Eigen::Matrix3d rotMat;
//ToDo: Choose a rotation Model concerning our axis rotation
if (true) // roll -> pitch -> yaw (extrinsic rotations)
{
rotMat(0, 0) = ca * cb;
rotMat(1, 0) = sa * cb;
rotMat(2, 0) = -sb;
rotMat(2, 0) = -sb;
rotMat(0, 1) = ca * sb * sy - sa * cy;
rotMat(1, 1) = sa * sb * sy + ca * cy;
......@@ -416,20 +416,20 @@ void calcRotationMatrix(Eigen::MatrixXd* m_orderMatrices, const int order, doubl
rotMat(0, 0) = ca * cb;
rotMat(1, 0) = sa * cy + ca * sb * sy;
rotMat(2, 0) = sa * sy - ca * sb * cy;
rotMat(0, 1) = -sa * cb;
rotMat(1, 1) = ca * cy - sa * sb * sy;
rotMat(2, 1) = ca * sy + sa * sb * cy;
rotMat(2, 1) = ca * sy + sa * sb * cy;
rotMat(0, 2) = sb;
rotMat(1, 2) = -cb * sy;
rotMat(2, 2) = cb * cy;
}
}
//Eigen::MatrixXd orderMatrices[5];
//Eigen::MatrixXd Rl = orderMatrices[1];
Eigen::MatrixXd zero(1, 1);
zero(0, 0) = 1;
m_orderMatrices[0] = zero;
......@@ -450,33 +450,33 @@ void calcRotationMatrix(Eigen::MatrixXd* m_orderMatrices, const int order, doubl
for (int l = 2; l <= order; l++){
for (int l = 2; l <= order; l++) {
auto Rone = m_orderMatrices[1];
auto Rlm1 = m_orderMatrices[l - 1];
Eigen::MatrixXd Rl(l * 2 + 1, l * 2 + 1);
for (int m = -l; m <= l; m++){
for (int m = -l; m <= l; m++) {
for (int n = -l; n <= l; n++){
for (int n = -l; n <= l; n++) {
const int d = (m == 0) ? 1 : 0;
double denom;
if (abs(n) == l)
denom = (2 * l) * (2 * l - 1);
else
denom = l * l - n * n;
denom = l * l - n * n;
double u = sqrt((l * l - m * m) / denom);
double v = sqrt((1.0 + d) * (l + abs(m) - 1.0) * (l + abs(m)) / denom) * (1.0 - 2.0 * d) * 0.5;
double w = sqrt((l - abs(m) - 1.0) * (l - abs(m)) / denom) * (1.0 - d) * (-0.5);
if (u != 0.0)
u *= U(l, m, n, Rone, Rlm1);
if (v != 0.0)
v *= V(l, m, n, Rone, Rlm1);
if (w != 0.0)
w *= W(l, m, n, Rone, Rlm1);
w *= W(l, m, n, Rone, Rlm1);
Rl(m + l, n + l) = u + v + w;
}
}
......@@ -548,7 +548,7 @@ void CVAAmbisonicsBinauralMixdownReproduction::UpdateScene(CVASceneState* pNewSt
else
return;
// Get the realworld position as position, view and up vector
//VAVec3 vListenerPos, vListenerView, vListenerUp;
//m_oParams.pCore->GetSoundReceiverRealWorldPositionOrientationVU(m_iListenerID, vListenerPos, vListenerView, vListenerUp);
......@@ -567,7 +567,7 @@ void CVAAmbisonicsBinauralMixdownReproduction::UpdateScene(CVASceneState* pNewSt
ConvertQuaternionToViewUp(qOrientEstimated, vListenerView, vListenerUp);
ConvertQuaternionToViewUp(qOrientRealWorld, vListenerView2, vListenerUp2);
vListenerPos = m_v3ReproductionCenterPos;
//keep the Listener Position fixed, since we want to keep the virtual loudspeaker array fixed around this position
......@@ -583,9 +583,9 @@ void CVAAmbisonicsBinauralMixdownReproduction::UpdateScene(CVASceneState* pNewSt
VistaVector3D vvListenerUp = VistaVector3D(vListenerUp.x, vListenerUp.y, vListenerUp.z);
VistaVector3D vvListenerPos = VistaVector3D(vListenerPos.x, vListenerPos.y, vListenerPos.z);
if (m_sRotationMode == "BFormat" && m_bBFormatIsInit) {
//Calculate Rotation from Listener to Origin
//rotate ListenerUp to point Up in standard Up-Vector(0,1,0)
......@@ -600,8 +600,8 @@ void CVAAmbisonicsBinauralMixdownReproduction::UpdateScene(CVASceneState* pNewSt
//Extract Angles from Quaternion in RAD
double dRoll, dPitch, dYaw;
calculateYPRAnglesFromQuaternion(qRotatedViewToOrigin, dRoll, dPitch, dYaw);
calcRotationMatrix(m_orderMatrices, m_iAmbisonicsTruncationOrder, dYaw, dPitch, dRoll);
//calcRotationMatrix(m_orderMatrices, m_iAmbisonicsTruncationOrder, 0, 0, ITAConstants::PI_D);
......@@ -621,7 +621,7 @@ void CVAAmbisonicsBinauralMixdownReproduction::UpdateScene(CVASceneState* pNewSt
matrix1[i][j] = R1(i, j);
}
}
const int order2 = 5;
double matrix2[order2][order2];
for (int i = 0; i < order2; i++) {
......@@ -648,7 +648,7 @@ void CVAAmbisonicsBinauralMixdownReproduction::UpdateScene(CVASceneState* pNewSt
*/
Eigen::MatrixXd matRotation = buildRotationMatrix(m_orderMatrices, m_iAmbisonicsTruncationOrder);
//To be deleted: only for testing purposes. Better display of 25x25 matrix (possible to see ind. values)
/*double matrix[25][25];
for (int i = 0; i < 25; i++) {
......@@ -674,39 +674,34 @@ void CVAAmbisonicsBinauralMixdownReproduction::UpdateScene(CVASceneState* pNewSt
}
*/
/*Eigen::DiagonalMatrix diag(5);
Eigen::MatrixXd matDiagRemax(GetNumInputChannels,GetNumInputChannels);
//matDiagRemax.diagonal()
Eigen::MatrixXd matDecoder = m_matYinv.transpose()*
*/
int m, n;
int iCurrentOrder;
double dGain=0;
//gains
for (int i = 0; i < GetNumInputChannels(); i++){
iCurrentOrder = floor(sqrt(i));
double dGain = 0;
for (int i = 0; i < GetNumInputChannels(); i++) {
iCurrentOrder = floor(sqrt(i));
for (int j = 0; j < GetNumVirtualLoudspeaker(); j++)
{
for (int k = 0; k < 25; k++){
{
for (int k = 0; k < 25; k++) {
SHLinear2DegreeOrder(k, m, n);
dGain += m_matYinv(k, j) * matRotation(i,k) * m_vdRemaxWeights[n];
//dGain = m_matYinv(i, j) * m_vdRemaxWeights[iCurrentOrder];
dGain += m_matYinv(k, j) * matRotation(i, k) * m_vdRemaxWeights[n];
}
m_pDecoderMatrixPatchBay->ConnectChannels(0, i, 0, j, dGain);
dGain = 0;
}
}
}
/*for (int i = 0; i < GetNumInputChannels(); i++)
{
int iCurrentOrder = (int) floor(sqrt(i));
for( int j=0; j < GetNumVirtualLoudspeaker(); j++ )
{
double dGain = m_matYinv(i, j)*m_vdRemaxWeights[iCurrentOrder];
m_pDecoderMatrixPatchBay->ConnectChannels(0, i, 0, j, dGain);
}
}*/
else if ((m_sRotationMode == "ViewUp") || (m_sRotationMode == "Quaternion") || !m_bBFormatIsInit) {
double dAzimuth, dElevation;
//iterate over all virtual loudspeakers and add rotation Quaternion to adjust position with regards to the head movement
for (int i = 0; i < GetNumVirtualLoudspeaker(); i++)
{
......@@ -793,14 +788,14 @@ void CVAAmbisonicsBinauralMixdownReproduction::UpdateScene(CVASceneState* pNewSt
pFilterChL->Release();
pFilterChR->Release();
m_pdsStreamFilter->pTrigger->trigger();
}
m_bBFormatIsInit = true;
}
else {
return; //RotationMode is set to a wrong String
}
......@@ -808,7 +803,7 @@ void CVAAmbisonicsBinauralMixdownReproduction::UpdateScene(CVASceneState* pNewSt
return;
}
......
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