Minor changes to compile cleanly with MSVC++
[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-1999             *
9  * by 1999 Monty <monty@xiph.org> and The XIPHOPHORUS Company       *
10  * http://www.xiph.org/                                             *
11  *                                                                  *
12  ********************************************************************
13
14  function: window functions
15  author: Monty <xiphmont@mit.edu>
16  modifications by: Monty
17  last modification date: Nov 16 1999
18
19  ********************************************************************/
20
21 #include <stdlib.h>
22 #include <math.h>
23 #include "os.h"
24
25 /* The 'vorbis window' is sin(sin(x)*sin(x)*2pi) */
26
27 double *_vorbis_window(int window,int left,int right){
28   double *ret=calloc(window,sizeof(double));
29   int leftbegin=window/4-left/2;
30   int rightbegin=window-window/4-right/2;
31   int i;
32   
33   for(i=0;i<left;i++){
34     double x=(i+.5)/left*M_PI/2.;
35     x=sin(x);
36     x*=x;
37     x*=M_PI/2.;
38     x=sin(x);
39     ret[i+leftbegin]=x;
40   }
41
42   for(i=leftbegin+left;i<rightbegin;i++)
43     ret[i]=1.;
44
45   for(i=0;i<right;i++){
46     double x=(right-i-.5)/right*M_PI/2.;
47     x=sin(x);
48     x*=x;
49     x*=M_PI/2.;
50     x=sin(x);
51     ret[i+rightbegin]=x;
52   }
53
54   return(ret);
55 }
56