68 if (self->count == 1) {
69 self->cycle_time = system_time;
72 self->cycle_time +=
self->clock_period * period;
73 loop_error = system_time -
self->cycle_time;
75 self->cycle_time +=
FFMAX(self->feedback2_factor, 1.0 / self->count) * loop_error;
76 self->clock_period +=
self->feedback3_factor * loop_error / period;
78 return self->cycle_time;
83 #define LFG_MAX ((1LL << 32) - 1) 90 double ideal[SAMPLES];
91 double samples[SAMPLES];
92 for (n0 = 0; n0 < 40; n0 = 2 * n0 + 1) {
93 for (n1 = 0; n1 < 10; n1 = 2 * n1 + 1) {
94 double best_error = 1000000000;
96 double bestpar1 = 0.001;
100 for (i = 0; i < SAMPLES; i++) {
101 ideal[i] = 10 + i + n1 * i / (1000);
102 samples[i] = ideal[i] + n0 * (
av_lfg_get(&prng) - LFG_MAX / 2) / (LFG_MAX * 10LL);
108 for (par0 = bestpar0 * 0.8; par0 <= bestpar0 * 1.21; par0 += bestpar0 * 0.05) {
109 for (par1 = bestpar1 * 0.8; par1 <= bestpar1 * 1.21; par1 += bestpar1 * 0.05) {
113 printf(
"Could not allocate memory for timefilter.\n");
116 for (i = 0; i < SAMPLES; i++) {
119 error += (filtered - ideal[i]) * (filtered - ideal[i]);
122 if (error < best_error) {
134 for (i = 0; i < SAMPLES; i++) {
137 printf(
"%f %f %f %f\n", i - samples[i] + 10, filtered - samples[i],
138 samples[
FFMAX(i, 1)] - samples[
FFMAX(i - 1, 0)], filtered - lastfil);
143 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 ...
Opaque type representing a time filter state.
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 ...