Skip to content

Commit

Permalink
aplay: fix the wrong count in compute_max_peak() for 16bit+ sample wi…
Browse files Browse the repository at this point in the history
…dths

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: #57
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
  • Loading branch information
perexg committed Oct 15, 2020
1 parent 860b851 commit 246e132
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions aplay/aplay.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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 {
Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 246e132

Please sign in to comment.