annotate libaf/window.c @ 34325:fc74085e2487

Fix bug in Win32 GUI introduced in r34403. When selecting a file to open in the open dialog, the open dialog just reappears. handlemsg() passes unknown messages (such as evDropFile) to the gui's playercontrol function (guiSetEvent()). We cannot replace the handlemsg(hWnd, evDropFile) call by handlemsg(hWnd, evLoadPlay), because evLoadPlay is known in handlemsg() and has a different meaning there. So we directly call gui->playercontrol(evLoadPlay) instead where evDropFile and evLoadPlay have the same meaning. Reported by Stephen Sheldon, sfsheldo gmail com.
author ib
date Thu, 08 Dec 2011 19:41:28 +0000
parents 32725ca88fed
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
28229
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 26759
diff changeset
1 /*
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 26759
diff changeset
2 * Copyright (C) 2001 Anders Johansson ajh@atri.curtin.edu.au
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 26759
diff changeset
3 *
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 26759
diff changeset
4 * This file is part of MPlayer.
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 26759
diff changeset
5 *
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 26759
diff changeset
6 * MPlayer is free software; you can redistribute it and/or modify
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 26759
diff changeset
7 * it under the terms of the GNU General Public License as published by
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 26759
diff changeset
8 * the Free Software Foundation; either version 2 of the License, or
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 26759
diff changeset
9 * (at your option) any later version.
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 26759
diff changeset
10 *
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 26759
diff changeset
11 * MPlayer is distributed in the hope that it will be useful,
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 26759
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 26759
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 26759
diff changeset
14 * GNU General Public License for more details.
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 26759
diff changeset
15 *
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 26759
diff changeset
16 * You should have received a copy of the GNU General Public License along
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 26759
diff changeset
17 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 26759
diff changeset
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 26759
diff changeset
19 */
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
20
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
21 /* Calculates a number of window functions. The following window
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
22 functions are currently implemented: Boxcar, Triang, Hanning,
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
23 Hamming, Blackman, Flattop and Kaiser. In the function call n is
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
24 the number of filter taps and w the buffer in which the filter
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
25 coefficients will be stored.
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
26 */
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
27
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
28 #include <math.h>
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
29 #include "dsp.h"
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
30
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
31 /*
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
32 // Boxcar
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
33 //
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
34 // n window length
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
35 // w buffer for the window parameters
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
36 */
26350
07abe94a9cc4 Fix illegal identifier: Rename _ftype_t macro to FLOAT_TYPE.
diego
parents: 14274
diff changeset
37 void af_window_boxcar(int n, FLOAT_TYPE* w)
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
38 {
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
39 int i;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
40 // Calculate window coefficients
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
41 for (i=0 ; i<n ; i++)
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
42 w[i] = 1.0;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
43 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
44
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
45
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
46 /*
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
47 // Triang a.k.a Bartlett
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
48 //
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28229
diff changeset
49 // | (N-1)|
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
50 // 2 * |k - -----|
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
51 // | 2 |
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
52 // w = 1.0 - ---------------
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
53 // N+1
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
54 // n window length
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
55 // w buffer for the window parameters
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
56 */
26350
07abe94a9cc4 Fix illegal identifier: Rename _ftype_t macro to FLOAT_TYPE.
diego
parents: 14274
diff changeset
57 void af_window_triang(int n, FLOAT_TYPE* w)
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
58 {
26350
07abe94a9cc4 Fix illegal identifier: Rename _ftype_t macro to FLOAT_TYPE.
diego
parents: 14274
diff changeset
59 FLOAT_TYPE k1 = (FLOAT_TYPE)(n & 1);
07abe94a9cc4 Fix illegal identifier: Rename _ftype_t macro to FLOAT_TYPE.
diego
parents: 14274
diff changeset
60 FLOAT_TYPE k2 = 1/((FLOAT_TYPE)n + k1);
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
61 int end = (n + 1) >> 1;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
62 int i;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28229
diff changeset
63
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
64 // Calculate window coefficients
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
65 for (i=0 ; i<end ; i++)
26350
07abe94a9cc4 Fix illegal identifier: Rename _ftype_t macro to FLOAT_TYPE.
diego
parents: 14274
diff changeset
66 w[i] = w[n-i-1] = (2.0*((FLOAT_TYPE)(i+1))-(1.0-k1))*k2;
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
67 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
68
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
69
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
70 /*
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
71 // Hanning
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
72 // 2*pi*k
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
73 // w = 0.5 - 0.5*cos(------), where 0 < k <= N
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
74 // N+1
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
75 // n window length
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
76 // w buffer for the window parameters
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
77 */
26350
07abe94a9cc4 Fix illegal identifier: Rename _ftype_t macro to FLOAT_TYPE.
diego
parents: 14274
diff changeset
78 void af_window_hanning(int n, FLOAT_TYPE* w)
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
79 {
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
80 int i;
26350
07abe94a9cc4 Fix illegal identifier: Rename _ftype_t macro to FLOAT_TYPE.
diego
parents: 14274
diff changeset
81 FLOAT_TYPE k = 2*M_PI/((FLOAT_TYPE)(n+1)); // 2*pi/(N+1)
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28229
diff changeset
82
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
83 // Calculate window coefficients
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
84 for (i=0; i<n; i++)
26350
07abe94a9cc4 Fix illegal identifier: Rename _ftype_t macro to FLOAT_TYPE.
diego
parents: 14274
diff changeset
85 *w++ = 0.5*(1.0 - cos(k*(FLOAT_TYPE)(i+1)));
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
86 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
87
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
88 /*
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
89 // Hamming
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
90 // 2*pi*k
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
91 // w(k) = 0.54 - 0.46*cos(------), where 0 <= k < N
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
92 // N-1
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
93 //
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
94 // n window length
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
95 // w buffer for the window parameters
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
96 */
26350
07abe94a9cc4 Fix illegal identifier: Rename _ftype_t macro to FLOAT_TYPE.
diego
parents: 14274
diff changeset
97 void af_window_hamming(int n,FLOAT_TYPE* w)
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
98 {
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
99 int i;
26350
07abe94a9cc4 Fix illegal identifier: Rename _ftype_t macro to FLOAT_TYPE.
diego
parents: 14274
diff changeset
100 FLOAT_TYPE k = 2*M_PI/((FLOAT_TYPE)(n-1)); // 2*pi/(N-1)
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
101
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
102 // Calculate window coefficients
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
103 for (i=0; i<n; i++)
26350
07abe94a9cc4 Fix illegal identifier: Rename _ftype_t macro to FLOAT_TYPE.
diego
parents: 14274
diff changeset
104 *w++ = 0.54 - 0.46*cos(k*(FLOAT_TYPE)i);
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
105 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
106
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
107 /*
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
108 // Blackman
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
109 // 2*pi*k 4*pi*k
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
110 // w(k) = 0.42 - 0.5*cos(------) + 0.08*cos(------), where 0 <= k < N
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
111 // N-1 N-1
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
112 //
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
113 // n window length
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
114 // w buffer for the window parameters
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
115 */
26350
07abe94a9cc4 Fix illegal identifier: Rename _ftype_t macro to FLOAT_TYPE.
diego
parents: 14274
diff changeset
116 void af_window_blackman(int n,FLOAT_TYPE* w)
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
117 {
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
118 int i;
26350
07abe94a9cc4 Fix illegal identifier: Rename _ftype_t macro to FLOAT_TYPE.
diego
parents: 14274
diff changeset
119 FLOAT_TYPE k1 = 2*M_PI/((FLOAT_TYPE)(n-1)); // 2*pi/(N-1)
07abe94a9cc4 Fix illegal identifier: Rename _ftype_t macro to FLOAT_TYPE.
diego
parents: 14274
diff changeset
120 FLOAT_TYPE k2 = 2*k1; // 4*pi/(N-1)
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
121
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
122 // Calculate window coefficients
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
123 for (i=0; i<n; i++)
26350
07abe94a9cc4 Fix illegal identifier: Rename _ftype_t macro to FLOAT_TYPE.
diego
parents: 14274
diff changeset
124 *w++ = 0.42 - 0.50*cos(k1*(FLOAT_TYPE)i) + 0.08*cos(k2*(FLOAT_TYPE)i);
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
125 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
126
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
127 /*
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
128 // Flattop
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
129 // 2*pi*k 4*pi*k
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
130 // w(k) = 0.2810638602 - 0.5208971735*cos(------) + 0.1980389663*cos(------), where 0 <= k < N
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
131 // N-1 N-1
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
132 //
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
133 // n window length
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
134 // w buffer for the window parameters
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
135 */
26350
07abe94a9cc4 Fix illegal identifier: Rename _ftype_t macro to FLOAT_TYPE.
diego
parents: 14274
diff changeset
136 void af_window_flattop(int n,FLOAT_TYPE* w)
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
137 {
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
138 int i;
26350
07abe94a9cc4 Fix illegal identifier: Rename _ftype_t macro to FLOAT_TYPE.
diego
parents: 14274
diff changeset
139 FLOAT_TYPE k1 = 2*M_PI/((FLOAT_TYPE)(n-1)); // 2*pi/(N-1)
07abe94a9cc4 Fix illegal identifier: Rename _ftype_t macro to FLOAT_TYPE.
diego
parents: 14274
diff changeset
140 FLOAT_TYPE k2 = 2*k1; // 4*pi/(N-1)
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28229
diff changeset
141
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
142 // Calculate window coefficients
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
143 for (i=0; i<n; i++)
26350
07abe94a9cc4 Fix illegal identifier: Rename _ftype_t macro to FLOAT_TYPE.
diego
parents: 14274
diff changeset
144 *w++ = 0.2810638602 - 0.5208971735*cos(k1*(FLOAT_TYPE)i)
07abe94a9cc4 Fix illegal identifier: Rename _ftype_t macro to FLOAT_TYPE.
diego
parents: 14274
diff changeset
145 + 0.1980389663*cos(k2*(FLOAT_TYPE)i);
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
146 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
147
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28229
diff changeset
148 /* Computes the 0th order modified Bessel function of the first kind.
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28229
diff changeset
149 // (Needed to compute Kaiser window)
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28229
diff changeset
150 //
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
151 // y = sum( (x/(2*n))^2 )
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
152 // n
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
153 */
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28229
diff changeset
154 #define BIZ_EPSILON 1E-21 // Max error acceptable
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
155
26350
07abe94a9cc4 Fix illegal identifier: Rename _ftype_t macro to FLOAT_TYPE.
diego
parents: 14274
diff changeset
156 static FLOAT_TYPE besselizero(FLOAT_TYPE x)
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28229
diff changeset
157 {
26350
07abe94a9cc4 Fix illegal identifier: Rename _ftype_t macro to FLOAT_TYPE.
diego
parents: 14274
diff changeset
158 FLOAT_TYPE temp;
07abe94a9cc4 Fix illegal identifier: Rename _ftype_t macro to FLOAT_TYPE.
diego
parents: 14274
diff changeset
159 FLOAT_TYPE sum = 1.0;
07abe94a9cc4 Fix illegal identifier: Rename _ftype_t macro to FLOAT_TYPE.
diego
parents: 14274
diff changeset
160 FLOAT_TYPE u = 1.0;
07abe94a9cc4 Fix illegal identifier: Rename _ftype_t macro to FLOAT_TYPE.
diego
parents: 14274
diff changeset
161 FLOAT_TYPE halfx = x/2.0;
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
162 int n = 1;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
163
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
164 do {
26350
07abe94a9cc4 Fix illegal identifier: Rename _ftype_t macro to FLOAT_TYPE.
diego
parents: 14274
diff changeset
165 temp = halfx/(FLOAT_TYPE)n;
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
166 u *=temp * temp;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
167 sum += u;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
168 n++;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
169 } while (u >= BIZ_EPSILON * sum);
26759
8eff880f638c cosmetics: Remove useless parentheses from return statements.
diego
parents: 26350
diff changeset
170 return sum;
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
171 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
172
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
173 /*
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
174 // Kaiser
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
175 //
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
176 // n window length
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
177 // w buffer for the window parameters
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
178 // b beta parameter of Kaiser window, Beta >= 1
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
179 //
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
180 // Beta trades the rejection of the low pass filter against the
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
181 // transition width from passband to stop band. Larger Beta means a
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
182 // slower transition and greater stop band rejection. See Rabiner and
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
183 // Gold (Theory and Application of DSP) under Kaiser windows for more
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
184 // about Beta. The following table from Rabiner and Gold gives some
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
185 // feel for the effect of Beta:
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28229
diff changeset
186 //
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
187 // All ripples in dB, width of transition band = D*N where N = window
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
188 // length
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28229
diff changeset
189 //
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
190 // BETA D PB RIP SB RIP
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
191 // 2.120 1.50 +-0.27 -30
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
192 // 3.384 2.23 0.0864 -40
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
193 // 4.538 2.93 0.0274 -50
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
194 // 5.658 3.62 0.00868 -60
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
195 // 6.764 4.32 0.00275 -70
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
196 // 7.865 5.0 0.000868 -80
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
197 // 8.960 5.7 0.000275 -90
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
198 // 10.056 6.4 0.000087 -100
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
199 */
26350
07abe94a9cc4 Fix illegal identifier: Rename _ftype_t macro to FLOAT_TYPE.
diego
parents: 14274
diff changeset
200 void af_window_kaiser(int n, FLOAT_TYPE* w, FLOAT_TYPE b)
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
201 {
26350
07abe94a9cc4 Fix illegal identifier: Rename _ftype_t macro to FLOAT_TYPE.
diego
parents: 14274
diff changeset
202 FLOAT_TYPE tmp;
07abe94a9cc4 Fix illegal identifier: Rename _ftype_t macro to FLOAT_TYPE.
diego
parents: 14274
diff changeset
203 FLOAT_TYPE k1 = 1.0/besselizero(b);
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
204 int k2 = 1 - (n & 1);
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
205 int end = (n + 1) >> 1;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28229
diff changeset
206 int i;
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28229
diff changeset
207
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
208 // Calculate window coefficients
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
209 for (i=0 ; i<end ; i++){
26350
07abe94a9cc4 Fix illegal identifier: Rename _ftype_t macro to FLOAT_TYPE.
diego
parents: 14274
diff changeset
210 tmp = (FLOAT_TYPE)(2*i + k2) / ((FLOAT_TYPE)n - 1.0);
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
211 w[end-(1&(!k2))+i] = w[end-1-i] = k1 * besselizero(b*sqrt(1.0 - tmp*tmp));
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
212 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
213 }