diff options
author | Jaroslav Kysela <perex@perex.cz> | 2020-10-15 13:12:37 +0200 |
---|---|---|
committer | Jaroslav Kysela <perex@perex.cz> | 2020-10-15 13:14:39 +0200 |
commit | 246e132b802ba83a902b3b20f654151ee810850c (patch) | |
tree | 57e0fd71e55d6932107fa8a414e688923d1de2f2 /aplay | |
parent | 860b851639f1674ad003114acc4a6c15fa94ab6e (diff) | |
download | alsa-utils-246e132b802ba83a902b3b20f654151ee810850c.tar.gz |
aplay: fix the wrong count in compute_max_peak() for 16bit+ sample widths
The count argument was renamed to samples to correctly represent
the value meaning. Also, remove the wrong count recalculation lines
for 16-bit, 24-bit and 32-bit samples.
BugLink: https://github.com/alsa-project/alsa-utils/issues/57
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
Diffstat (limited to 'aplay')
-rw-r--r-- | aplay/aplay.c | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/aplay/aplay.c b/aplay/aplay.c index b002cec..0a65ad6 100644 --- a/aplay/aplay.c +++ b/aplay/aplay.c @@ -1765,12 +1765,12 @@ static void print_vu_meter(signed int *perc, signed int *maxperc) } /* peak handler */ -static void compute_max_peak(u_char *data, size_t count) +static void compute_max_peak(u_char *data, size_t samples) { signed int val, max, perc[2], max_peak[2]; - static int run = 0; - size_t ocount = count; - int format_little_endian = snd_pcm_format_little_endian(hwparams.format); + static int run = 0; + size_t osamples = samples; + int format_little_endian = snd_pcm_format_little_endian(hwparams.format); int ichans, c; if (vumeter == VUMETER_STEREO) @@ -1784,7 +1784,7 @@ static void compute_max_peak(u_char *data, size_t count) signed char *valp = (signed char *)data; signed char mask = snd_pcm_format_silence(hwparams.format); c = 0; - while (count-- > 0) { + while (samples-- > 0) { val = *valp++ ^ mask; val = abs(val); if (max_peak[c] < val) @@ -1799,9 +1799,8 @@ static void compute_max_peak(u_char *data, size_t count) signed short mask = snd_pcm_format_silence_16(hwparams.format); signed short sval; - count /= 2; c = 0; - while (count-- > 0) { + while (samples-- > 0) { if (format_little_endian) sval = le16toh(*valp); else @@ -1819,9 +1818,8 @@ static void compute_max_peak(u_char *data, size_t count) unsigned char *valp = data; signed int mask = snd_pcm_format_silence_32(hwparams.format); - count /= 3; c = 0; - while (count-- > 0) { + while (samples-- > 0) { if (format_little_endian) { val = valp[0] | (valp[1]<<8) | (valp[2]<<16); } else { @@ -1844,9 +1842,8 @@ static void compute_max_peak(u_char *data, size_t count) signed int *valp = (signed int *)data; signed int mask = snd_pcm_format_silence_32(hwparams.format); - count /= 4; c = 0; - while (count-- > 0) { + while (samples-- > 0) { if (format_little_endian) val = le32toh(*valp); else @@ -1895,8 +1892,8 @@ static void compute_max_peak(u_char *data, size_t count) print_vu_meter(perc, maxperc); fflush(stderr); } - else if(verbose==3) { - fprintf(stderr, _("Max peak (%li samples): 0x%08x "), (long)ocount, max_peak[0]); + else if (verbose==3) { + fprintf(stderr, _("Max peak (%li samples): 0x%08x "), (long)osamples, max_peak[0]); for (val = 0; val < 20; val++) if (val <= perc[0] / 5) putc('#', stderr); |