[FFmpeg-devel] [PATCH] Lowpass functionality for lavc

Kostya kostya.shishkov
Thu Aug 14 18:16:16 CEST 2008


On Thu, Aug 14, 2008 at 04:40:27PM +0200, Michael Niedermayer wrote:
[...]
> > 
> > /**
> >  * Create new filter state.
> >  *
> >  * @param order filter order
> >  *
> >  * @return pointer to new filter state or NULL if state creation fails
> >  */
> > void* ff_lowpass_filter_init_state(int order);
> 
> state and filter coefficients structure? why 2?
> especially with void this is a recipe for confusion

I'm not a filter expert but from what I know:
IIR filter takes input x[i] and produces y[n] = SUM[i=0..N-1] Cy[i]*y[n-i] + SUM[i=0..M-1] Cx[i]*x[n-i]

Now let's filter two channels, for example.
Since each channel is a separate input, we have to store its
coefficients and filtered values separately. I do that in FilterState.

Filter coefficients, on the other hand, are constant for the
given filter, so storing them in each state is an overkill
since it doubles state size (I use precalculated Cx[] values, so it's
only 1.5x times now).

[...] 
> > 
> > void ff_lowpass_filter(void *coeffs, void *state, int size, int16_t *src, int sstep, int16_t *dst, int dstep)
> > {
> >     int i, j;
> >     float in, res;
> >     LPFilterCoeffs *c = (LPFilterCoeffs*)coeffs;
> >     LPFilterState  *s = (LPFilterState*) state;
> > 
> >     for(i = 0; i < size; i++, src += sstep, dst += dstep){ 
> >         for(j = 0; j < LOWPASS_FILTER_ORDER - 1; j++){
> >             s->x[j] = s->x[j+1];
> >             s->y[j] = s->y[j+1];
> >         }
> 
> luckily iam in good mood
> please unroll the loop and remove this
> 
> its supposed to look something like
> 
> #define FILTER(a,b,c,d, src)
>     s->x[a]=  *src++ * c->gain;
>     s->y[a]=  s->x[a] + 123*s->y[a] + 321*s->y[b] + ...
>     *dst++= av_clip_int16(s->y[a]);
> 
> FILTER(0,1,2,3)
> FILTER(1,2,3,0)
> FILTER(2,3,0,1)
> FILTER(3,0,1,2)

Thank you for this example, will comply. 

> [...]
> -- 
> Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
> 
> The misfortune of the wise is better than the prosperity of the fool.
> -- Epicurus




More information about the ffmpeg-devel mailing list