[Tremor] runtime-generated lookup tables

Nicolas Pitre nico at cam.org
Wed Mar 8 18:56:12 PST 2006


On Wed, 8 Mar 2006, Oliver Lange wrote:

> > If you look into libvorbis you'll find the code to create those tables since
> > libvorbis initializes those tables dynamically.  Just add the appropriate
> > scalling for the fixed point value (make sure not to overflow) and there you
> > go.
> > 
> 
> Hmmm i only got libvorbis-1.1.2, where the window tables are
> pre-defined in lib/window.c. I was searching for "vwin" through
> the whole project (all and every file) but found no reference
> except for the code which applies from the computed table.
> Must be an older libvorbis version ? Or the computing function
> is putting the results to somewhere else than "vwin" ?

It was present in an old version (svn revision 1120).  The code was:

float *_vorbis_window(int type, int window,int left,int right){
  float *ret=_ogg_calloc(window,sizeof(float));

  switch(type){
  case 0:
    /* The 'vorbis window' (window 0) is sin(sin(x)*sin(x)*2pi) */
    {
      int leftbegin=window/4-left/2;
      int rightbegin=window-window/4-right/2;
      int i;

      for(i=0;i<left;i++){
        float x=(i+.5)/left*M_PI/2.;
        x=sin(x);
        x*=x;
        x*=M_PI/2.;
        x=sin(x);
        ret[i+leftbegin]=x;
      }

      for(i=leftbegin+left;i<rightbegin;i++)
        ret[i]=1.;

      for(i=0;i<right;i++){
        float x=(right-i-.5)/right*M_PI/2.;
        x=sin(x);
        x*=x;
        x*=M_PI/2.;
        x=sin(x);
        ret[i+rightbegin]=x;
      }
    }
    break;
  default:
    _ogg_free(ret);
    return(NULL);
  }
  return(ret);
}


Nicolas


More information about the Tremor mailing list