[PATCH v6 22/25] loopback: Allow shorter adjust_time

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Allow shorter adjust times than 1s.
In order to not break the existing API, values below 100 will still be
considered to be seconds, while values greater or equal 100 will be ms.
This allows to specify adjust times as low as 100 ms.

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

diff --git a/src/modules/module-loopback.c b/src/modules/module-loopback.c
index 442b24c..77a5c04 100644
--- a/src/modules/module-loopback.c
+++ b/src/modules/module-loopback.c
@@ -45,7 +45,7 @@ PA_MODULE_LOAD_ONCE(false);
 PA_MODULE_USAGE(
         "source=<source to connect to> "
         "sink=<sink to connect to> "
-        "adjust_time=<how often to readjust rates in s> "
+        "adjust_time=<how often to readjust rates in s, values >= 100 are in ms> "
         "latency_msec=<latency in ms> "
         "format=<sample format> "
         "rate=<sample rate> "
@@ -65,7 +65,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)
 
 struct userdata {
     pa_core *core;
@@ -1107,7 +1107,7 @@ int pa__init(pa_module *m) {
     bool rate_set = false;
     bool channels_set = false;
     pa_memchunk silence;
-    uint32_t adjust_time_sec;
+    uint32_t adjust_time;
     const char *n;
     bool remix = true;
 
@@ -1197,16 +1197,19 @@ int pa__init(pa_module *m) {
     u->extra_latency = 0;
     u->latency_error = 0;
 
-    adjust_time_sec = DEFAULT_ADJUST_TIME_USEC / PA_USEC_PER_SEC;
-    if (pa_modargs_get_value_u32(ma, "adjust_time", &adjust_time_sec) < 0) {
+    /* The default adjust time is set to 1s. The adjust time given on the
+     * command line is considered to be in seconds if it is below 100,
+     * else ms are assumed. */
+    adjust_time = DEFAULT_ADJUST_TIME_USEC / PA_USEC_PER_SEC;
+    if (pa_modargs_get_value_u32(ma, "adjust_time", &adjust_time) < 0) {
         pa_log("Failed to parse adjust_time value");
         goto fail;
     }
 
-    if (adjust_time_sec != DEFAULT_ADJUST_TIME_USEC / PA_USEC_PER_SEC)
-        u->adjust_time = adjust_time_sec * PA_USEC_PER_SEC;
+    if (adjust_time < 100)
+        u->adjust_time = adjust_time * PA_USEC_PER_SEC;
     else
-        u->adjust_time = DEFAULT_ADJUST_TIME_USEC;
+        u->adjust_time = adjust_time * PA_USEC_PER_MSEC;
 
     u->real_adjust_time = u->adjust_time;
     u->real_adjust_time_sum = 0;
-- 
2.8.1



[Index of Archives]     [Linux Audio Users]     [AMD Graphics]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux