Fixed peak meter

This commit is contained in:
Jaroslav Kysela 2001-10-02 07:43:12 +00:00
parent 9528f8a6c0
commit 0cdfe6f00d

View file

@ -88,7 +88,6 @@ static int buffer_pos = 0;
static size_t bits_per_sample, bits_per_frame;
static size_t chunk_bytes;
static snd_output_t *log;
static unsigned int max_peak = 0;
static int fd = -1;
static int count, fdcount;
@ -510,12 +509,6 @@ int main(int argc, char *argv[])
else
capturev(&argv[optind], argc - optind);
}
if (verbose) {
unsigned int max = (1 << bits_per_sample) - 1;
if (max == 0)
max = ~0;
printf("Max peak: %u (0x%x) %i%%\n", max_peak, max_peak, max_peak / (max / 100));
}
snd_pcm_close(handle);
free(audiobuf);
snd_output_close(log);
@ -879,20 +872,24 @@ void xrun(void)
/* peak handler */
static void compute_max_peak(u_char *data, size_t count)
{
unsigned int val;
size_t step;
signed int val, max, max_peak = 0;
size_t step, ocount = count;
while (count-- > 0) {
switch (bits_per_sample) {
case 8: val = *data ^ snd_pcm_format_silence(hwparams.format); step = 1; break;
case 16: val = *(unsigned short *)data ^ snd_pcm_format_silence_16(hwparams.format); step = 2; break;
case 32: val = *(unsigned int *)data ^ snd_pcm_format_silence_32(hwparams.format); step = 4; break;
case 8: val = *(signed char *)data ^ snd_pcm_format_silence(hwparams.format); step = 1; break;
case 16: val = *(signed short *)data ^ snd_pcm_format_silence_16(hwparams.format); step = 2; break;
case 32: val = *(signed int *)data ^ snd_pcm_format_silence_32(hwparams.format); step = 4; break;
default: val = 0; step = 1; break;
}
data += step;
if (max_peak < val)
max_peak = val;
}
max = 1 << (bits_per_sample-1);
if (max == 0)
max = 0x7fffffff;
printf("Max peak (%li samples): %i (0x%x) %i%%\n", ocount, max_peak, max_peak, max_peak / (max / 100));
}
/*