[pulseaudio-commits] r1958 - in /branches/lennart/src/pulsecore: time-smoother.c time-smoother.h
svnmailer-noreply at 0pointer.de
svnmailer-noreply at 0pointer.de
Sat Oct 27 08:48:02 PDT 2007
Author: lennart
Date: Sat Oct 27 17:48:01 2007
New Revision: 1958
URL: http://0pointer.de/cgi-bin/viewcvs.cgi?rev=1958&root=pulseaudio&view=rev
Log:
add ability to "pause" the input time temporarily. don't accidently overwrite variables we still need.
Modified:
branches/lennart/src/pulsecore/time-smoother.c
branches/lennart/src/pulsecore/time-smoother.h
Modified: branches/lennart/src/pulsecore/time-smoother.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/pulsecore/time-smoother.c?rev=1958&root=pulseaudio&r1=1957&r2=1958&view=diff
==============================================================================
--- branches/lennart/src/pulsecore/time-smoother.c (original)
+++ branches/lennart/src/pulsecore/time-smoother.c Sat Oct 27 17:48:01 2007
@@ -34,7 +34,7 @@
#include "time-smoother.h"
-#define HISTORY_MAX 100
+#define HISTORY_MAX 50
/*
* Implementation of a time smoothing algorithm to synchronize remote
@@ -63,6 +63,8 @@
pa_usec_t adjust_time, history_time;
pa_bool_t monotonic;
+ pa_usec_t time_offset;
+
pa_usec_t px, py; /* Point p, where we want to reach stability */
double dp; /* Gradient we want at point p */
@@ -79,6 +81,9 @@
/* Cached parameters for our interpolation polynomial y=ax^3+b^2+cx */
double a, b, c;
pa_bool_t abc_valid;
+
+ pa_bool_t paused;
+ pa_usec_t pause_time;
};
pa_smoother* pa_smoother_new(pa_usec_t adjust_time, pa_usec_t history_time, pa_bool_t monotonic) {
@@ -90,6 +95,7 @@
s = pa_xnew(pa_smoother, 1);
s->adjust_time = adjust_time;
s->history_time = history_time;
+ s->time_offset = 0;
s->monotonic = monotonic;
s->px = s->py = 0;
@@ -104,6 +110,8 @@
s->last_y = 0;
s->abc_valid = FALSE;
+
+ s->paused = FALSE;
return s;
}
@@ -293,12 +301,24 @@
}
void pa_smoother_put(pa_smoother *s, pa_usec_t x, pa_usec_t y) {
- pa_assert(s);
+ pa_usec_t ney;
+ double nde;
+
+ pa_assert(s);
+ pa_assert(x >= s->time_offset);
+
+ /* Fix up x value */
+ if (s->paused)
+ x = s->pause_time;
+ else
+ x -= s->time_offset;
+
+ pa_assert(x >= s->ex);
/* First, we calculate the position we'd estimate for x, so that
* we can adjust our position smoothly from this one */
- estimate(s, x, &s->ey, &s->de);
- s->ex = x;
+ estimate(s, x, &ney, &nde);
+ s->ex = x; s->ey = ney; s->de = nde;
/* Then, we add the new measurement to our history */
add_to_history(s, x, y);
@@ -317,7 +337,42 @@
pa_usec_t y;
pa_assert(s);
+ pa_assert(x >= s->time_offset);
+
+ /* Fix up x value */
+ if (s->paused)
+ x = s->pause_time;
+ else
+ x -= s->time_offset;
+
+ pa_assert(x >= s->ex);
estimate(s, x, &y, NULL);
return y;
}
+
+void pa_smoother_set_time_offset(pa_smoother *s, pa_usec_t offset) {
+ pa_assert(s);
+
+ s->time_offset = offset;
+}
+
+void pa_smoother_pause(pa_smoother *s, pa_usec_t x) {
+ pa_assert(s);
+
+ if (s->paused)
+ return;
+
+ s->paused = TRUE;
+ s->pause_time = x;
+}
+
+void pa_smoother_resume(pa_smoother *s, pa_usec_t x) {
+ pa_assert(s);
+
+ if (!s->paused)
+ return;
+
+ s->paused = FALSE;
+ s->time_offset += x - s->pause_time;
+}
Modified: branches/lennart/src/pulsecore/time-smoother.h
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/pulsecore/time-smoother.h?rev=1958&root=pulseaudio&r1=1957&r2=1958&view=diff
==============================================================================
--- branches/lennart/src/pulsecore/time-smoother.h (original)
+++ branches/lennart/src/pulsecore/time-smoother.h Sat Oct 27 17:48:01 2007
@@ -29,10 +29,15 @@
typedef struct pa_smoother pa_smoother;
-pa_smoother* pa_smoother_new(pa_usec_t adjust_x, pa_usec_t history_x, pa_bool_t monotonic);
+pa_smoother* pa_smoother_new(pa_usec_t adjust_time, pa_usec_t history_time, pa_bool_t monotonic);
void pa_smoother_free(pa_smoother* s);
void pa_smoother_put(pa_smoother *s, pa_usec_t x, pa_usec_t y);
pa_usec_t pa_smoother_get(pa_smoother *s, pa_usec_t x);
+void pa_smoother_set_time_offset(pa_smoother *s, pa_usec_t offset);
+
+void pa_smoother_pause(pa_smoother *s, pa_usec_t x);
+void pa_smoother_resume(pa_smoother *s, pa_usec_t x);
+
#endif
More information about the pulseaudio-commits
mailing list