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>
This commit is contained in:
Jaroslav Kysela 2020-10-15 13:12:37 +02:00
parent 860b851639
commit 246e132b80

View file

@ -1765,11 +1765,11 @@ static void print_vu_meter(signed int *perc, signed int *maxperc)
} }
/* peak handler */ /* 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]; signed int val, max, perc[2], max_peak[2];
static int run = 0; static int run = 0;
size_t ocount = count; size_t osamples = samples;
int format_little_endian = snd_pcm_format_little_endian(hwparams.format); int format_little_endian = snd_pcm_format_little_endian(hwparams.format);
int ichans, c; int ichans, c;
@ -1784,7 +1784,7 @@ static void compute_max_peak(u_char *data, size_t count)
signed char *valp = (signed char *)data; signed char *valp = (signed char *)data;
signed char mask = snd_pcm_format_silence(hwparams.format); signed char mask = snd_pcm_format_silence(hwparams.format);
c = 0; c = 0;
while (count-- > 0) { while (samples-- > 0) {
val = *valp++ ^ mask; val = *valp++ ^ mask;
val = abs(val); val = abs(val);
if (max_peak[c] < 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 mask = snd_pcm_format_silence_16(hwparams.format);
signed short sval; signed short sval;
count /= 2;
c = 0; c = 0;
while (count-- > 0) { while (samples-- > 0) {
if (format_little_endian) if (format_little_endian)
sval = le16toh(*valp); sval = le16toh(*valp);
else else
@ -1819,9 +1818,8 @@ static void compute_max_peak(u_char *data, size_t count)
unsigned char *valp = data; unsigned char *valp = data;
signed int mask = snd_pcm_format_silence_32(hwparams.format); signed int mask = snd_pcm_format_silence_32(hwparams.format);
count /= 3;
c = 0; c = 0;
while (count-- > 0) { while (samples-- > 0) {
if (format_little_endian) { if (format_little_endian) {
val = valp[0] | (valp[1]<<8) | (valp[2]<<16); val = valp[0] | (valp[1]<<8) | (valp[2]<<16);
} else { } else {
@ -1844,9 +1842,8 @@ static void compute_max_peak(u_char *data, size_t count)
signed int *valp = (signed int *)data; signed int *valp = (signed int *)data;
signed int mask = snd_pcm_format_silence_32(hwparams.format); signed int mask = snd_pcm_format_silence_32(hwparams.format);
count /= 4;
c = 0; c = 0;
while (count-- > 0) { while (samples-- > 0) {
if (format_little_endian) if (format_little_endian)
val = le32toh(*valp); val = le32toh(*valp);
else else
@ -1895,8 +1892,8 @@ static void compute_max_peak(u_char *data, size_t count)
print_vu_meter(perc, maxperc); print_vu_meter(perc, maxperc);
fflush(stderr); fflush(stderr);
} }
else if(verbose==3) { else if (verbose==3) {
fprintf(stderr, _("Max peak (%li samples): 0x%08x "), (long)ocount, max_peak[0]); fprintf(stderr, _("Max peak (%li samples): 0x%08x "), (long)osamples, max_peak[0]);
for (val = 0; val < 20; val++) for (val = 0; val < 20; val++)
if (val <= perc[0] / 5) if (val <= perc[0] / 5)
putc('#', stderr); putc('#', stderr);