From fc7500c3c7a7d6bfb975a87e23b7544a84da3186 Mon Sep 17 00:00:00 2001 From: Jaroslav Kysela Date: Mon, 14 Jun 2021 12:22:08 +0200 Subject: [PATCH] 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 --- aplay/aplay.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/aplay/aplay.c b/aplay/aplay.c index d89b7df..cc51dcb 100644 --- a/aplay/aplay.c +++ b/aplay/aplay.c @@ -525,7 +525,7 @@ int main(int argc, char *argv[]) }; char *pcm_name = "default"; 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; FILE *direction; @@ -612,6 +612,7 @@ int main(int argc, char *argv[]) } break; case 'f': + force_sample_format = 1; if (strcasecmp(optarg, "cd") == 0 || strcasecmp(optarg, "cdr") == 0) { if (strcasecmp(optarg, "cdr") == 0) 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; hwparams = rhwparams;