]> git.alsa-project.org Git - alsa-utils.git/commitdiff
bat: Add 'readcapture' option to support analyzing external audio
authorTim Bird <tim.bird@sony.com>
Tue, 17 May 2022 15:50:49 +0000 (09:50 -0600)
committerJaroslav Kysela <perex@perex.cz>
Fri, 4 Nov 2022 21:06:00 +0000 (22:06 +0100)
If audio data is captured on another device (ie we are NOT using
loopback mode), then allow alsabat to analyze that data, by passing
a filename reference on the command line.

Add the '--readcapture' option to the argument parser. When
this option is specified, avoid doing a local capture, and instead
just read the audio data from the indicated file, and analyze that.

Fixes: https://github.com/alsa-project/alsa-utils/pull/166
Signed-off-by: Tim Bird <tim.bird@sony.com>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
bat/bat.c
bat/common.h

index 86457703e3c53f3dd5f214abd62d005942cb281e..17d025d5544ecbd0de0271cbda7eb2b24a23beb3 100644 (file)
--- a/bat/bat.c
+++ b/bat/bat.c
@@ -331,6 +331,8 @@ _("Usage: alsabat [-options]...\n"
 "      --log=#            file that both stdout and strerr redirecting to\n"
 "      --file=#           file for playback\n"
 "      --saveplay=#       file that storing playback content, for debug\n"
+"      --readcapture=#    file with previously captured content.  File data\n"
+"                         is used for analysis instead of capturing it.\n"
 "      --local            internal loop, set to bypass pcm hardware devices\n"
 "      --standalone       standalone mode, to bypass analysis\n"
 "      --roundtriplatency round trip latency mode\n"
@@ -397,6 +399,7 @@ static void parse_arguments(struct bat *bat, int argc, char *argv[])
                {"roundtriplatency", 0, 0, OPT_ROUNDTRIPLATENCY},
                {"snr-db",   1, 0, OPT_SNRTHD_DB},
                {"snr-pc",   1, 0, OPT_SNRTHD_PC},
+               {"readcapture", 1, 0, OPT_READCAPTURE},
                {0, 0, 0, 0}
        };
 
@@ -412,6 +415,11 @@ static void parse_arguments(struct bat *bat, int argc, char *argv[])
                case OPT_SAVEPLAY:
                        bat->debugplay = optarg;
                        break;
+               case OPT_READCAPTURE:
+                       bat->capturefile = optarg;
+                       bat->capture.mode = MODE_ANALYZE_ONLY;
+                       bat->playback.mode = MODE_ANALYZE_ONLY;
+                       break;
                case OPT_LOCAL:
                        bat->local = true;
                        break;
@@ -708,6 +716,15 @@ int main(int argc, char *argv[])
                goto analyze;
        }
 
+       if (bat.capture.mode == MODE_ANALYZE_ONLY && bat.capturefile) {
+               bat.capture.file = strdup(bat.capturefile);
+               fprintf(bat.log,
+                       _("Using data from file %s for analysis\n"),
+                       bat.capture.file);
+               fprintf(bat.log, _("Skipping playback and capture\n"));
+               goto analyze;
+       }
+
        /* loopback thread: playback and capture in a loop */
        if (bat.local == false)
                test_loopback(&bat);
index 1b07fbeb7755d676f8f5f53f185d18711c4b614b..a9bae5d2b7417e29ab424f778a9eef2c42b508d3 100644 (file)
@@ -25,6 +25,7 @@
 #define OPT_ROUNDTRIPLATENCY           (OPT_BASE + 6)
 #define OPT_SNRTHD_DB                  (OPT_BASE + 7)
 #define OPT_SNRTHD_PC                  (OPT_BASE + 8)
+#define OPT_READCAPTURE                        (OPT_BASE + 9)
 
 #define COMPOSE(a, b, c, d)            ((a) | ((b)<<8) | ((c)<<16) | ((d)<<24))
 #define WAV_RIFF                       COMPOSE('R', 'I', 'F', 'F')
@@ -151,6 +152,7 @@ enum _bat_op_mode {
        MODE_UNKNOWN = -1,
        MODE_SINGLE = 0,
        MODE_LOOPBACK,
+       MODE_ANALYZE_ONLY,
        MODE_LAST
 };
 
@@ -223,6 +225,7 @@ struct bat {
        char *narg;                     /* argument string of duration */
        char *logarg;                   /* path name of log file */
        char *debugplay;                /* path name to store playback signal */
+       char *capturefile;              /* path name for previously saved recording */
        bool standalone;                /* enable to bypass analysis */
        bool roundtriplatency;          /* enable round trip latency */