aplay: fix VU meter for S24_LE etc formats

When recording or playing back audio in a format where the number of
significant bits is less than the physical width (e.g. S24_LE), the VU
meter code needs to consider the number of significant bits in the samples
rather than the physical sample width (e.g. 24 vs 32 bits). Otherwise the
resulting VU meter display will be far too low and it will just indicate
0% all the time.

Tested with a device supporting the S24_LE format.

Signed-off-by: Ricard Wanderlof <ricardw@axis.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
This commit is contained in:
Ricard Wanderlof 2015-09-15 13:10:00 +02:00 committed by Takashi Iwai
parent 5f0fc49a3a
commit cd1bb5f4a7

View file

@ -124,7 +124,7 @@ static int fatal_errors = 0;
static int verbose = 0; static int verbose = 0;
static int vumeter = VUMETER_NONE; static int vumeter = VUMETER_NONE;
static int buffer_pos = 0; static int buffer_pos = 0;
static size_t bits_per_sample, bits_per_frame; static size_t significant_bits_per_sample, bits_per_sample, bits_per_frame;
static size_t chunk_bytes; static size_t chunk_bytes;
static int test_position = 0; static int test_position = 0;
static int test_coef = 8; static int test_coef = 8;
@ -1344,6 +1344,7 @@ static void set_params(void)
snd_pcm_dump(handle, log); snd_pcm_dump(handle, log);
bits_per_sample = snd_pcm_format_physical_width(hwparams.format); bits_per_sample = snd_pcm_format_physical_width(hwparams.format);
significant_bits_per_sample = snd_pcm_format_width(hwparams.format);
bits_per_frame = bits_per_sample * hwparams.channels; bits_per_frame = bits_per_sample * hwparams.channels;
chunk_bytes = chunk_size * bits_per_frame / 8; chunk_bytes = chunk_size * bits_per_frame / 8;
audiobuf = realloc(audiobuf, chunk_bytes); audiobuf = realloc(audiobuf, chunk_bytes);
@ -1745,7 +1746,7 @@ static void compute_max_peak(u_char *data, size_t count)
} }
return; return;
} }
max = 1 << (bits_per_sample-1); max = 1 << (significant_bits_per_sample-1);
if (max <= 0) if (max <= 0)
max = 0x7fffffff; max = 0x7fffffff;