arecord: Inform users when 8-bit sampling is used on tty

When we reverted 0c5948e ("aplay: try to use 16-bit format to
increase capture quality"), we should also handle the original
problem somehow. This code shows a warning with a hint to
the right parameter.

Fixes: https://github.com/alsa-project/alsa-utils/issues/96
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
This commit is contained in:
Jaroslav Kysela 2021-06-14 12:22:08 +02:00
parent f35b66d8f1
commit fc7500c3c7

View file

@ -525,7 +525,7 @@ int main(int argc, char *argv[])
}; };
char *pcm_name = "default"; char *pcm_name = "default";
int tmp, err, c; int tmp, err, c;
int do_device_list = 0, do_pcm_list = 0; int do_device_list = 0, do_pcm_list = 0, force_sample_format = 0;
snd_pcm_info_t *info; snd_pcm_info_t *info;
FILE *direction; FILE *direction;
@ -612,6 +612,7 @@ int main(int argc, char *argv[])
} }
break; break;
case 'f': case 'f':
force_sample_format = 1;
if (strcasecmp(optarg, "cd") == 0 || strcasecmp(optarg, "cdr") == 0) { if (strcasecmp(optarg, "cd") == 0 || strcasecmp(optarg, "cdr") == 0) {
if (strcasecmp(optarg, "cdr") == 0) if (strcasecmp(optarg, "cdr") == 0)
rhwparams.format = SND_PCM_FORMAT_S16_BE; rhwparams.format = SND_PCM_FORMAT_S16_BE;
@ -844,6 +845,14 @@ int main(int argc, char *argv[])
} }
} }
if (!force_sample_format &&
isatty(fileno(stdin)) &&
stream == SND_PCM_STREAM_CAPTURE &&
snd_pcm_format_width(rhwparams.format) <= 8)
fprintf(stderr, "Warning: Some sources (like microphones) may produce inaudiable results\n"
" with 8-bit sampling. Use '-f' argument to increase resolution\n"
" e.g. '-f S16_LE'.\n");
chunk_size = 1024; chunk_size = 1024;
hwparams = rhwparams; hwparams = rhwparams;