Incremental update
[platform/upstream/libvorbis.git] / lib / window.c
1 /********************************************************************
2  *                                                                  *
3  * THIS FILE IS PART OF THE Ogg Vorbis SOFTWARE CODEC SOURCE CODE.  *
4  * USE, DISTRIBUTION AND REPRODUCTION OF THIS SOURCE IS GOVERNED BY *
5  * THE GNU PUBLIC LICENSE 2, WHICH IS INCLUDED WITH THIS SOURCE.    *
6  * PLEASE READ THESE TERMS DISTRIBUTING.                            *
7  *                                                                  *
8  * THE OggSQUISH SOURCE CODE IS (C) COPYRIGHT 1994-2000             *
9  * by Monty <monty@xiph.org> and The XIPHOPHORUS Company            *
10  * http://www.xiph.org/                                             *
11  *                                                                  *
12  ********************************************************************
13
14  function: window functions
15  last mod: $Id: window.c,v 1.6 2000/02/06 13:39:48 xiphmont Exp $
16
17  ********************************************************************/
18
19 #include <stdlib.h>
20 #include <math.h>
21 #include "os.h"
22
23 double *_vorbis_window(int type, int window,int left,int right){
24   double *ret=calloc(window,sizeof(double));
25
26   switch(type){
27   case 0:
28     /* The 'vorbis window' (window 0) is sin(sin(x)*sin(x)*2pi) */
29     {
30       int leftbegin=window/4-left/2;
31       int rightbegin=window-window/4-right/2;
32       int i;
33     
34       for(i=0;i<left;i++){
35         double x=(i+.5)/left*M_PI/2.;
36         x=sin(x);
37         x*=x;
38         x*=M_PI/2.;
39         x=sin(x);
40         ret[i+leftbegin]=x;
41       }
42       
43       for(i=leftbegin+left;i<rightbegin;i++)
44         ret[i]=1.;
45       
46       for(i=0;i<right;i++){
47         double x=(right-i-.5)/right*M_PI/2.;
48         x=sin(x);
49         x*=x;
50         x*=M_PI/2.;
51         x=sin(x);
52         ret[i+rightbegin]=x;
53       }
54     }
55     break;
56   default:
57     free(ret);
58     return(NULL);
59   }
60   return(ret);
61 }
62