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

Michael Niedermayer michaelni
Thu Aug 14 19:44:04 CEST 2008


On Thu, Aug 14, 2008 at 07:16:16PM +0300, Kostya wrote:
> 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).

good, you convinced me. but make it something "less void"


> 
> [...] 
> > > 
> > > 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. 

sorry for not being clear when i first (tried) to suggest it, i thought
its the obvious way to avoid the memmove

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

Thouse who are best at talking, realize last or never when they are wrong.
-------------- 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/20080814/1005db72/attachment.pgp>



More information about the ffmpeg-devel mailing list