41 double feedback2_factor,
42 double feedback3_factor)
45 self->clock_period = clock_period;
46 self->feedback2_factor = feedback2_factor;
47 self->feedback3_factor = feedback3_factor;
64 if (self->count == 1) {
65 self->cycle_time = system_time;
68 self->cycle_time +=
self->clock_period * period;
69 loop_error = system_time -
self->cycle_time;
71 self->cycle_time +=
FFMAX(self->feedback2_factor, 1.0 / self->count) * loop_error;
72 self->clock_period +=
self->feedback3_factor * loop_error / period;
74 return self->cycle_time;
79 #define LFG_MAX ((1LL << 32) - 1)
86 double ideal[SAMPLES];
88 for (n0 = 0; n0 < 40; n0 = 2 * n0 + 1) {
89 for (n1 = 0; n1 < 10; n1 = 2 * n1 + 1) {
90 double best_error = 1000000000;
92 double bestpar1 = 0.001;
96 for (i = 0; i < SAMPLES; i++) {
97 ideal[i] = 10 + i + n1 * i / (1000);
98 samples[i] = ideal[i] + n0 * (
av_lfg_get(&prng) - LFG_MAX / 2) / (LFG_MAX * 10LL);
104 for (par0 = bestpar0 * 0.8; par0 <= bestpar0 * 1.21; par0 += bestpar0 * 0.05) {
105 for (par1 = bestpar1 * 0.8; par1 <= bestpar1 * 1.21; par1 += bestpar1 * 0.05) {
108 for (i = 0; i < SAMPLES; i++) {
111 error += (filtered - ideal[i]) * (filtered - ideal[i]);
114 if (error < best_error) {
126 for (i = 0; i < SAMPLES; i++) {
129 printf(
"%f %f %f %f\n", i - samples[i] + 10, filtered - samples[i],
130 samples[
FFMAX(i, 1)] - samples[
FFMAX(i - 1, 0)], filtered - lastfil);
135 printf(
" [%f %f %9f]", bestpar0, bestpar1, best_error);
void ff_timefilter_destroy(TimeFilter *self)
Free all resources associated with the filter.
memory handling functions
void ff_timefilter_reset(TimeFilter *self)
Reset the filter.
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
int main(int argc, char **argv)
static unsigned int av_lfg_get(AVLFG *c)
Get the next random unsigned 32-bit number using an ALFG.
TimeFilter * ff_timefilter_new(double clock_period, double feedback2_factor, double feedback3_factor)
Create a new Delay Locked Loop time filter.
av_cold void av_lfg_init(AVLFG *c, unsigned int seed)
double ff_timefilter_update(TimeFilter *self, double system_time, double period)
Update the filter.
common internal and external API header
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...