diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2009-03-06 00:26:51 +0000 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2009-03-06 00:26:51 +0000 |
commit | 1b85ec1ea231f26184c8e7328322916bdaf08db9 (patch) | |
tree | 27024a5922c32c8c8d6b778cc698191fa0fa7785 /libavformat/timefilter.c | |
parent | 8537591abcf19b802f10e4a76a1f76a4133e4f5a (diff) | |
download | ffmpeg-1b85ec1ea231f26184c8e7328322916bdaf08db9.tar.gz |
Selftest code.
Originally committed as revision 17844 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavformat/timefilter.c')
-rw-r--r-- | libavformat/timefilter.c | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/libavformat/timefilter.c b/libavformat/timefilter.c index 56d2605fcf..809dbc60ce 100644 --- a/libavformat/timefilter.c +++ b/libavformat/timefilter.c @@ -72,3 +72,51 @@ double ff_timefilter_update(TimeFilter *self, double system_time, double period) } return self->cycle_time; } + +#ifdef TEST +main(){ + double n0,n1; +#define SAMPLES 1000 + double ideal[SAMPLES]; + double samples[SAMPLES]; + for(n0= 0; n0<40; n0=2*n0+1){ + for(n1= 0; n1<10; n1=2*n1+1){ + double best_error= 1000000000; + double bestpar0=1; + double bestpar1=0.001; + int better, i; + + srandom(123); + for(i=0; i<SAMPLES; i++){ + ideal[i] = 10 + i + n1*i/(1000); + samples[i]= ideal[i] + n0*(rand()-RAND_MAX/2)/(RAND_MAX*10LL); + } + + do{ + double par0, par1; + better=0; + for(par0= bestpar0*0.8; par0<=bestpar0*1.21; par0+=bestpar0*0.05){ + for(par1= bestpar1*0.8; par1<=bestpar1*1.21; par1+=bestpar1*0.05){ + double error=0; + TimeFilter *tf= ff_timefilter_new(par0, par1); + for(i=0; i<SAMPLES; i++){ + double filtered; + filtered= ff_timefilter_update(tf, samples[i], 1); + error += (filtered - ideal[i]) * (filtered - ideal[i]); + } + ff_timefilter_destroy(tf); + if(error < best_error){ + best_error= error; + bestpar0= par0; + bestpar1= par1; + better=1; + } + } + } + }while(better); + printf(" [%f %f %f]", bestpar0, bestpar1, best_error); + } + printf("\n"); + } +} +#endif |