Skip to content

Commit

Permalink
Audio: Optimize and fix TDFB direction calculation
Browse files Browse the repository at this point in the history
This check-in refines the TDFB direction calculation, addressing
performance:

- Correct infinite loop in `max_mic_distance` by fixing loop conditions.

These modification collectively enhance the algorithm's robustness
and computational efficiency.

Signed-off-by: Shriram Shastry <malladi.sastry@intel.com>
  • Loading branch information
ShriramShastry committed Jun 11, 2024
1 parent 65bad5c commit c5df3e2
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/audio/tdfb/tdfb_direction.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,8 @@ static int16_t max_mic_distance(struct tdfb_comp_data *cd)

/* Max lag based on largest array dimension. Microphone coordinates are Q4.12 meters */
for (i = 0; i < cd->config->num_mic_locations; i++) {
for (j = 0; i < cd->config->num_mic_locations; i++) {
if (j == i)
continue;

/* Start from i+1 halves the amount of iteration & to eliminate redundant checks */
for (j = i + 1; j < cd->config->num_mic_locations; j++) {
dx = cd->mic_locations[i].x - cd->mic_locations[j].x;
dy = cd->mic_locations[i].y - cd->mic_locations[j].y;
dz = cd->mic_locations[i].z - cd->mic_locations[j].z;
Expand Down Expand Up @@ -282,9 +280,10 @@ static void level_update(struct tdfb_comp_data *cd, int frames, int ch_count, in
/* Calculate mean square level */
for (n = 0; n < frames; n++) {
s = *p;
tmp += ((int32_t)s * s);
p += ch_count;
/* handle circular buffer */
tdfb_cinc_s16(&p, cd->direction.d_end, cd->direction.d_size);
tmp += ((int64_t)s * s);
}

/* Calculate mean square power */
Expand Down

0 comments on commit c5df3e2

Please sign in to comment.