misc/tremor/window.c
branchhedgeroid
changeset 6045 9a7cc0f29430
parent 6043 9bd2d6b1ba52
child 6047 10011f051f9c
equal deleted inserted replaced
6043:9bd2d6b1ba52 6045:9a7cc0f29430
     1 /********************************************************************
       
     2  *                                                                  *
       
     3  * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE.   *
       
     4  *                                                                  *
       
     5  * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS     *
       
     6  * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
       
     7  * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING.       *
       
     8  *                                                                  *
       
     9  * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002    *
       
    10  * BY THE Xiph.Org FOUNDATION http://www.xiph.org/                  *
       
    11  *                                                                  *
       
    12  ********************************************************************
       
    13 
       
    14  function: window functions
       
    15 
       
    16  ********************************************************************/
       
    17 
       
    18 #include <stdlib.h>
       
    19 #include <math.h>
       
    20 #include "misc.h"
       
    21 #include "window.h"
       
    22 #include "window_lookup.h"
       
    23 
       
    24 const void *_vorbis_window(int type, int left){
       
    25 
       
    26   switch(type){
       
    27   case 0:
       
    28 
       
    29     switch(left){
       
    30     case 32:
       
    31       return vwin64;
       
    32     case 64:
       
    33       return vwin128;
       
    34     case 128:
       
    35       return vwin256;
       
    36     case 256:
       
    37       return vwin512;
       
    38     case 512:
       
    39       return vwin1024;
       
    40     case 1024:
       
    41       return vwin2048;
       
    42     case 2048:
       
    43       return vwin4096;
       
    44     case 4096:
       
    45       return vwin8192;
       
    46     default:
       
    47       return(0);
       
    48     }
       
    49     break;
       
    50   default:
       
    51     return(0);
       
    52   }
       
    53 }
       
    54 
       
    55 void _vorbis_apply_window(ogg_int32_t *d,const void *window_p[2],
       
    56 			  long *blocksizes,
       
    57 			  int lW,int W,int nW){
       
    58   
       
    59   LOOKUP_T *window[2]={window_p[0],window_p[1]};
       
    60   long n=blocksizes[W];
       
    61   long ln=blocksizes[lW];
       
    62   long rn=blocksizes[nW];
       
    63 
       
    64   long leftbegin=n/4-ln/4;
       
    65   long leftend=leftbegin+ln/2;
       
    66 
       
    67   long rightbegin=n/2+n/4-rn/4;
       
    68   long rightend=rightbegin+rn/2;
       
    69   
       
    70   int i,p;
       
    71 
       
    72   for(i=0;i<leftbegin;i++)
       
    73     d[i]=0;
       
    74 
       
    75   for(p=0;i<leftend;i++,p++)
       
    76     d[i]=MULT31(d[i],window[lW][p]);
       
    77 
       
    78   for(i=rightbegin,p=rn/2-1;i<rightend;i++,p--)
       
    79     d[i]=MULT31(d[i],window[nW][p]);
       
    80 
       
    81   for(;i<n;i++)
       
    82     d[i]=0;
       
    83 }