Skip to content

Commit

Permalink
math: avoid re-initialising variables every loop iteration
Browse files Browse the repository at this point in the history
In psy_get_mel_filterbank() if fb->slaney_normalize isn't set, 3
variables are reset to the same values needless every loop iteration.
Move initialisations outside the loop instead.

Signed-off-by: Guennadi Liakhovetski <[email protected]>
  • Loading branch information
lyakh authored and kv2019i committed Apr 3, 2024
1 parent 1ce9e45 commit f77bdfb
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/math/auditory/auditory.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ int psy_get_mel_filterbank(struct psy_mel_filterbank *fb)
int32_t up_slope;
int32_t down_slope;
int32_t slope;
int32_t scale;
int32_t scale_inv;
int32_t scale = ONE_Q16;
int32_t scale_inv = ONE_Q16;
int16_t *mel;
int16_t mel_start;
int16_t mel_end;
Expand Down Expand Up @@ -137,6 +137,8 @@ int psy_get_mel_filterbank(struct psy_mel_filterbank *fb)
if (fb->scratch_length1 < fb->half_fft_bins)
return -ENOMEM;

fb->scale_log2 = 0;

mel = fb->scratch_data1;
for (i = 0; i < fb->half_fft_bins; i++) {
f = fb->samplerate * i / fb->fft_bins;
Expand Down Expand Up @@ -164,10 +166,6 @@ int psy_get_mel_filterbank(struct psy_mel_filterbank *fb)
}

scale = Q_MULTSR_32X32((int64_t)scale, scale_inv, 16, 16, 16);
} else {
scale = ONE_Q16;
scale_inv = ONE_Q16;
fb->scale_log2 = 0;
}
for (j = 0; j < fb->half_fft_bins; j++) {
up_slope = (((int32_t)mel[j] - left_mel) << 15) / delta_cl; /* Q17.15 */
Expand Down

0 comments on commit f77bdfb

Please sign in to comment.