Commit 08ffd370 authored by Michael Niedermayer's avatar Michael Niedermayer

Allow timespans to vary.

No change in performance if they do not vary.

Originally committed as revision 17840 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent 28e947e4
...@@ -34,10 +34,10 @@ struct TimeFilter { ...@@ -34,10 +34,10 @@ struct TimeFilter {
double integrator2_state; double integrator2_state;
}; };
TimeFilter * ff_timefilter_new(double period, double feedback2_factor, double feedback3_factor) TimeFilter * ff_timefilter_new(double feedback2_factor, double feedback3_factor)
{ {
TimeFilter *self = av_mallocz(sizeof(TimeFilter)); TimeFilter *self = av_mallocz(sizeof(TimeFilter));
self->integrator2_state = period; self->integrator2_state = 1.0;
self->feedback2_factor = feedback2_factor; self->feedback2_factor = feedback2_factor;
self->feedback3_factor = feedback3_factor; self->feedback3_factor = feedback3_factor;
return self; return self;
...@@ -53,20 +53,20 @@ void ff_timefilter_reset(TimeFilter *self) ...@@ -53,20 +53,20 @@ void ff_timefilter_reset(TimeFilter *self)
self->cycle_time = 0; self->cycle_time = 0;
} }
void ff_timefilter_update(TimeFilter *self, double system_time) void ff_timefilter_update(TimeFilter *self, double system_time, double period)
{ {
if (!self->cycle_time) { if (!self->cycle_time) {
/// init loop /// init loop
self->cycle_time = system_time; self->cycle_time = system_time;
} else { } else {
double loop_error; double loop_error;
self->cycle_time+= self->integrator2_state; self->cycle_time+= self->integrator2_state * period;
/// calculate loop error /// calculate loop error
loop_error = system_time - self->cycle_time; loop_error = system_time - self->cycle_time;
/// update loop /// update loop
self->cycle_time += self->feedback2_factor * loop_error; self->cycle_time += self->feedback2_factor * loop_error;
self->integrator2_state += self->feedback3_factor * loop_error; self->integrator2_state += self->feedback3_factor * loop_error / period;
} }
} }
......
...@@ -37,10 +37,6 @@ typedef struct TimeFilter TimeFilter; ...@@ -37,10 +37,6 @@ typedef struct TimeFilter TimeFilter;
/** /**
* Create a new Delay Locked Loop time filter * Create a new Delay Locked Loop time filter
* *
* period is the device cycle duration in seconds. For example, at
* 44.1Hz and a buffer size of 512 frames, period = 512 / 44100. The filter
* only works if the cycle duration is fixed.
*
* feedback2_factor and feedback3_factor are the factors used for the * feedback2_factor and feedback3_factor are the factors used for the
* multiplications that are respectively performed in the second and third * multiplications that are respectively performed in the second and third
* feedback paths of the loop. * feedback paths of the loop.
...@@ -58,19 +54,22 @@ typedef struct TimeFilter TimeFilter; ...@@ -58,19 +54,22 @@ typedef struct TimeFilter TimeFilter;
* For more details about these parameters and background concepts please see: * For more details about these parameters and background concepts please see:
* http://www.kokkinizita.net/papers/usingdll.pdf * http://www.kokkinizita.net/papers/usingdll.pdf
*/ */
TimeFilter * ff_timefilter_new(double period, double feedback2_factor, double feedback3_factor); TimeFilter * ff_timefilter_new(double feedback2_factor, double feedback3_factor);
/** /**
* Update the filter * Update the filter
* *
* This function must be called in real time, at each process cycle. * This function must be called in real time, at each process cycle.
* *
* period is the device cycle duration in seconds. For example, at
* 44.1Hz and a buffer size of 512 frames, period = 512 / 44100.
*
* system_time, in seconds, should be the value of the system clock time, * system_time, in seconds, should be the value of the system clock time,
* at (or as close as possible to) the moment the device hardware interrupt * at (or as close as possible to) the moment the device hardware interrupt
* occured (or any other event the device clock raises at the beginning of a * occured (or any other event the device clock raises at the beginning of a
* cycle). * cycle).
*/ */
void ff_timefilter_update(TimeFilter *self, double system_time); void ff_timefilter_update(TimeFilter *self, double system_time, double period);
/** /**
* Retrieve the filtered time * Retrieve the filtered time
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment