Skip to content

Commit 2a328dc

Browse files
This check-in refines the TDFB direction calculation, addressing
correctness: Bugfix: - Fix off-by-one error in `line_array_mode_check` ensuring all checks for co-linearity among microphone locations are performed. Signed-off-by: Shriram Shastry <malladi.sastry@intel.com>
1 parent c5df3e2 commit 2a328dc

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/audio/tdfb/tdfb_direction.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,10 @@ static int16_t max_mic_distance(struct tdfb_comp_data *cd)
125125

126126
/* Max lag based on largest array dimension. Microphone coordinates are Q4.12 meters */
127127
for (i = 0; i < cd->config->num_mic_locations; i++) {
128-
/* Start from i+1 halves the amount of iteration & to eliminate redundant checks */
129-
for (j = i + 1; j < cd->config->num_mic_locations; j++) {
128+
for (j = 0; i < cd->config->num_mic_locations; i++) {
129+
if (j == i)
130+
continue;
131+
130132
dx = cd->mic_locations[i].x - cd->mic_locations[j].x;
131133
dy = cd->mic_locations[i].y - cd->mic_locations[j].y;
132134
dz = cd->mic_locations[i].z - cd->mic_locations[j].z;
@@ -157,7 +159,8 @@ static bool line_array_mode_check(struct tdfb_comp_data *cd)
157159
* Form vector AB(a,b,c) from x(i+1) - x(i), y(i+1) - y(i), z(i+1) - z(i)
158160
* Form vector AC(d,e,f) from x(i+2) - x(i), y(i+2) - y(1), z(i+2) - z(i)
159161
*/
160-
for (i = 0; i < num_mic_locations - 3; i++) {
162+
/* Calculates cross product only once */
163+
for (i = 0; i < num_mic_locations - 2; i++) {
161164
a = cd->mic_locations[i + 1].x - cd->mic_locations[i].x;
162165
b = cd->mic_locations[i + 1].y - cd->mic_locations[i].y;
163166
c = cd->mic_locations[i + 1].z - cd->mic_locations[i].z;
@@ -280,10 +283,9 @@ static void level_update(struct tdfb_comp_data *cd, int frames, int ch_count, in
280283
/* Calculate mean square level */
281284
for (n = 0; n < frames; n++) {
282285
s = *p;
283-
tmp += ((int32_t)s * s);
284286
p += ch_count;
285-
/* handle circular buffer */
286287
tdfb_cinc_s16(&p, cd->direction.d_end, cd->direction.d_size);
288+
tmp += ((int64_t)s * s);
287289
}
288290

289291
/* Calculate mean square power */

0 commit comments

Comments
 (0)