[pulseaudio-discuss] [PATCH 20/21 v2] loopback: Add adjust_time_msec parameter to allow adjust times below 1s

Georg Chini georg at chini.tk
Sun Feb 19 16:15:28 UTC 2017


A new parameter is introduced to allow specifying smaller adjust_time values
than 1s. This may be useful for a better latency control, although with alsa
devices and the current smoother code no improvement could be found.
This patch also changes the default adjust time to 1s, the old value of 10s
does not allow a tight control of the end to end latency and would lead to
unnecessary jitter.

---
 src/modules/module-loopback.c | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/src/modules/module-loopback.c b/src/modules/module-loopback.c
index 4d85ee5..f4b17ef 100644
--- a/src/modules/module-loopback.c
+++ b/src/modules/module-loopback.c
@@ -46,6 +46,7 @@ PA_MODULE_USAGE(
         "source=<source to connect to> "
         "sink=<sink to connect to> "
         "adjust_time=<how often to readjust rates in s> "
+        "adjust_time_msec=<how often to readjust rates in ms> "
         "latency_msec=<latency in ms> "
         "low_device_latency=<boolean, use half of the normal device latency> "
         "adjust_threshold_usec=<threshold for latency adjustment in usec> "
@@ -69,7 +70,7 @@ PA_MODULE_USAGE(
 
 #define MIN_DEVICE_LATENCY (2.5*PA_USEC_PER_MSEC)
 
-#define DEFAULT_ADJUST_TIME_USEC (10*PA_USEC_PER_SEC)
+#define DEFAULT_ADJUST_TIME_USEC (1*PA_USEC_PER_SEC)
 
 typedef struct loopback_msg loopback_msg;
 
@@ -191,6 +192,7 @@ static const char* const valid_modargs[] = {
     "source",
     "sink",
     "adjust_time",
+    "adjust_time_msec",
     "latency_msec",
     "low_device_latency",
     "adjust_threshold_usec",
@@ -1491,6 +1493,7 @@ int pa__init(pa_module *m) {
     bool channels_set = false;
     pa_memchunk silence;
     uint32_t adjust_time_sec;
+    uint32_t adjust_time_msec;
     const char *n;
     bool remix = true;
     bool low_device_latency = false;
@@ -1608,10 +1611,18 @@ int pa__init(pa_module *m) {
         goto fail;
     }
 
-    if (adjust_time_sec != DEFAULT_ADJUST_TIME_USEC / PA_USEC_PER_SEC)
+    adjust_time_msec = DEFAULT_ADJUST_TIME_USEC / PA_USEC_PER_MSEC;
+    if (pa_modargs_get_value_u32(ma, "adjust_time_msec", &adjust_time_msec) < 0 || (adjust_time_msec != 0 && adjust_time_msec < 100)) {
+        pa_log("Failed to parse adjust_time_msec value");
+        goto fail;
+    }
+
+    /* If adjust_time and adjust_time_msec are both specified, prefer the adjust_time_msec value */
+    u->adjust_time = DEFAULT_ADJUST_TIME_USEC;
+    if (adjust_time_msec != DEFAULT_ADJUST_TIME_USEC / PA_USEC_PER_MSEC)
+        u->adjust_time = adjust_time_msec * PA_USEC_PER_MSEC;
+    else if (adjust_time_sec != DEFAULT_ADJUST_TIME_USEC / PA_USEC_PER_SEC)
         u->adjust_time = adjust_time_sec * PA_USEC_PER_SEC;
-    else
-        u->adjust_time = DEFAULT_ADJUST_TIME_USEC;
 
     u->real_adjust_time = u->adjust_time;
 
-- 
2.10.1



More information about the pulseaudio-discuss mailing list