[FFmpeg-devel] [Jack-Devel] [PATCH] libavdevice: JACK demuxer

Michael Niedermayer michaelni
Thu Mar 5 03:02:14 CET 2009


On Wed, Mar 04, 2009 at 09:31:44PM +0100, Fons Adriaensen wrote:
> On Wed, Mar 04, 2009 at 05:06:08PM +0100, Michael Niedermayer wrote:
> 
> > well, the filter will take the first system time it gets as its
> > best estimate
> 
> there's no alternative at that time

this is not strictly true, though it certainly is not what i meant but
there very well can be a systematic error so that the first time + 5ms
might be better as a hyphothetical example.
What i meant was that following the first time things behave somehow
"asymetrically" giving the first time a much higher effective weight ...


> 
> > and then "add" future times slowly into this to
> > compensate. That is it weights the first sample
> > very differently than the following ones, this is
> > clearly not optimal.
> 
> What makes you think that ?

common sense


> 
> > or in other words the noisyness or call it accuracy of its internal state
> > will be very poor after the first sampele while after a hundread it will
> > be better.
> 
> Which is what matters. 

yes but it would converge quicker where the factor not fixed


> 
> > The filter though will add samples in IIR fashion while ignoring
> > this
> 
> It's called exponential averaging, which means recent
> samples have more weight than older ones. Without that
> a system can't be adaptive.

that isnt true, one can design a non exponential filter that is
adaptive as well.

heres a simple example with the recently posted timefilter patch
code below will simulate random uncorrelated jitter and a samplerate
error, it will find the best values for both parameters using a really
lame search.
if you enable the code under ALTERNATIVE it will adapt the first factor
in a very primitive way that likely isnt optimal either but beats
the simple constant case

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.00001;
            int better, i;

            srandom(123);
            for(i=0; i<SAMPLES; i++){
                ideal[i]  = 10 + i + n1*i/(10*10);
                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(1, par0, par1);
                        for(i=0; i<SAMPLES; i++){
                            double filtered;
#if ALTERNATIVE
tf->feedback2_factor= FFMAX(par0, 1.0/(i+1));
#endif
                            ff_timefilter_update(tf, samples[i]);
                            filtered= ff_timefilter_read(tf);
                            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");
    }
}

results of this are
 [0.800000 0.000008 0.000000] [2.021560 1.006953 0.000100] [2.021560 1.006953 0.000901] [2.021560 1.006953 0.004903]
 [0.052227 0.000000 0.040452] [0.149737 0.009816 0.143180] [0.275251 0.027830 0.269643] [0.409600 0.061186 0.444376]
 [0.052227 0.000000 0.364068] [0.085899 0.003979 0.719558] [0.149737 0.009816 1.288622] [0.233964 0.021402 2.096296]
 [0.052227 0.000000 1.982147] [0.061332 0.002239 2.795419] [0.094704 0.004949 4.427345] [0.149737 0.009816 7.015830]
 [0.052227 0.000000 9.101697] [0.051952 0.001481 10.538358] [0.068719 0.002750 14.464223] [0.101469 0.005209 21.232117]
 [0.052227 0.000000 38.874358] [0.048488 0.001091 40.524498] [0.054976 0.001810 48.958747] [0.072155 0.003031 64.794577]

ALTERNATIVE:
 [0.800000 0.000008 0.000000] [2.021560 1.006953 0.000100] [2.021560 1.006953 0.000901] [2.021560 1.006953 0.004903]
 [0.001144 0.000001 0.010675] [0.134218 0.009644 0.131673] [0.261489 0.026504 0.261801] [0.389120 0.061033 0.440048]
 [0.001144 0.000001 0.096077] [0.057724 0.003997 0.572458] [0.134218 0.009644 1.185061] [0.220201 0.021150 2.017409]
 [0.001144 0.000001 0.523088] [0.035184 0.002340 1.930126] [0.068719 0.004759 3.683940] [0.134218 0.009644 6.451997]
 [0.001144 0.000001 2.401933] [0.029555 0.001397 6.646778] [0.041562 0.002893 10.444674] [0.075763 0.005290 17.908798]
 [0.001144 0.000001 10.258925] [0.024826 0.000836 22.467767] [0.033249 0.001882 32.411319] [0.041781 0.003046 47.771058]



[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Observe your enemies, for they first find out your faults. -- Antisthenes
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090305/eeb9a5d8/attachment.pgp>



More information about the ffmpeg-devel mailing list