Revision 1b85ec1e

View differences:

libavformat/timefilter.c
72 72
    }
73 73
    return self->cycle_time;
74 74
}
75

  
76
#ifdef TEST
77
main(){
78
    double n0,n1;
79
#define SAMPLES 1000
80
    double ideal[SAMPLES];
81
    double samples[SAMPLES];
82
    for(n0= 0; n0<40; n0=2*n0+1){
83
        for(n1= 0; n1<10; n1=2*n1+1){
84
            double best_error= 1000000000;
85
            double bestpar0=1;
86
            double bestpar1=0.001;
87
            int better, i;
88

  
89
            srandom(123);
90
            for(i=0; i<SAMPLES; i++){
91
                ideal[i]  = 10 + i + n1*i/(1000);
92
                samples[i]= ideal[i] + n0*(rand()-RAND_MAX/2)/(RAND_MAX*10LL);
93
            }
94

  
95
            do{
96
                double par0, par1;
97
                better=0;
98
                for(par0= bestpar0*0.8; par0<=bestpar0*1.21; par0+=bestpar0*0.05){
99
                    for(par1= bestpar1*0.8; par1<=bestpar1*1.21; par1+=bestpar1*0.05){
100
                        double error=0;
101
                        TimeFilter *tf= ff_timefilter_new(par0, par1);
102
                        for(i=0; i<SAMPLES; i++){
103
                            double filtered;
104
                            filtered=  ff_timefilter_update(tf, samples[i], 1);
105
                            error += (filtered - ideal[i]) * (filtered - ideal[i]);
106
                        }
107
                        ff_timefilter_destroy(tf);
108
                        if(error < best_error){
109
                            best_error= error;
110
                            bestpar0= par0;
111
                            bestpar1= par1;
112
                            better=1;
113
                        }
114
                    }
115
                }
116
            }while(better);
117
            printf(" [%f %f %f]", bestpar0, bestpar1, best_error);
118
        }
119
        printf("\n");
120
    }
121
}
122
#endif

Also available in: Unified diff