]> git.alsa-project.org Git - alsa-utils.git/commitdiff
bat: really skip analysis of the first period and update related comment
authorDelio Brignoli <dbrignoli@audioscience.com>
Mon, 18 Sep 2023 08:33:37 +0000 (09:33 +0100)
committerJaroslav Kysela <perex@perex.cz>
Tue, 17 Oct 2023 11:28:13 +0000 (13:28 +0200)
Prior to this change bat/analyze.c would skip the last period of the recording, contrary to
what the comment in the code which stated the first period was meant to be skipped.

The comment has been updated to state that both the first and last period are skipped and the code
has been updated to match.

Closes: https://github.com/alsa-project/alsa-utils/pull/237
Signed-off-by: Delio Brignoli <dbrignoli@audioscience.com>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
bat/analyze.c

index 686788000f99f74ddf89fe1e73c876c7ea273344..b8d02706fe6677660ee626ab13cc4e02d38e87fd 100644 (file)
@@ -299,7 +299,7 @@ static int calculate_noise(struct bat *bat, float *src, int channel)
        /* each section has 2 sine periods, the first one for locating
         * and the second one for noise calculating */
        int nsamples_per_section = nsamples * 2;
-       /* all sine periods will be calculated except the first one */
+       /* all sine periods will be calculated except the first and last one */
        int nsection = bat->frames / nsamples - 1;
 
        fprintf(bat->log, _("samples per period: %d\n"), nsamples);
@@ -331,7 +331,7 @@ static int calculate_noise(struct bat *bat, float *src, int channel)
        /* calculate average noise level */
        sum_snr_pc = 0.0;
        cnt_clean = cnt_noise = 0;
-       for (i = 0, offset = 0; i < nsection; i++) {
+       for (i = 1, offset = nsamples; i < nsection; i++) {
                na.snr_db = SNR_DB_INVALID;
 
                err = calculate_noise_one_period(bat, &na, src + offset,