Skip to content

Commit d94a426

Browse files
committed
removed unnecessary malloc and multiplication with identity matrix in invertLsMtx2D/3D. Thank you jinnsjj
1 parent cc55bc9 commit d94a426

File tree

1 file changed

+6
-26
lines changed

1 file changed

+6
-26
lines changed

framework/modules/saf_vbap/saf_vbap.c

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -681,15 +681,10 @@ void invertLsMtx3D
681681
)
682682
{
683683
int i, j, n;
684-
float* tempGroup;
685-
float tempInv[9], eye3[9];
684+
float tempGroup[9];
685+
float tempInv[9];
686686
void* hSinv;
687687

688-
for(i=0; i<3; i++)
689-
for(j=0; j<3; j++)
690-
eye3[i*3+j] = i==j ? 1.0f : 0.0f;
691-
tempGroup = malloc1d(9* sizeof(float));
692-
693688
/* pre-calculate inversions of the loudspeaker groups and store into matrix */
694689
(*layoutInvMtx) = malloc1d(N_group * 9 * sizeof(float));
695690
utility_sinv_create(&hSinv, 3);
@@ -700,18 +695,13 @@ void invertLsMtx3D
700695
tempGroup[j*3+i] = U_spkr[ls_groups[n*3+i]*3 + j];
701696

702697
/* get inverse of current group */
703-
utility_sinv(hSinv, tempGroup,tempGroup,3);
704-
cblas_sgemm(CblasRowMajor, CblasNoTrans, CblasTrans, 3, 3, 3, 1.0f,
705-
(float*)eye3, 3,
706-
tempGroup, 3, 0.0f,
707-
(float*)tempInv, 3);
698+
utility_sinv(hSinv, tempGroup, tempInv, 3);
708699

709700
/* store the vectorized inverse as a row the output */
710701
for(i=0; i<3; i++)
711702
for(j=0; j<3; j++)
712703
(*layoutInvMtx)[n*9+(i*3+j)] = tempInv[j*3+i];
713704
}
714-
free(tempGroup);
715705
utility_sinv_destroy(&hSinv);
716706
}
717707

@@ -947,15 +937,10 @@ void invertLsMtx2D
947937
)
948938
{
949939
int i, j, n;
950-
float* tempGroup;
951-
float tempInv[4], eye2[4];
940+
float tempGroup[4];
941+
float tempInv[4];
952942
void* hSinv;
953943

954-
for(i=0; i<2; i++)
955-
for(j=0; j<2; j++)
956-
eye2[i*2+j] = i==j ? 1.0f : 0.0f;
957-
tempGroup = malloc1d(4* sizeof(float));
958-
959944
/* pre-calculate inversions of the loudspeaker groups and store into matrix */
960945
(*layoutInvMtx) = malloc1d(N_pairs * 4 * sizeof(float));
961946
utility_sinv_create(&hSinv, 2);
@@ -966,19 +951,14 @@ void invertLsMtx2D
966951
tempGroup[j*2+i] = U_spkr[ls_pairs[n*2+i]*2 + j];
967952

968953
/* get inverse of current group */
969-
utility_sinv(hSinv, tempGroup,tempGroup,2);
970-
cblas_sgemm(CblasRowMajor, CblasNoTrans, CblasTrans, 2, 2, 2, 1.0,
971-
eye2, 2,
972-
tempGroup, 2, 0.0,
973-
tempInv, 2);
954+
utility_sinv(hSinv, tempGroup, tempInv, 2);
974955

975956
/* store the vectorized inverse as a row the output */
976957
for(i=0; i<2; i++)
977958
for(j=0; j<2; j++)
978959
(*layoutInvMtx)[n*4+(i*2+j)] = tempInv[j*2+i];
979960
}
980961

981-
free(tempGroup);
982962
utility_sinv_destroy(&hSinv);
983963
}
984964

0 commit comments

Comments
 (0)