Skip to content

Commit

Permalink
Audio: Bugfix: Optimize level_update function and improve comments
Browse files Browse the repository at this point in the history
Use int32_t instead of int64_t to improve performance in level_update.

Improve comments in max_mic_distance function to better explain the
distance calculation between all possible microphone pairs. Correct
the typo in line_array_mode_check function.

Signed-off-by: Shriram Shastry <[email protected]>

Address reviewer comments: Improve comments in max_mic_distance and
correct typo in line_array_mode_check
  • Loading branch information
ShriramShastry authored and kv2019i committed Aug 5, 2024
1 parent ae830b4 commit a4c44ad
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/audio/tdfb/tdfb_direction.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@ 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++) {
/* Start from i+1 halves the amount of iteration & to eliminate redundant checks */
/* Calculate distances between all possible microphone pairs to
* find the maximum distance
*/
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;
Expand Down Expand Up @@ -155,7 +157,7 @@ static bool line_array_mode_check(struct tdfb_comp_data *cd)

/* Cross product of vectors AB and AC is (0, 0, 0) if they are co-linear.
* Form vector AB(a,b,c) from x(i+1) - x(i), y(i+1) - y(i), z(i+1) - z(i)
* Form vector AC(d,e,f) from x(i+2) - x(i), y(i+2) - y(1), z(i+2) - z(i)
* Form vector AC(d,e,f) from x(i+2) - x(i), y(i+2) - y(i), z(i+2) - z(i)
*/
for (i = 0; i < num_mic_locations - 2; i++) {
a = cd->mic_locations[i + 1].x - cd->mic_locations[i].x;
Expand Down Expand Up @@ -280,9 +282,9 @@ 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;
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 a4c44ad

Please sign in to comment.