Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
165 | serge | 1 | #include |
2 | |||
3 | /*------ 18 point xform -------*/ |
||
4 | static float w[18]; |
||
5 | static float w2[9]; |
||
6 | static float coef[9][4]; |
||
7 | |||
8 | static float v[6]; |
||
9 | static float v2[3]; |
||
10 | static float coef87; |
||
11 | /* |
||
12 | typedef struct |
||
13 | { |
||
14 | float *w; |
||
15 | float *w2; |
||
16 | void *coef; |
||
17 | } |
||
18 | IMDCT_INIT_BLOCK; |
||
19 | |||
20 | static IMDCT_INIT_BLOCK imdct_info_18 = |
||
21 | {w, w2, coef}; |
||
22 | static IMDCT_INIT_BLOCK imdct_info_6 = |
||
23 | {v, v2, &coef87}; |
||
24 | */ |
||
25 | /*=============================================================*/ |
||
26 | void imdct_init() |
||
27 | { |
||
28 | int k, p, n; |
||
29 | double t, pi; |
||
30 | // IMDCT_INIT_BLOCK *addr; |
||
31 | // float *w, *w2; |
||
32 | // float *v, *v2, *coef87; |
||
33 | |||
34 | /*--- 18 point --*/ |
||
35 | // addr = imdct_init_addr_18(); |
||
36 | // w = addr->w; |
||
37 | // w2 = addr->w2; |
||
38 | // coef = addr->coef; |
||
39 | /*----*/ |
||
40 | n = 18; |
||
41 | pi = 4.0 * atan(1.0); |
||
42 | t = pi / (4 * n); |
||
43 | for (p = 0; p < n; p++) |
||
44 | w[p] = (float) (2.0 * cos(t * (2 * p + 1))); |
||
45 | for (p = 0; p < 9; p++) |
||
46 | w2[p] = (float) (2.0 *cos(2 * t * (2 * p + 1))); |
||
47 | |||
48 | t = pi / (2 * n); |
||
49 | for (k = 0; k < 9; k++) |
||
50 | { |
||
51 | for (p = 0; p < 4; p++) |
||
52 | coef[k][p] = (float) (cos(t * (2 * k) * (2 * p + 1))); |
||
53 | } |
||
54 | |||
55 | /*--- 6 point */ |
||
56 | // addr = imdct_init_addr_6(); |
||
57 | // v = addr->w; |
||
58 | // v2 = addr->w2; |
||
59 | // coef87 = addr->coef; |
||
60 | /*----*/ |
||
61 | n = 6; |
||
62 | pi = 4.0 * atan(1.0); |
||
63 | t = pi / (4 * n); |
||
64 | for (p = 0; p < n; p++) |
||
65 | v[p] = (float) (2.0 *cos(t * (2 * p + 1))); |
||
66 | |||
67 | for (p = 0; p < 3; p++) |
||
68 | v2[p] = (float) (2.0 *cos(2 * t * (2 * p + 1))); |
||
69 | |||
70 | t = pi / (2 * n); |
||
71 | k = 1; |
||
72 | p = 0; |
||
73 | coef87 = (float) (cos(t * (2 * k) * (2 * p + 1))); |
||
74 | /* adjust scaling to save a few mults */ |
||
75 | for (p = 0; p < 6; p++) |
||
76 | v[p] = v[p] / 2.0f; |
||
77 | coef87 = (float) (2.0 * coef87); |
||
78 | } |
||
79 | /*--------------------------------------------------------------------*/ |
||
80 | void imdct18(float f[18]) /* 18 point */ |
||
81 | { |
||
82 | int p; |
||
83 | float a[9], b[9]; |
||
84 | float ap, bp, a8p, b8p; |
||
85 | float g1, g2; |
||
86 | |||
87 | |||
88 | for (p = 0; p < 4; p++) |
||
89 | { |
||
90 | g1 = w[p] * f[p]; |
||
91 | g2 = w[17 - p] * f[17 - p]; |
||
92 | ap = g1 + g2; // a[p] |
||
93 | |||
94 | bp = w2[p] * (g1 - g2); // b[p] |
||
95 | |||
96 | g1 = w[8 - p] * f[8 - p]; |
||
97 | g2 = w[9 + p] * f[9 + p]; |
||
98 | a8p = g1 + g2; // a[8-p] |
||
99 | |||
100 | b8p = w2[8 - p] * (g1 - g2); // b[8-p] |
||
101 | |||
102 | a[p] = ap + a8p; |
||
103 | a[5 + p] = ap - a8p; |
||
104 | b[p] = bp + b8p; |
||
105 | b[5 + p] = bp - b8p; |
||
106 | } |
||
107 | g1 = w[p] * f[p]; |
||
108 | g2 = w[17 - p] * f[17 - p]; |
||
109 | a[p] = g1 + g2; |
||
110 | b[p] = w2[p] * (g1 - g2); |
||
111 | |||
112 | |||
113 | f[0] = 0.5f * (a[0] + a[1] + a[2] + a[3] + a[4]); |
||
114 | f[1] = 0.5f * (b[0] + b[1] + b[2] + b[3] + b[4]); |
||
115 | |||
116 | f[2] = coef[1][0] * a[5] + coef[1][1] * a[6] + coef[1][2] * a[7] |
||
117 | + coef[1][3] * a[8]; |
||
118 | f[3] = coef[1][0] * b[5] + coef[1][1] * b[6] + coef[1][2] * b[7] |
||
119 | + coef[1][3] * b[8] - f[1]; |
||
120 | f[1] = f[1] - f[0]; |
||
121 | f[2] = f[2] - f[1]; |
||
122 | |||
123 | f[4] = coef[2][0] * a[0] + coef[2][1] * a[1] + coef[2][2] * a[2] |
||
124 | + coef[2][3] * a[3] - a[4]; |
||
125 | f[5] = coef[2][0] * b[0] + coef[2][1] * b[1] + coef[2][2] * b[2] |
||
126 | + coef[2][3] * b[3] - b[4] - f[3]; |
||
127 | f[3] = f[3] - f[2]; |
||
128 | f[4] = f[4] - f[3]; |
||
129 | |||
130 | f[6] = coef[3][0] * (a[5] - a[7] - a[8]); |
||
131 | f[7] = coef[3][0] * (b[5] - b[7] - b[8]) - f[5]; |
||
132 | f[5] = f[5] - f[4]; |
||
133 | f[6] = f[6] - f[5]; |
||
134 | |||
135 | f[8] = coef[4][0] * a[0] + coef[4][1] * a[1] + coef[4][2] * a[2] |
||
136 | + coef[4][3] * a[3] + a[4]; |
||
137 | f[9] = coef[4][0] * b[0] + coef[4][1] * b[1] + coef[4][2] * b[2] |
||
138 | + coef[4][3] * b[3] + b[4] - f[7]; |
||
139 | f[7] = f[7] - f[6]; |
||
140 | f[8] = f[8] - f[7]; |
||
141 | |||
142 | f[10] = coef[5][0] * a[5] + coef[5][1] * a[6] + coef[5][2] * a[7] |
||
143 | + coef[5][3] * a[8]; |
||
144 | f[11] = coef[5][0] * b[5] + coef[5][1] * b[6] + coef[5][2] * b[7] |
||
145 | + coef[5][3] * b[8] - f[9]; |
||
146 | f[9] = f[9] - f[8]; |
||
147 | f[10] = f[10] - f[9]; |
||
148 | |||
149 | f[12] = 0.5f * (a[0] + a[2] + a[3]) - a[1] - a[4]; |
||
150 | f[13] = 0.5f * (b[0] + b[2] + b[3]) - b[1] - b[4] - f[11]; |
||
151 | f[11] = f[11] - f[10]; |
||
152 | f[12] = f[12] - f[11]; |
||
153 | |||
154 | f[14] = coef[7][0] * a[5] + coef[7][1] * a[6] + coef[7][2] * a[7] |
||
155 | + coef[7][3] * a[8]; |
||
156 | f[15] = coef[7][0] * b[5] + coef[7][1] * b[6] + coef[7][2] * b[7] |
||
157 | + coef[7][3] * b[8] - f[13]; |
||
158 | f[13] = f[13] - f[12]; |
||
159 | f[14] = f[14] - f[13]; |
||
160 | |||
161 | f[16] = coef[8][0] * a[0] + coef[8][1] * a[1] + coef[8][2] * a[2] |
||
162 | + coef[8][3] * a[3] + a[4]; |
||
163 | f[17] = coef[8][0] * b[0] + coef[8][1] * b[1] + coef[8][2] * b[2] |
||
164 | + coef[8][3] * b[3] + b[4] - f[15]; |
||
165 | f[15] = f[15] - f[14]; |
||
166 | f[16] = f[16] - f[15]; |
||
167 | f[17] = f[17] - f[16]; |
||
168 | } |
||
169 | /*--------------------------------------------------------------------*/ |
||
170 | /* does 3, 6 pt dct. changes order from f[i][window] c[window][i] */ |
||
171 | void imdct6_3(float f[]) /* 6 point */ |
||
172 | { |
||
173 | int w; |
||
174 | float buf[18]; |
||
175 | float *a, *c; // b[i] = a[3+i] |
||
176 | |||
177 | float g1, g2; |
||
178 | float a02, b02; |
||
179 | |||
180 | c = f; |
||
181 | a = buf; |
||
182 | for (w = 0; w < 3; w++) |
||
183 | { |
||
184 | g1 = v[0] * f[3 * 0]; |
||
185 | g2 = v[5] * f[3 * 5]; |
||
186 | a[0] = g1 + g2; |
||
187 | a[3 + 0] = v2[0] * (g1 - g2); |
||
188 | |||
189 | g1 = v[1] * f[3 * 1]; |
||
190 | g2 = v[4] * f[3 * 4]; |
||
191 | a[1] = g1 + g2; |
||
192 | a[3 + 1] = v2[1] * (g1 - g2); |
||
193 | |||
194 | g1 = v[2] * f[3 * 2]; |
||
195 | g2 = v[3] * f[3 * 3]; |
||
196 | a[2] = g1 + g2; |
||
197 | a[3 + 2] = v2[2] * (g1 - g2); |
||
198 | |||
199 | a += 6; |
||
200 | f++; |
||
201 | } |
||
202 | |||
203 | a = buf; |
||
204 | for (w = 0; w < 3; w++) |
||
205 | { |
||
206 | a02 = (a[0] + a[2]); |
||
207 | b02 = (a[3 + 0] + a[3 + 2]); |
||
208 | c[0] = a02 + a[1]; |
||
209 | c[1] = b02 + a[3 + 1]; |
||
210 | c[2] = coef87 * (a[0] - a[2]); |
||
211 | c[3] = coef87 * (a[3 + 0] - a[3 + 2]) - c[1]; |
||
212 | c[1] = c[1] - c[0]; |
||
213 | c[2] = c[2] - c[1]; |
||
214 | c[4] = a02 - a[1] - a[1]; |
||
215 | c[5] = b02 - a[3 + 1] - a[3 + 1] - c[3]; |
||
216 | c[3] = c[3] - c[2]; |
||
217 | c[4] = c[4] - c[3]; |
||
218 | c[5] = c[5] - c[4]; |
||
219 | a += 6; |
||
220 | c += 6; |
||
221 | } |
||
222 | }>>>>>>>>>> |