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

Michael Niedermayer michaelni
Tue Aug 12 19:33:43 CEST 2008


On Tue, Aug 12, 2008 at 08:11:49PM +0300, Kostya wrote:
> On Tue, Aug 12, 2008 at 07:58:19PM +0300, Kostya wrote:
> [...]
> 
> oops, attached an old version of files, here're new ones

[...]
> /** filter order */
> #define LOWPASS_FILTER_ORDER 4
> 
> /**
>  * IIR filter global parameters
>  */
> typedef struct LPFilterCoeffs{
>     float gain;
>     float c[LOWPASS_FILTER_ORDER];
> }LPFilterCoeffs;
> 
> /**
>  * IIR filter state
>  */
> typedef struct LPFilterState{
>     int   pos;
>     float x[LOWPASS_FILTER_ORDER];
>     float y[LOWPASS_FILTER_ORDER];
> }LPFilterState;

I think these things could be moved to the c file


> 
> /**
>  * Initialize filter coefficients.
>  *
>  * @param order  filter order
>  * @param coeffs filter coefficients
>  * @param freq   input frequency (sample rate/2)
>  * @param cutoff cutoff frequency
>  *
>  * @return zero if filter creation succeeded, a negative value if filter could not be created
>  */
> int ff_lowpass_filter_init_coeffs(int order, LPFilterCoeffs *coeffs, int freq, int cutoff);
> 

> /**
>  * Filter input value.
>  *
>  * @param coeffs filter coefficients
>  * @param s      filter state
>  * @param in     input value
>  *
>  * @return filtered value
>  */
> static av_always_inline float ff_lowpass_filter(LPFilterCoeffs *coeffs, LPFilterState *s, float in)
> {
>     int i;
>     float res;
>     
>     in *= coeffs->gain;
>     //FIXME: made only for 4th order filter
>     res = (s->x[s->pos&3] + in)*1 + (s->x[(s->pos+1)&3] + s->x[(s->pos+3)&3])*4 +  s->x[(s->pos+2)&3]*6;
>     for(i = 0; i < 4; i++)
>         res += coeffs->c[i] * s->y[(s->pos + i)&3];
>     s->x[s->pos&3] = in;
>     s->y[s->pos&3] = res;
>     s->pos++;
>     return res;
> }

i suspect this would be even slower than the moving of samples.
does gcc optimize the &3 stuff away? if not you will have to unroll it
by hand like i suggested, if OTOH gcc does optimize it away then its fine.
and with unroll i mean a function that works with 4 samples at a time.


[...]
> int ff_lowpass_filter_init_coeffs(int order, LPFilterCoeffs *coeffs, int freq, int cutoff)
> {
>     int i, j, size;
>     float cutoff_ratio;
> 
>     //since I'm too lazy to calculate coefficients, I take more or less matching ones from the table
>     //TODO: generic version
>     size = sizeof(lp_filter_data) / sizeof(lp_filter_data[0]);
>     cutoff_ratio = (float)cutoff / freq;
>     if(cutoff_ratio > lp_filter_data[0][0])
>         return -1;
>     for(i = 0; i < size; i++){
>         if(cutoff_ratio >= lp_filter_data[i][0])
>             break;
>     }
>     if(i == size)
>         i = size - 1;
>     coeffs->gain     = lp_filter_data[i][1];

>     for(j = 0; j < 4; j++)
>         coeffs->c[j] = lp_filter_data[i][j+2];

memcpy

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

I wish the Xiph folks would stop pretending they've got something they
do not.  Somehow I fear this will remain a wish. -- M?ns Rullg?rd
-------------- 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/20080812/b368eccd/attachment.pgp>



More information about the ffmpeg-devel mailing list