[FFmpeg-soc] [soc]: r2945 - nellyenc/nellymoserenc.c

Michael Niedermayer michaelni at gmx.at
Thu Jul 31 03:43:42 CEST 2008


On Wed, Jul 30, 2008 at 11:06:37PM +0200, bwolowiec wrote:
> Author: bwolowiec
> Date: Wed Jul 30 23:06:37 2008
> New Revision: 2945
> 
> Log:
> precalculate most used pow() values
> 
> 
> Modified:
>    nellyenc/nellymoserenc.c
> 
> Modified: nellyenc/nellymoserenc.c
> ==============================================================================
> --- nellyenc/nellymoserenc.c	(original)
> +++ nellyenc/nellymoserenc.c	Wed Jul 30 23:06:37 2008
> @@ -24,6 +24,7 @@
>  #include "avcodec.h"
>  #include "dsputil.h"
>  
> +#define MAX_POW_CACHED (1<<15)
>  
>  /*
>   * FIXME: Bitstream from vorbis_enc.c (move to seperate file?)
> @@ -81,6 +82,7 @@ typedef struct NellyMoserEncodeContext {
>      DSPContext      dsp;
>      MDCTContext     mdct_ctx;
>      float pows[NELLY_FILL_LEN];
> +    float pow_table[MAX_POW_CACHED];

please dont put arrays of constants in the context, they would be duplicated
that way for every instance of the encoder.


>      DECLARE_ALIGNED_16(float,mdct_tmp[NELLY_BUF_LEN*2]);
>      DECLARE_ALIGNED_16(float,mdct_out[NELLY_BUF_LEN*2]);
>  } NellyMoserEncodeContext;
> @@ -123,6 +125,8 @@ static av_cold int encode_init(AVCodecCo
>              sine_window[255-i] = sine_window[i];
>          }
>      }
> +    for(i=0; i<MAX_POW_CACHED; i++)
> +        s->pow_table[i] = -pow(2, -i/2048.0 - 3.0);
>  
>      s->bufsize = 0;
>      return 0;
> @@ -203,7 +207,11 @@ static void encode_block(NellyMoserEncod
>              val = ff_nelly_init_table[bk];
>          }
>  
> -        pval = -pow(2, -val/2048.0 - 3.0);
> +        if(val >= 0 && val < MAX_POW_CACHED){
> +            pval = s->pow_table[val];
> +        }else{
> +            pval = -pow(2, -val/2048.0 - 3.0);
> +        }

you only need a table of 2048 entries
pow(2, x/2048 + y) == pow(2, x/2048)*pow(2, y) and pow(2, y) is 
1,2,4,8 ... aka a shift
above x contains the 0.0 ... 1.0 part and y the integer part

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

Breaking DRM is a little like attempting to break through a door even
though the window is wide open and the only thing in the house is a bunch
of things you dont want and which you would get tomorrow for free anyway
-------------- 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-soc/attachments/20080731/e1a18d72/attachment.pgp>


More information about the FFmpeg-soc mailing list