]> git.alsa-project.org Git - alsa-utils.git/commitdiff
arecord: Inform users when 8-bit sampling is used on tty
authorJaroslav Kysela <perex@perex.cz>
Mon, 14 Jun 2021 10:22:08 +0000 (12:22 +0200)
committerJaroslav Kysela <perex@perex.cz>
Mon, 14 Jun 2021 10:25:10 +0000 (12:25 +0200)
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>
aplay/aplay.c

index d89b7df1340b3712c6b6a489588ef77ddee95474..cc51dcb48bba395cdbbe002e38e6d8f0d52872ee 100644 (file)
@@ -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;