aboutsummaryrefslogtreecommitdiffstats
path: root/libavdevice/timefilter.c
diff options
context:
space:
mode:
authorNicolas George <nicolas.george@normalesup.org>2012-02-15 19:15:45 +0100
committerNicolas George <nicolas.george@normalesup.org>2012-03-05 16:57:27 +0100
commit3073aadf2ded5f02f2db7ee151a02f592ea24733 (patch)
tree9362cec0db3e674132eb99822742fbcd27b154dc /libavdevice/timefilter.c
parent1007a805a486a1348a0543ac2dd99d823148d25c (diff)
downloadffmpeg-3073aadf2ded5f02f2db7ee151a02f592ea24733.tar.gz
timefilter: internally compute feedback factors.
The feedback factors for the timefilter are directly computed from the expected period. This commit changes the init function to accept the period itself and compute the feedback factors internally, rather than having all client code duplicate the formulas. This commit also actually fixes the formulas: the current code had sqrt(2*o), but the correct formula, both theoretically and according to experimental testing, is sqrt(2)*o. Furthermore, it adds an exponential to feedback factors larger than 1 with large periods.
Diffstat (limited to 'libavdevice/timefilter.c')
-rw-r--r--libavdevice/timefilter.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/libavdevice/timefilter.c b/libavdevice/timefilter.c
index e225ed11a9..4b8a10cb40 100644
--- a/libavdevice/timefilter.c
+++ b/libavdevice/timefilter.c
@@ -36,14 +36,21 @@ struct TimeFilter {
int count;
};
-TimeFilter *ff_timefilter_new(double clock_period,
- double feedback2_factor,
- double feedback3_factor)
+/* 1 - exp(-x) using a 3-order power series */
+static double qexpneg(double x)
+{
+ return 1 - 1 / (1 + x * (1 + x / 2 * (1 + x / 3)));
+}
+
+TimeFilter *ff_timefilter_new(double time_base,
+ double period,
+ double bandwidth)
{
TimeFilter *self = av_mallocz(sizeof(TimeFilter));
- self->clock_period = clock_period;
- self->feedback2_factor = feedback2_factor;
- self->feedback3_factor = feedback3_factor;
+ double o = 2 * M_PI * bandwidth * period * time_base;
+ self->clock_period = time_base;
+ self->feedback2_factor = qexpneg(M_SQRT2 * o);
+ self->feedback3_factor = qexpneg(o * o);
return self;
}