1 /********************************************************************
3 * THIS FILE IS PART OF THE OggGhost SOFTWARE CODEC SOURCE CODE. *
4 * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
5 * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
6 * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
8 * THE OggGhost SOURCE CODE IS (C) COPYRIGHT 2007-2011 *
9 * by the Xiph.Org Foundation http://www.xiph.org/ *
11 ********************************************************************
13 function: window functions for research code
16 ********************************************************************/
25 static void rectangle(float *x
, int n
){
32 static void sine(float *x
, int n
){
42 /* Minimum 4-term Blackman Harris; highest sidelobe = -92dB */
48 static void blackmann_harris(float *x
, int n
){
50 float scale
= 2*M_PI
/n
;
54 float w
= A0
- A1
*cos(scale
*i5
) + A2
*cos(scale
*i5
*2) - A3
*cos(scale
*i5
*3);
59 /* Good 'ol Hanning window (narrow mainlobe, fast falloff, high sidelobes) */
60 static void hanning(float *x
, int n
){
62 float scale
= 2*M_PI
/n
;
66 x
[i
] = (.5-.5*cos(scale
*i5
));
70 /* Triangular * gaussian (sidelobeless window) */
73 static void tgauss_deep(float *x
, int n
){
76 float f
= (i
+.5-n
/2.)/(n
/2.);
77 x
[i
] = exp(-TGB
*pow(f
,2)) * pow(1.-fabs(f
),TGA
);
81 static void vorbis(float *d
, int n
){
84 d
[i
] = sin(0.5 * M_PI
* sin((i
+.5)/n
* M_PI
)*sin((i
+.5)/n
* M_PI
));
87 static float beta(int n
, float alpha
){
88 return cosh (acosh(pow(10,alpha
))/(n
-1));
91 static double T(double n
, double x
){
93 return cos(n
*acos(x
));
95 return cosh(n
*acosh(x
));
99 /* Dolph-Chebyshev window (a=6., all sidelobes < -120dB) */
100 static void dolphcheb(float *d
, int n
){
105 double b
= beta(N
,a
);
110 sum
+= (k
&1?-1:1)*T(N
,b
*cos(M_PI
*k
/N
)) * cos (2*i
*k
*M_PI
/N
);
117 /* sidelobeless window machine optimized for fast convergence */
118 static void maxwell1(float *x
, int n
){
120 float scale
= 2*M_PI
/n
;
123 x
[i
] = pow( 119.72981
124 - 119.24098*cos(scale
*i5
)
125 + 0.10283622*cos(2*scale
*i5
)
126 + 0.044013144*cos(3*scale
*i5
)
127 + 0.97203713*cos(4*scale
*i5
),
132 window_bundle window_functions
= {