]> code.delx.au - pulseaudio/commitdiff
alsa: increase interval between smoother updates exponentially for alsa sources,...
authorLennart Poettering <lennart@poettering.net>
Sun, 23 Aug 2009 20:34:42 +0000 (22:34 +0200)
committerLennart Poettering <lennart@poettering.net>
Sun, 23 Aug 2009 20:34:42 +0000 (22:34 +0200)
src/modules/alsa/alsa-sink.c
src/modules/alsa/alsa-source.c

index c3694729a53a4ce4edad8a622a36db0413ff0a2f..b99ed78235ada3b697dcfe498f4584c90245712c 100644 (file)
@@ -733,10 +733,9 @@ static void update_smoother(struct userdata *u) {
         now1 = pa_rtclock_now();
 
     /* check if the time since the last update is bigger than the interval */
-    if (u->last_smoother_update > 0) {
+    if (u->last_smoother_update > 0)
         if (u->last_smoother_update + u->smoother_interval > now1)
             return;
-    }
 
     position = (int64_t) u->write_count - ((int64_t) delay * (int64_t) u->frame_size);
 
@@ -745,11 +744,11 @@ static void update_smoother(struct userdata *u) {
 
     now2 = pa_bytes_to_usec((uint64_t) position, &u->sink->sample_spec);
 
+    pa_smoother_put(u->smoother, now1, now2);
+
     u->last_smoother_update = now1;
     /* exponentially increase the update interval up to the MAX limit */
     u->smoother_interval = PA_MIN (u->smoother_interval * 2, SMOOTHER_MAX_INTERVAL);
-
-    pa_smoother_put(u->smoother, now1, now2);
 }
 
 static pa_usec_t sink_get_latency(struct userdata *u) {
@@ -927,7 +926,6 @@ static int unsuspend(struct userdata *u) {
     u->first = TRUE;
     u->since_start = 0;
 
-
     pa_log_info("Resumed successfully...");
 
     return 0;
index 7da37553320977303038fec2a96fd3e22dc1eb95..336027a275c7216d311a85cec0e3f8d00b8bc66a 100644 (file)
@@ -65,6 +65,9 @@
 #define TSCHED_MIN_SLEEP_USEC (10*PA_USEC_PER_MSEC)          /* 10ms */
 #define TSCHED_MIN_WAKEUP_USEC (4*PA_USEC_PER_MSEC)          /* 4ms */
 
+#define SMOOTHER_MIN_INTERVAL (2*PA_USEC_PER_MSEC)           /* 2ms */
+#define SMOOTHER_MAX_INTERVAL (200*PA_USEC_PER_MSEC)         /* 200ms */
+
 #define VOLUME_ACCURACY (PA_VOLUME_NORM/100)
 
 struct userdata {
@@ -108,6 +111,8 @@ struct userdata {
 
     pa_smoother *smoother;
     uint64_t read_count;
+    pa_usec_t smoother_interval;
+    pa_usec_t last_smoother_update;
 
     pa_reserve_wrapper *reserve;
     pa_hook_slot *reserve_slot;
@@ -691,15 +696,23 @@ static void update_smoother(struct userdata *u) {
         now1 = pa_timespec_load(&htstamp);
     }
 
-    position = u->read_count + ((uint64_t) delay * (uint64_t) u->frame_size);
-
     /* Hmm, if the timestamp is 0, then it wasn't set and we take the current time */
     if (now1 <= 0)
         now1 = pa_rtclock_now();
 
+    /* check if the time since the last update is bigger than the interval */
+    if (u->last_smoother_update > 0)
+        if (u->last_smoother_update + u->smoother_interval > now1)
+            return;
+
+    position = u->read_count + ((uint64_t) delay * (uint64_t) u->frame_size);
     now2 = pa_bytes_to_usec(position, &u->source->sample_spec);
 
     pa_smoother_put(u->smoother, now1, now2);
+
+    u->last_smoother_update = now1;
+    /* exponentially increase the update interval up to the MAX limit */
+    u->smoother_interval = PA_MIN (u->smoother_interval * 2, SMOOTHER_MAX_INTERVAL);
 }
 
 static pa_usec_t source_get_latency(struct userdata *u) {
@@ -862,6 +875,8 @@ static int unsuspend(struct userdata *u) {
 
     u->read_count = 0;
     pa_smoother_reset(u->smoother, pa_rtclock_now(), TRUE);
+    u->smoother_interval = SMOOTHER_MIN_INTERVAL;
+    u->last_smoother_update = 0;
 
     pa_log_info("Resumed successfully...");
 
@@ -1469,6 +1484,7 @@ pa_source *pa_alsa_source_new(pa_module *m, pa_modargs *ma, const char*driver, p
             5,
             pa_rtclock_now(),
             FALSE);
+    u->smoother_interval = SMOOTHER_MIN_INTERVAL;
 
     dev_id = pa_modargs_get_value(
             ma, "device_id",