1 |
291 |
simons |
/*
|
2 |
|
|
* mad - MPEG audio decoder
|
3 |
|
|
* Copyright (C) 2000-2001 Robert Leslie
|
4 |
|
|
*
|
5 |
|
|
* This program is free software; you can redistribute it and/or modify
|
6 |
|
|
* it under the terms of the GNU General Public License as published by
|
7 |
|
|
* the Free Software Foundation; either version 2 of the License, or
|
8 |
|
|
* (at your option) any later version.
|
9 |
|
|
*
|
10 |
|
|
* This program is distributed in the hope that it will be useful,
|
11 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
|
|
* GNU General Public License for more details.
|
14 |
|
|
*
|
15 |
|
|
* You should have received a copy of the GNU General Public License
|
16 |
|
|
* along with this program; if not, write to the Free Software
|
17 |
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
18 |
|
|
*
|
19 |
|
|
* $Id: synth.c,v 1.3 2001-11-06 17:01:28 simons Exp $
|
20 |
|
|
*/
|
21 |
|
|
|
22 |
|
|
# ifdef HAVE_CONFIG_H
|
23 |
|
|
# include "config.h"
|
24 |
|
|
# endif
|
25 |
|
|
|
26 |
|
|
# include "global.h"
|
27 |
|
|
|
28 |
|
|
# include "fixed.h"
|
29 |
|
|
# include "frame.h"
|
30 |
|
|
# include "synth.h"
|
31 |
|
|
# include "../audio.h"
|
32 |
|
|
|
33 |
|
|
#ifndef EMBED
|
34 |
|
|
# include <stdio.h>
|
35 |
|
|
#endif
|
36 |
|
|
|
37 |
|
|
/*
|
38 |
|
|
* NAME: synth->mute()
|
39 |
|
|
* DESCRIPTION: zero all polyphase filterbank values, resetting synthesis
|
40 |
|
|
*/
|
41 |
|
|
void mad_synth_mute(struct mad_synth *synth)
|
42 |
|
|
{
|
43 |
|
|
unsigned int ch, s, v;
|
44 |
|
|
|
45 |
|
|
for (ch = 0; ch < 2; ++ch) {
|
46 |
|
|
for (s = 0; s < 16; ++s) {
|
47 |
|
|
for (v = 0; v < 8; ++v) {
|
48 |
|
|
synth->filter[ch][0][0][s][v] = synth->filter[ch][0][1][s][v] =
|
49 |
|
|
synth->filter[ch][1][0][s][v] = synth->filter[ch][1][1][s][v] = 0;
|
50 |
|
|
}
|
51 |
|
|
}
|
52 |
|
|
}
|
53 |
|
|
}
|
54 |
|
|
|
55 |
|
|
/*
|
56 |
|
|
* NAME: synth->init()
|
57 |
|
|
* DESCRIPTION: initialize synth struct
|
58 |
|
|
*/
|
59 |
|
|
inline void mad_synth_init(struct mad_synth *synth)
|
60 |
|
|
{
|
61 |
|
|
mad_synth_mute(synth);
|
62 |
|
|
|
63 |
|
|
synth->phase = 0;
|
64 |
|
|
|
65 |
|
|
synth->pcm.samplerate = 0;
|
66 |
|
|
synth->pcm.channels = 0;
|
67 |
|
|
synth->pcm.length = 0;
|
68 |
|
|
}
|
69 |
|
|
|
70 |
|
|
/*
|
71 |
|
|
* An optional optimization called here the Subband Synthesis Optimization
|
72 |
|
|
* (SSO) improves the performance of subband synthesis at the expense of
|
73 |
|
|
* accuracy.
|
74 |
|
|
*
|
75 |
|
|
* The idea is to simplify 32x32->64-bit multiplication to 32x32->32 such
|
76 |
|
|
* that extra scaling and rounding are not necessary. This often allows the
|
77 |
|
|
* compiler to use faster 32-bit multiply-accumulate instructions instead of
|
78 |
|
|
* explicit 64-bit multiply, shift, and add instructions.
|
79 |
|
|
*
|
80 |
|
|
* SSO works like this: a full 32x32->64-bit multiply of two mad_fixed_t
|
81 |
|
|
* values requires the result to be right-shifted 28 bits to be properly
|
82 |
|
|
* scaled to the same fixed-point format. Right shifts can be applied at any
|
83 |
|
|
* time to either operand or to the result, so the optimization involves
|
84 |
|
|
* careful placement of these shifts to minimize the loss of accuracy.
|
85 |
|
|
*
|
86 |
|
|
* First, a 14-bit shift is applied with rounding at compile-time to the D[]
|
87 |
|
|
* table of coefficients for the subband synthesis window. This only loses 2
|
88 |
|
|
* bits of accuracy because the lower 12 bits are always zero. A second
|
89 |
|
|
* 12-bit shift occurs after the DCT calculation. This loses 12 bits of
|
90 |
|
|
* accuracy. Finally, a third 2-bit shift occurs just before the sample is
|
91 |
|
|
* saved in the PCM buffer. 14 + 12 + 2 == 28 bits.
|
92 |
|
|
*/
|
93 |
|
|
|
94 |
|
|
/* FPM_DEFAULT without OPT_SSO will actually lose accuracy and performance */
|
95 |
|
|
|
96 |
|
|
# if defined(FPM_DEFAULT) && !defined(OPT_SSO)
|
97 |
|
|
# define OPT_SSO
|
98 |
|
|
# endif
|
99 |
|
|
|
100 |
|
|
/* second SSO shift, with rounding */
|
101 |
|
|
|
102 |
|
|
# if defined(OPT_SSO)
|
103 |
|
|
# define SHIFT(x) (((x) + (1L << 11)) >> 12)
|
104 |
|
|
# else
|
105 |
|
|
# define SHIFT(x) (x)
|
106 |
|
|
# endif
|
107 |
|
|
|
108 |
|
|
/* possible DCT speed optimization */
|
109 |
|
|
|
110 |
|
|
# if defined(OPT_SPEED) && defined(MAD_F_MLX)
|
111 |
|
|
# define OPT_DCTO
|
112 |
|
|
# define MUL(x, y) \
|
113 |
|
|
({ mad_fixed64hi_t hi; \
|
114 |
|
|
mad_fixed64lo_t lo; \
|
115 |
|
|
MAD_F_MLX(hi, lo, (x), (y)); \
|
116 |
|
|
hi << (32 - MAD_F_SCALEBITS - 3); \
|
117 |
|
|
})
|
118 |
|
|
# else
|
119 |
|
|
# undef OPT_DCTO
|
120 |
|
|
# define MUL(x, y) mad_f_mul((x), (y))
|
121 |
|
|
# endif
|
122 |
|
|
|
123 |
|
|
/*
|
124 |
|
|
* NAME: dct32()
|
125 |
|
|
* DESCRIPTION: perform fast in[32]->out[32] DCT
|
126 |
|
|
*/
|
127 |
|
|
static
|
128 |
|
|
void dct32(mad_fixed_t const in[32], unsigned int slot,
|
129 |
|
|
mad_fixed_t lo[16][8], mad_fixed_t hi[16][8])
|
130 |
|
|
{
|
131 |
|
|
mad_fixed_t t0, t1, t2, t3, t4, t5, t6, t7;
|
132 |
|
|
mad_fixed_t t8, t9, t10, t11, t12, t13, t14, t15;
|
133 |
|
|
mad_fixed_t t16, t17, t18, t19, t20, t21, t22, t23;
|
134 |
|
|
mad_fixed_t t24, t25, t26, t27, t28, t29, t30, t31;
|
135 |
|
|
mad_fixed_t t32, t33, t34, t35, t36, t37, t38, t39;
|
136 |
|
|
mad_fixed_t t40, t41, t42, t43, t44, t45, t46, t47;
|
137 |
|
|
mad_fixed_t t48, t49, t50, t51, t52, t53, t54, t55;
|
138 |
|
|
mad_fixed_t t56, t57, t58, t59, t60, t61, t62, t63;
|
139 |
|
|
mad_fixed_t t64, t65, t66, t67, t68, t69, t70, t71;
|
140 |
|
|
mad_fixed_t t72, t73, t74, t75, t76, t77, t78, t79;
|
141 |
|
|
mad_fixed_t t80, t81, t82, t83, t84, t85, t86, t87;
|
142 |
|
|
mad_fixed_t t88, t89, t90, t91, t92, t93, t94, t95;
|
143 |
|
|
mad_fixed_t t96, t97, t98, t99, t100, t101, t102, t103;
|
144 |
|
|
mad_fixed_t t104, t105, t106, t107, t108, t109, t110, t111;
|
145 |
|
|
mad_fixed_t t112, t113, t114, t115, t116, t117, t118, t119;
|
146 |
|
|
mad_fixed_t t120, t121, t122, t123, t124, t125, t126, t127;
|
147 |
|
|
mad_fixed_t t128, t129, t130, t131, t132, t133, t134, t135;
|
148 |
|
|
mad_fixed_t t136, t137, t138, t139, t140, t141, t142, t143;
|
149 |
|
|
mad_fixed_t t144, t145, t146, t147, t148, t149, t150, t151;
|
150 |
|
|
mad_fixed_t t152, t153, t154, t155, t156, t157, t158, t159;
|
151 |
|
|
mad_fixed_t t160, t161, t162, t163, t164, t165, t166, t167;
|
152 |
|
|
mad_fixed_t t168, t169, t170, t171, t172, t173, t174, t175;
|
153 |
|
|
mad_fixed_t t176;
|
154 |
|
|
|
155 |
|
|
/* costab[i] = cos(PI / (2 * 32) * i) */
|
156 |
|
|
|
157 |
|
|
# if defined(OPT_DCTO)
|
158 |
|
|
enum {
|
159 |
|
|
costab1 = MAD_F(0x7fd8878e),
|
160 |
|
|
costab2 = MAD_F(0x7f62368f),
|
161 |
|
|
costab3 = MAD_F(0x7e9d55fc),
|
162 |
|
|
costab4 = MAD_F(0x7d8a5f40),
|
163 |
|
|
costab5 = MAD_F(0x7c29fbee),
|
164 |
|
|
costab6 = MAD_F(0x7a7d055b),
|
165 |
|
|
costab7 = MAD_F(0x78848414),
|
166 |
|
|
costab8 = MAD_F(0x7641af3d),
|
167 |
|
|
costab9 = MAD_F(0x73b5ebd1),
|
168 |
|
|
costab10 = MAD_F(0x70e2cbc6),
|
169 |
|
|
costab11 = MAD_F(0x6dca0d14),
|
170 |
|
|
costab12 = MAD_F(0x6a6d98a4),
|
171 |
|
|
costab13 = MAD_F(0x66cf8120),
|
172 |
|
|
costab14 = MAD_F(0x62f201ac),
|
173 |
|
|
costab15 = MAD_F(0x5ed77c8a),
|
174 |
|
|
costab16 = MAD_F(0x5a82799a),
|
175 |
|
|
costab17 = MAD_F(0x55f5a4d2),
|
176 |
|
|
costab18 = MAD_F(0x5133cc94),
|
177 |
|
|
costab19 = MAD_F(0x4c3fdff4),
|
178 |
|
|
costab20 = MAD_F(0x471cece7),
|
179 |
|
|
costab21 = MAD_F(0x41ce1e65),
|
180 |
|
|
costab22 = MAD_F(0x3c56ba70),
|
181 |
|
|
costab23 = MAD_F(0x36ba2014),
|
182 |
|
|
costab24 = MAD_F(0x30fbc54d),
|
183 |
|
|
costab25 = MAD_F(0x2b1f34eb),
|
184 |
|
|
costab26 = MAD_F(0x25280c5e),
|
185 |
|
|
costab27 = MAD_F(0x1f19f97b),
|
186 |
|
|
costab28 = MAD_F(0x18f8b83c),
|
187 |
|
|
costab29 = MAD_F(0x12c8106f),
|
188 |
|
|
costab30 = MAD_F(0x0c8bd35e),
|
189 |
|
|
costab31 = MAD_F(0x0647d97c)
|
190 |
|
|
};
|
191 |
|
|
# else
|
192 |
|
|
enum {
|
193 |
|
|
costab1 = MAD_F(0x0ffb10f2), /* 0.998795456 */
|
194 |
|
|
costab2 = MAD_F(0x0fec46d2), /* 0.995184727 */
|
195 |
|
|
costab3 = MAD_F(0x0fd3aac0), /* 0.989176510 */
|
196 |
|
|
costab4 = MAD_F(0x0fb14be8), /* 0.980785280 */
|
197 |
|
|
costab5 = MAD_F(0x0f853f7e), /* 0.970031253 */
|
198 |
|
|
costab6 = MAD_F(0x0f4fa0ab), /* 0.956940336 */
|
199 |
|
|
costab7 = MAD_F(0x0f109082), /* 0.941544065 */
|
200 |
|
|
costab8 = MAD_F(0x0ec835e8), /* 0.923879533 */
|
201 |
|
|
costab9 = MAD_F(0x0e76bd7a), /* 0.903989293 */
|
202 |
|
|
costab10 = MAD_F(0x0e1c5979), /* 0.881921264 */
|
203 |
|
|
costab11 = MAD_F(0x0db941a3), /* 0.857728610 */
|
204 |
|
|
costab12 = MAD_F(0x0d4db315), /* 0.831469612 */
|
205 |
|
|
costab13 = MAD_F(0x0cd9f024), /* 0.803207531 */
|
206 |
|
|
costab14 = MAD_F(0x0c5e4036), /* 0.773010453 */
|
207 |
|
|
costab15 = MAD_F(0x0bdaef91), /* 0.740951125 */
|
208 |
|
|
costab16 = MAD_F(0x0b504f33), /* 0.707106781 */
|
209 |
|
|
costab17 = MAD_F(0x0abeb49a), /* 0.671558955 */
|
210 |
|
|
costab18 = MAD_F(0x0a267993), /* 0.634393284 */
|
211 |
|
|
costab19 = MAD_F(0x0987fbfe), /* 0.595699304 */
|
212 |
|
|
costab20 = MAD_F(0x08e39d9d), /* 0.555570233 */
|
213 |
|
|
costab21 = MAD_F(0x0839c3cd), /* 0.514102744 */
|
214 |
|
|
costab22 = MAD_F(0x078ad74e), /* 0.471396737 */
|
215 |
|
|
costab23 = MAD_F(0x06d74402), /* 0.427555093 */
|
216 |
|
|
costab24 = MAD_F(0x061f78aa), /* 0.382683432 */
|
217 |
|
|
costab25 = MAD_F(0x0563e69d), /* 0.336889853 */
|
218 |
|
|
costab26 = MAD_F(0x04a5018c), /* 0.290284677 */
|
219 |
|
|
costab27 = MAD_F(0x03e33f2f), /* 0.242980180 */
|
220 |
|
|
costab28 = MAD_F(0x031f1708), /* 0.195090322 */
|
221 |
|
|
costab29 = MAD_F(0x0259020e), /* 0.146730474 */
|
222 |
|
|
costab30 = MAD_F(0x01917a6c), /* 0.098017140 */
|
223 |
|
|
costab31 = MAD_F(0x00c8fb30) /* 0.049067674 */
|
224 |
|
|
};
|
225 |
|
|
# endif
|
226 |
|
|
|
227 |
|
|
t0 = in[0] + in[31]; t16 = MUL(in[0] - in[31], costab1);
|
228 |
|
|
t1 = in[15] + in[16]; t17 = MUL(in[15] - in[16], costab31);
|
229 |
|
|
|
230 |
|
|
t41 = t16 + t17;
|
231 |
|
|
t59 = MUL(t16 - t17, costab2);
|
232 |
|
|
t33 = t0 + t1;
|
233 |
|
|
t50 = MUL(t0 - t1, costab2);
|
234 |
|
|
|
235 |
|
|
t2 = in[7] + in[24]; t18 = MUL(in[7] - in[24], costab15);
|
236 |
|
|
t3 = in[8] + in[23]; t19 = MUL(in[8] - in[23], costab17);
|
237 |
|
|
|
238 |
|
|
t42 = t18 + t19;
|
239 |
|
|
t60 = MUL(t18 - t19, costab30);
|
240 |
|
|
t34 = t2 + t3;
|
241 |
|
|
t51 = MUL(t2 - t3, costab30);
|
242 |
|
|
|
243 |
|
|
t4 = in[3] + in[28]; t20 = MUL(in[3] - in[28], costab7);
|
244 |
|
|
t5 = in[12] + in[19]; t21 = MUL(in[12] - in[19], costab25);
|
245 |
|
|
|
246 |
|
|
t43 = t20 + t21;
|
247 |
|
|
t61 = MUL(t20 - t21, costab14);
|
248 |
|
|
t35 = t4 + t5;
|
249 |
|
|
t52 = MUL(t4 - t5, costab14);
|
250 |
|
|
|
251 |
|
|
t6 = in[4] + in[27]; t22 = MUL(in[4] - in[27], costab9);
|
252 |
|
|
t7 = in[11] + in[20]; t23 = MUL(in[11] - in[20], costab23);
|
253 |
|
|
|
254 |
|
|
t44 = t22 + t23;
|
255 |
|
|
t62 = MUL(t22 - t23, costab18);
|
256 |
|
|
t36 = t6 + t7;
|
257 |
|
|
t53 = MUL(t6 - t7, costab18);
|
258 |
|
|
|
259 |
|
|
t8 = in[1] + in[30]; t24 = MUL(in[1] - in[30], costab3);
|
260 |
|
|
t9 = in[14] + in[17]; t25 = MUL(in[14] - in[17], costab29);
|
261 |
|
|
|
262 |
|
|
t45 = t24 + t25;
|
263 |
|
|
t63 = MUL(t24 - t25, costab6);
|
264 |
|
|
t37 = t8 + t9;
|
265 |
|
|
t54 = MUL(t8 - t9, costab6);
|
266 |
|
|
|
267 |
|
|
t10 = in[6] + in[25]; t26 = MUL(in[6] - in[25], costab13);
|
268 |
|
|
t11 = in[9] + in[22]; t27 = MUL(in[9] - in[22], costab19);
|
269 |
|
|
|
270 |
|
|
t46 = t26 + t27;
|
271 |
|
|
t64 = MUL(t26 - t27, costab26);
|
272 |
|
|
t38 = t10 + t11;
|
273 |
|
|
t55 = MUL(t10 - t11, costab26);
|
274 |
|
|
|
275 |
|
|
t12 = in[2] + in[29]; t28 = MUL(in[2] - in[29], costab5);
|
276 |
|
|
t13 = in[13] + in[18]; t29 = MUL(in[13] - in[18], costab27);
|
277 |
|
|
|
278 |
|
|
t47 = t28 + t29;
|
279 |
|
|
t65 = MUL(t28 - t29, costab10);
|
280 |
|
|
t39 = t12 + t13;
|
281 |
|
|
t56 = MUL(t12 - t13, costab10);
|
282 |
|
|
|
283 |
|
|
t14 = in[5] + in[26]; t30 = MUL(in[5] - in[26], costab11);
|
284 |
|
|
t15 = in[10] + in[21]; t31 = MUL(in[10] - in[21], costab21);
|
285 |
|
|
|
286 |
|
|
t48 = t30 + t31;
|
287 |
|
|
t66 = MUL(t30 - t31, costab22);
|
288 |
|
|
t40 = t14 + t15;
|
289 |
|
|
t57 = MUL(t14 - t15, costab22);
|
290 |
|
|
|
291 |
|
|
t69 = t33 + t34; t89 = MUL(t33 - t34, costab4);
|
292 |
|
|
t70 = t35 + t36; t90 = MUL(t35 - t36, costab28);
|
293 |
|
|
t71 = t37 + t38; t91 = MUL(t37 - t38, costab12);
|
294 |
|
|
t72 = t39 + t40; t92 = MUL(t39 - t40, costab20);
|
295 |
|
|
t73 = t41 + t42; t94 = MUL(t41 - t42, costab4);
|
296 |
|
|
t74 = t43 + t44; t95 = MUL(t43 - t44, costab28);
|
297 |
|
|
t75 = t45 + t46; t96 = MUL(t45 - t46, costab12);
|
298 |
|
|
t76 = t47 + t48; t97 = MUL(t47 - t48, costab20);
|
299 |
|
|
|
300 |
|
|
t78 = t50 + t51; t100 = MUL(t50 - t51, costab4);
|
301 |
|
|
t79 = t52 + t53; t101 = MUL(t52 - t53, costab28);
|
302 |
|
|
t80 = t54 + t55; t102 = MUL(t54 - t55, costab12);
|
303 |
|
|
t81 = t56 + t57; t103 = MUL(t56 - t57, costab20);
|
304 |
|
|
|
305 |
|
|
t83 = t59 + t60; t106 = MUL(t59 - t60, costab4);
|
306 |
|
|
t84 = t61 + t62; t107 = MUL(t61 - t62, costab28);
|
307 |
|
|
t85 = t63 + t64; t108 = MUL(t63 - t64, costab12);
|
308 |
|
|
t86 = t65 + t66; t109 = MUL(t65 - t66, costab20);
|
309 |
|
|
|
310 |
|
|
t113 = t69 + t70;
|
311 |
|
|
t114 = t71 + t72;
|
312 |
|
|
|
313 |
|
|
/* 0 */ hi[15][slot] = SHIFT(t113 + t114);
|
314 |
|
|
/* 16 */ lo[ 0][slot] = SHIFT(MUL(t113 - t114, costab16));
|
315 |
|
|
|
316 |
|
|
t115 = t73 + t74;
|
317 |
|
|
t116 = t75 + t76;
|
318 |
|
|
|
319 |
|
|
t32 = t115 + t116;
|
320 |
|
|
|
321 |
|
|
/* 1 */ hi[14][slot] = SHIFT(t32);
|
322 |
|
|
|
323 |
|
|
t118 = t78 + t79;
|
324 |
|
|
t119 = t80 + t81;
|
325 |
|
|
|
326 |
|
|
t58 = t118 + t119;
|
327 |
|
|
|
328 |
|
|
/* 2 */ hi[13][slot] = SHIFT(t58);
|
329 |
|
|
|
330 |
|
|
t121 = t83 + t84;
|
331 |
|
|
t122 = t85 + t86;
|
332 |
|
|
|
333 |
|
|
t67 = t121 + t122;
|
334 |
|
|
|
335 |
|
|
t49 = (t67 << 1) - t32;
|
336 |
|
|
|
337 |
|
|
/* 3 */ hi[12][slot] = SHIFT(t49);
|
338 |
|
|
|
339 |
|
|
t125 = t89 + t90;
|
340 |
|
|
t126 = t91 + t92;
|
341 |
|
|
|
342 |
|
|
t93 = t125 + t126;
|
343 |
|
|
|
344 |
|
|
/* 4 */ hi[11][slot] = SHIFT(t93);
|
345 |
|
|
|
346 |
|
|
t128 = t94 + t95;
|
347 |
|
|
t129 = t96 + t97;
|
348 |
|
|
|
349 |
|
|
t98 = t128 + t129;
|
350 |
|
|
|
351 |
|
|
t68 = (t98 << 1) - t49;
|
352 |
|
|
|
353 |
|
|
/* 5 */ hi[10][slot] = SHIFT(t68);
|
354 |
|
|
|
355 |
|
|
t132 = t100 + t101;
|
356 |
|
|
t133 = t102 + t103;
|
357 |
|
|
|
358 |
|
|
t104 = t132 + t133;
|
359 |
|
|
|
360 |
|
|
t82 = (t104 << 1) - t58;
|
361 |
|
|
|
362 |
|
|
/* 6 */ hi[ 9][slot] = SHIFT(t82);
|
363 |
|
|
|
364 |
|
|
t136 = t106 + t107;
|
365 |
|
|
t137 = t108 + t109;
|
366 |
|
|
|
367 |
|
|
t110 = t136 + t137;
|
368 |
|
|
|
369 |
|
|
t87 = (t110 << 1) - t67;
|
370 |
|
|
|
371 |
|
|
t77 = (t87 << 1) - t68;
|
372 |
|
|
|
373 |
|
|
/* 7 */ hi[ 8][slot] = SHIFT(t77);
|
374 |
|
|
|
375 |
|
|
t141 = MUL(t69 - t70, costab8);
|
376 |
|
|
t142 = MUL(t71 - t72, costab24);
|
377 |
|
|
t143 = t141 + t142;
|
378 |
|
|
|
379 |
|
|
/* 8 */ hi[ 7][slot] = SHIFT(t143);
|
380 |
|
|
/* 24 */ lo[ 8][slot] =
|
381 |
|
|
SHIFT((MUL(t141 - t142, costab16) << 1) - t143);
|
382 |
|
|
|
383 |
|
|
t144 = MUL(t73 - t74, costab8);
|
384 |
|
|
t145 = MUL(t75 - t76, costab24);
|
385 |
|
|
t146 = t144 + t145;
|
386 |
|
|
|
387 |
|
|
t88 = (t146 << 1) - t77;
|
388 |
|
|
|
389 |
|
|
/* 9 */ hi[ 6][slot] = SHIFT(t88);
|
390 |
|
|
|
391 |
|
|
t148 = MUL(t78 - t79, costab8);
|
392 |
|
|
t149 = MUL(t80 - t81, costab24);
|
393 |
|
|
t150 = t148 + t149;
|
394 |
|
|
|
395 |
|
|
t105 = (t150 << 1) - t82;
|
396 |
|
|
|
397 |
|
|
/* 10 */ hi[ 5][slot] = SHIFT(t105);
|
398 |
|
|
|
399 |
|
|
t152 = MUL(t83 - t84, costab8);
|
400 |
|
|
t153 = MUL(t85 - t86, costab24);
|
401 |
|
|
t154 = t152 + t153;
|
402 |
|
|
|
403 |
|
|
t111 = (t154 << 1) - t87;
|
404 |
|
|
|
405 |
|
|
t99 = (t111 << 1) - t88;
|
406 |
|
|
|
407 |
|
|
/* 11 */ hi[ 4][slot] = SHIFT(t99);
|
408 |
|
|
|
409 |
|
|
t157 = MUL(t89 - t90, costab8);
|
410 |
|
|
t158 = MUL(t91 - t92, costab24);
|
411 |
|
|
t159 = t157 + t158;
|
412 |
|
|
|
413 |
|
|
t127 = (t159 << 1) - t93;
|
414 |
|
|
|
415 |
|
|
/* 12 */ hi[ 3][slot] = SHIFT(t127);
|
416 |
|
|
|
417 |
|
|
t160 = (MUL(t125 - t126, costab16) << 1) - t127;
|
418 |
|
|
|
419 |
|
|
/* 20 */ lo[ 4][slot] = SHIFT(t160);
|
420 |
|
|
/* 28 */ lo[12][slot] =
|
421 |
|
|
SHIFT((((MUL(t157 - t158, costab16) << 1) - t159) << 1) - t160);
|
422 |
|
|
|
423 |
|
|
t161 = MUL(t94 - t95, costab8);
|
424 |
|
|
t162 = MUL(t96 - t97, costab24);
|
425 |
|
|
t163 = t161 + t162;
|
426 |
|
|
|
427 |
|
|
t130 = (t163 << 1) - t98;
|
428 |
|
|
|
429 |
|
|
t112 = (t130 << 1) - t99;
|
430 |
|
|
|
431 |
|
|
/* 13 */ hi[ 2][slot] = SHIFT(t112);
|
432 |
|
|
|
433 |
|
|
t164 = (MUL(t128 - t129, costab16) << 1) - t130;
|
434 |
|
|
|
435 |
|
|
t166 = MUL(t100 - t101, costab8);
|
436 |
|
|
t167 = MUL(t102 - t103, costab24);
|
437 |
|
|
t168 = t166 + t167;
|
438 |
|
|
|
439 |
|
|
t134 = (t168 << 1) - t104;
|
440 |
|
|
|
441 |
|
|
t120 = (t134 << 1) - t105;
|
442 |
|
|
|
443 |
|
|
/* 14 */ hi[ 1][slot] = SHIFT(t120);
|
444 |
|
|
|
445 |
|
|
t135 = (MUL(t118 - t119, costab16) << 1) - t120;
|
446 |
|
|
|
447 |
|
|
/* 18 */ lo[ 2][slot] = SHIFT(t135);
|
448 |
|
|
|
449 |
|
|
t169 = (MUL(t132 - t133, costab16) << 1) - t134;
|
450 |
|
|
|
451 |
|
|
t151 = (t169 << 1) - t135;
|
452 |
|
|
|
453 |
|
|
/* 22 */ lo[ 6][slot] = SHIFT(t151);
|
454 |
|
|
|
455 |
|
|
t170 = (((MUL(t148 - t149, costab16) << 1) - t150) << 1) - t151;
|
456 |
|
|
|
457 |
|
|
/* 26 */ lo[10][slot] = SHIFT(t170);
|
458 |
|
|
/* 30 */ lo[14][slot] =
|
459 |
|
|
SHIFT((((((MUL(t166 - t167, costab16) << 1) -
|
460 |
|
|
t168) << 1) - t169) << 1) - t170);
|
461 |
|
|
|
462 |
|
|
t171 = MUL(t106 - t107, costab8);
|
463 |
|
|
t172 = MUL(t108 - t109, costab24);
|
464 |
|
|
t173 = t171 + t172;
|
465 |
|
|
|
466 |
|
|
t138 = (t173 << 1) - t110;
|
467 |
|
|
|
468 |
|
|
t123 = (t138 << 1) - t111;
|
469 |
|
|
|
470 |
|
|
t139 = (MUL(t121 - t122, costab16) << 1) - t123;
|
471 |
|
|
|
472 |
|
|
t117 = (t123 << 1) - t112;
|
473 |
|
|
|
474 |
|
|
/* 15 */ hi[ 0][slot] = SHIFT(t117);
|
475 |
|
|
|
476 |
|
|
t124 = (MUL(t115 - t116, costab16) << 1) - t117;
|
477 |
|
|
|
478 |
|
|
/* 17 */ lo[ 1][slot] = SHIFT(t124);
|
479 |
|
|
|
480 |
|
|
t131 = (t139 << 1) - t124;
|
481 |
|
|
|
482 |
|
|
/* 19 */ lo[ 3][slot] = SHIFT(t131);
|
483 |
|
|
|
484 |
|
|
t140 = (t164 << 1) - t131;
|
485 |
|
|
|
486 |
|
|
/* 21 */ lo[ 5][slot] = SHIFT(t140);
|
487 |
|
|
|
488 |
|
|
t174 = (MUL(t136 - t137, costab16) << 1) - t138;
|
489 |
|
|
|
490 |
|
|
t155 = (t174 << 1) - t139;
|
491 |
|
|
|
492 |
|
|
t147 = (t155 << 1) - t140;
|
493 |
|
|
|
494 |
|
|
/* 23 */ lo[ 7][slot] = SHIFT(t147);
|
495 |
|
|
|
496 |
|
|
t156 = (((MUL(t144 - t145, costab16) << 1) - t146) << 1) - t147;
|
497 |
|
|
|
498 |
|
|
/* 25 */ lo[ 9][slot] = SHIFT(t156);
|
499 |
|
|
|
500 |
|
|
t175 = (((MUL(t152 - t153, costab16) << 1) - t154) << 1) - t155;
|
501 |
|
|
|
502 |
|
|
t165 = (t175 << 1) - t156;
|
503 |
|
|
|
504 |
|
|
/* 27 */ lo[11][slot] = SHIFT(t165);
|
505 |
|
|
|
506 |
|
|
t176 = (((((MUL(t161 - t162, costab16) << 1) -
|
507 |
|
|
t163) << 1) - t164) << 1) - t165;
|
508 |
|
|
|
509 |
|
|
/* 29 */ lo[13][slot] = SHIFT(t176);
|
510 |
|
|
/* 31 */ lo[15][slot] =
|
511 |
|
|
SHIFT((((((((MUL(t171 - t172, costab16) << 1) -
|
512 |
|
|
t173) << 1) - t174) << 1) - t175) << 1) - t176);
|
513 |
|
|
|
514 |
|
|
/*
|
515 |
|
|
* Totals:
|
516 |
|
|
* 80 multiplies
|
517 |
|
|
* 80 additions
|
518 |
|
|
* 119 subtractions
|
519 |
|
|
* 49 shifts (not counting SSO)
|
520 |
|
|
*/
|
521 |
|
|
}
|
522 |
|
|
|
523 |
|
|
# undef MUL
|
524 |
|
|
# undef SHIFT
|
525 |
|
|
|
526 |
|
|
/* third SSO shift and/or D[] optimization preshift */
|
527 |
|
|
|
528 |
|
|
# if defined(OPT_SSO)
|
529 |
|
|
# if MAD_F_FRACBITS != 28
|
530 |
|
|
# error "MAD_F_FRACBITS must be 28 to use OPT_SSO"
|
531 |
|
|
# endif
|
532 |
|
|
# define ML0(hi, lo, x, y) ((lo) = (x) * (y))
|
533 |
|
|
# define MLA(hi, lo, x, y) ((lo) += (x) * (y))
|
534 |
|
|
# define MLZ(hi, lo) ((void) (hi), (mad_fixed_t) (lo))
|
535 |
|
|
# define SHIFT(x) ((x) >> 2)
|
536 |
|
|
# define PRESHIFT(x) ((MAD_F(x) + (1L << 13)) >> 14)
|
537 |
|
|
# else
|
538 |
|
|
# define ML0(hi, lo, x, y) MAD_F_ML0((hi), (lo), (x), (y))
|
539 |
|
|
# define MLA(hi, lo, x, y) MAD_F_MLA((hi), (lo), (x), (y))
|
540 |
|
|
# define MLZ(hi, lo) MAD_F_MLZ((hi), (lo))
|
541 |
|
|
# define SHIFT(x) (x)
|
542 |
|
|
# if defined(MAD_F_SCALEBITS)
|
543 |
|
|
# undef MAD_F_SCALEBITS
|
544 |
|
|
# define MAD_F_SCALEBITS (MAD_F_FRACBITS - 12)
|
545 |
|
|
# define PRESHIFT(x) (MAD_F(x) >> 12)
|
546 |
|
|
# else
|
547 |
|
|
# define PRESHIFT(x) MAD_F(x)
|
548 |
|
|
# endif
|
549 |
|
|
# endif
|
550 |
|
|
|
551 |
|
|
static
|
552 |
|
|
mad_fixed_t const D[17][32] = {
|
553 |
|
|
# include "D.dat"
|
554 |
|
|
};
|
555 |
|
|
|
556 |
|
|
/* 3. called to process output */
|
557 |
|
|
|
558 |
|
|
int speed = 0, nchan = 0;
|
559 |
|
|
|
560 |
|
|
# ifndef EMBED
|
561 |
|
|
int output_s(unsigned char const *ptr, unsigned int len);
|
562 |
|
|
# endif
|
563 |
|
|
|
564 |
|
|
static inline void
|
565 |
|
|
output(struct mad_pcm *pcm)
|
566 |
|
|
{
|
567 |
|
|
unsigned int nchannels;
|
568 |
|
|
union audio_control control;
|
569 |
|
|
mad_fixed_t *ch1, *ch2;
|
570 |
|
|
|
571 |
|
|
nchannels = pcm->channels;
|
572 |
|
|
|
573 |
|
|
if (nchannels != nchan || speed != pcm->samplerate)
|
574 |
|
|
{
|
575 |
|
|
# ifndef EMBED
|
576 |
|
|
control.command = AUDIO_COMMAND_CONFIG;
|
577 |
|
|
|
578 |
|
|
control.config.channels = nchannels;
|
579 |
|
|
control.config.speed = pcm->samplerate;
|
580 |
|
|
|
581 |
|
|
if (audio_oss(&control) == -1)
|
582 |
|
|
return;
|
583 |
|
|
# endif
|
584 |
|
|
nchan = nchannels;
|
585 |
|
|
speed = pcm->samplerate;
|
586 |
|
|
}
|
587 |
|
|
ch1 = &pcm->samples[0][0];
|
588 |
|
|
ch2 = &pcm->samples[1][0];
|
589 |
|
|
|
590 |
|
|
if (nchan == 1)
|
591 |
|
|
ch2 = ch1;
|
592 |
|
|
|
593 |
|
|
{
|
594 |
|
|
unsigned char data[MAX_NSAMPLES * 4 * 2];
|
595 |
|
|
unsigned int len;
|
596 |
|
|
|
597 |
|
|
len = audio_pcm_s16le(data, pcm->length, ch1, ch2);
|
598 |
|
|
# ifndef EMBED
|
599 |
|
|
output_s(data, len);
|
600 |
|
|
# endif
|
601 |
|
|
}
|
602 |
|
|
return;
|
603 |
|
|
}
|
604 |
|
|
|
605 |
|
|
# if defined(ASO_SYNTH)
|
606 |
|
|
void synth_full(struct mad_synth *, struct mad_frame const *,
|
607 |
|
|
unsigned int, unsigned int);
|
608 |
|
|
# else
|
609 |
|
|
/*
|
610 |
|
|
* NAME: synth->full()
|
611 |
|
|
* DESCRIPTION: perform full frequency PCM synthesis
|
612 |
|
|
*/
|
613 |
|
|
static inline
|
614 |
|
|
void synth_full(struct mad_synth *synth, struct mad_frame const *frame,
|
615 |
|
|
unsigned int nch, unsigned int ns)
|
616 |
|
|
{
|
617 |
|
|
unsigned int phase, ch, s, sb, pe, po;
|
618 |
|
|
mad_fixed_t *pcm1, *pcm2, (*filter)[2][2][16][8];
|
619 |
|
|
mad_fixed_t const (*sbsample)[36][32];
|
620 |
|
|
register mad_fixed_t (*fe)[8], (*fx)[8], (*fo)[8];
|
621 |
|
|
register mad_fixed_t const (*Dptr)[32], *ptr;
|
622 |
|
|
register mad_fixed64hi_t hi;
|
623 |
|
|
register mad_fixed64lo_t lo;
|
624 |
|
|
|
625 |
|
|
phase = synth->phase;
|
626 |
|
|
|
627 |
|
|
for (s = 0; s < ns; ++s) {
|
628 |
|
|
for (ch = 0; ch < nch; ++ch) {
|
629 |
|
|
sbsample = &frame->sbsample[ch];
|
630 |
|
|
filter = &synth->filter[ch];
|
631 |
|
|
pcm1 = synth->pcm.samples[ch];
|
632 |
|
|
|
633 |
|
|
dct32((*sbsample)[s], phase >> 1,
|
634 |
|
|
(*filter)[0][phase & 1], (*filter)[1][phase & 1]);
|
635 |
|
|
|
636 |
|
|
pe = phase & ~1;
|
637 |
|
|
po = ((phase - 1) & 0xf) | 1;
|
638 |
|
|
|
639 |
|
|
/* calculate 32 samples */
|
640 |
|
|
|
641 |
|
|
fe = &(*filter)[0][ phase & 1][0];
|
642 |
|
|
fx = &(*filter)[0][~phase & 1][0];
|
643 |
|
|
fo = &(*filter)[1][~phase & 1][0];
|
644 |
|
|
|
645 |
|
|
Dptr = &D[0];
|
646 |
|
|
|
647 |
|
|
ptr = *Dptr + pe;
|
648 |
|
|
ML0(hi, lo, (*fe)[0], ptr[ 0]);
|
649 |
|
|
MLA(hi, lo, (*fe)[1], ptr[14]);
|
650 |
|
|
MLA(hi, lo, (*fe)[2], ptr[12]);
|
651 |
|
|
MLA(hi, lo, (*fe)[3], ptr[10]);
|
652 |
|
|
MLA(hi, lo, (*fe)[4], ptr[ 8]);
|
653 |
|
|
MLA(hi, lo, (*fe)[5], ptr[ 6]);
|
654 |
|
|
MLA(hi, lo, (*fe)[6], ptr[ 4]);
|
655 |
|
|
MLA(hi, lo, (*fe)[7], ptr[ 2]);
|
656 |
|
|
|
657 |
|
|
ptr = *Dptr + po;
|
658 |
|
|
MLA(hi, lo, (*fx)[0], -ptr[ 0]);
|
659 |
|
|
MLA(hi, lo, (*fx)[1], -ptr[14]);
|
660 |
|
|
MLA(hi, lo, (*fx)[2], -ptr[12]);
|
661 |
|
|
MLA(hi, lo, (*fx)[3], -ptr[10]);
|
662 |
|
|
MLA(hi, lo, (*fx)[4], -ptr[ 8]);
|
663 |
|
|
MLA(hi, lo, (*fx)[5], -ptr[ 6]);
|
664 |
|
|
MLA(hi, lo, (*fx)[6], -ptr[ 4]);
|
665 |
|
|
MLA(hi, lo, (*fx)[7], -ptr[ 2]);
|
666 |
|
|
|
667 |
|
|
*pcm1++ = SHIFT(MLZ(hi, lo));
|
668 |
|
|
|
669 |
|
|
pcm2 = pcm1 + 30;
|
670 |
|
|
|
671 |
|
|
for (sb = 1; sb < 16; ++sb) {
|
672 |
|
|
++fe;
|
673 |
|
|
++Dptr;
|
674 |
|
|
|
675 |
|
|
/* D[32 - sb][i] == -D[sb][31 - i] */
|
676 |
|
|
|
677 |
|
|
ptr = *Dptr + pe;
|
678 |
|
|
ML0(hi, lo, (*fe)[7], ptr[ 2]);
|
679 |
|
|
MLA(hi, lo, (*fe)[6], ptr[ 4]);
|
680 |
|
|
MLA(hi, lo, (*fe)[5], ptr[ 6]);
|
681 |
|
|
MLA(hi, lo, (*fe)[4], ptr[ 8]);
|
682 |
|
|
MLA(hi, lo, (*fe)[3], ptr[10]);
|
683 |
|
|
MLA(hi, lo, (*fe)[2], ptr[12]);
|
684 |
|
|
MLA(hi, lo, (*fe)[1], ptr[14]);
|
685 |
|
|
MLA(hi, lo, (*fe)[0], ptr[ 0]);
|
686 |
|
|
|
687 |
|
|
ptr = *Dptr + po;
|
688 |
|
|
MLA(hi, lo, (*fo)[0], -ptr[ 0]);
|
689 |
|
|
MLA(hi, lo, (*fo)[1], -ptr[14]);
|
690 |
|
|
MLA(hi, lo, (*fo)[2], -ptr[12]);
|
691 |
|
|
MLA(hi, lo, (*fo)[3], -ptr[10]);
|
692 |
|
|
MLA(hi, lo, (*fo)[4], -ptr[ 8]);
|
693 |
|
|
MLA(hi, lo, (*fo)[5], -ptr[ 6]);
|
694 |
|
|
MLA(hi, lo, (*fo)[6], -ptr[ 4]);
|
695 |
|
|
MLA(hi, lo, (*fo)[7], -ptr[ 2]);
|
696 |
|
|
|
697 |
|
|
*pcm1++ = SHIFT(MLZ(hi, lo));
|
698 |
|
|
|
699 |
|
|
ptr = *Dptr - po;
|
700 |
|
|
ML0(hi, lo, (*fo)[7], ptr[31 - 2]);
|
701 |
|
|
MLA(hi, lo, (*fo)[6], ptr[31 - 4]);
|
702 |
|
|
MLA(hi, lo, (*fo)[5], ptr[31 - 6]);
|
703 |
|
|
MLA(hi, lo, (*fo)[4], ptr[31 - 8]);
|
704 |
|
|
MLA(hi, lo, (*fo)[3], ptr[31 - 10]);
|
705 |
|
|
MLA(hi, lo, (*fo)[2], ptr[31 - 12]);
|
706 |
|
|
MLA(hi, lo, (*fo)[1], ptr[31 - 14]);
|
707 |
|
|
MLA(hi, lo, (*fo)[0], ptr[31 - 16]);
|
708 |
|
|
|
709 |
|
|
ptr = *Dptr - pe;
|
710 |
|
|
MLA(hi, lo, (*fe)[0], ptr[31 - 16]);
|
711 |
|
|
MLA(hi, lo, (*fe)[1], ptr[31 - 14]);
|
712 |
|
|
MLA(hi, lo, (*fe)[2], ptr[31 - 12]);
|
713 |
|
|
MLA(hi, lo, (*fe)[3], ptr[31 - 10]);
|
714 |
|
|
MLA(hi, lo, (*fe)[4], ptr[31 - 8]);
|
715 |
|
|
MLA(hi, lo, (*fe)[5], ptr[31 - 6]);
|
716 |
|
|
MLA(hi, lo, (*fe)[6], ptr[31 - 4]);
|
717 |
|
|
MLA(hi, lo, (*fe)[7], ptr[31 - 2]);
|
718 |
|
|
|
719 |
|
|
*pcm2-- = SHIFT(MLZ(hi, lo));
|
720 |
|
|
|
721 |
|
|
++fo;
|
722 |
|
|
}
|
723 |
|
|
|
724 |
|
|
++Dptr;
|
725 |
|
|
|
726 |
|
|
ptr = *Dptr + po;
|
727 |
|
|
ML0(hi, lo, (*fo)[0], ptr[ 0]);
|
728 |
|
|
MLA(hi, lo, (*fo)[1], ptr[14]);
|
729 |
|
|
MLA(hi, lo, (*fo)[2], ptr[12]);
|
730 |
|
|
MLA(hi, lo, (*fo)[3], ptr[10]);
|
731 |
|
|
MLA(hi, lo, (*fo)[4], ptr[ 8]);
|
732 |
|
|
MLA(hi, lo, (*fo)[5], ptr[ 6]);
|
733 |
|
|
MLA(hi, lo, (*fo)[6], ptr[ 4]);
|
734 |
|
|
MLA(hi, lo, (*fo)[7], ptr[ 2]);
|
735 |
|
|
|
736 |
|
|
*pcm1 = SHIFT(-MLZ(hi, lo));
|
737 |
|
|
}
|
738 |
|
|
|
739 |
|
|
phase = (phase + 1) % 16;
|
740 |
|
|
|
741 |
|
|
synth->pcm.length = 32;
|
742 |
|
|
output (&synth->pcm);
|
743 |
|
|
}
|
744 |
|
|
}
|
745 |
|
|
# endif
|
746 |
|
|
|
747 |
|
|
/*
|
748 |
|
|
* NAME: synth->frame()
|
749 |
|
|
* DESCRIPTION: perform PCM synthesis of frame subband samples
|
750 |
|
|
*/
|
751 |
|
|
void inline mad_synth_frame(struct mad_synth *synth, struct mad_frame const *frame)
|
752 |
|
|
{
|
753 |
|
|
unsigned int nch, ns;
|
754 |
|
|
|
755 |
|
|
nch = MAD_NCHANNELS(&frame->header);
|
756 |
|
|
ns = MAD_NSBSAMPLES(&frame->header);
|
757 |
|
|
|
758 |
|
|
synth->pcm.samplerate = frame->header.samplerate;
|
759 |
|
|
synth->pcm.channels = nch;
|
760 |
|
|
synth->pcm.length = 32 * ns;
|
761 |
|
|
|
762 |
|
|
synth_full(synth, frame, nch, ns);
|
763 |
|
|
|
764 |
|
|
synth->phase = (synth->phase + ns) % 16;
|
765 |
|
|
}
|