Skip to content

Commit

Permalink
Audio: Optimize mel filterbank computation
Browse files Browse the repository at this point in the history
This check-in optimizes the mel filterbank generation function by
precomputing mel values for each FFT frequency ahead of the main
processing loop.

By calculating the psy_hz_to_mel conversions once for each required
frequency and storing these values in fb->scratch_data1, we avoid
redundant computations within the core loops for filter bank coefficient
calculation. This optimization reduces computational overhead,
especially beneficial for large FFT bin sizes.

The aim is to enhance execution efficiency of the mel filterbank
generation without altering its functional output.

Impact:
- Decreased computation load and execution time during filterbank
  creation.
- Maintained functional behavior, ensuring performance gains do not
  compromise accuracy or result integrity.

Signed-off-by: Shriram Shastry <[email protected]>
  • Loading branch information
ShriramShastry committed May 23, 2024
1 parent 3559f58 commit c5273f0
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/math/auditory/auditory.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ int psy_get_mel_filterbank(struct psy_mel_filterbank *fb)
int32_t slope;
int32_t scale = ONE_Q16;
int32_t scale_inv = ONE_Q16;
int16_t *mel;
int16_t mel_start;
int16_t mel_end;
int16_t mel_step;
Expand Down Expand Up @@ -139,7 +138,8 @@ int psy_get_mel_filterbank(struct psy_mel_filterbank *fb)

fb->scale_log2 = 0;

mel = fb->scratch_data1;
/* Precompute all mel values outside of the inner loop */
int16_t *mel = fb->scratch_data1;
for (i = 0; i < fb->half_fft_bins; i++) {
f = fb->samplerate * i / fb->fft_bins;
mel[i] = psy_hz_to_mel(f);
Expand Down

0 comments on commit c5273f0

Please sign in to comment.