Fix up configure and buildzip/wpsbuild.pl a bit
[kugel-rb.git] / apps / codecs / libmad / synth.c
bloba928864b77b20206e0c2c426280dfa7b896ef767
1 /*
2 * libmad - MPEG audio decoder library
3 * Copyright (C) 2000-2004 Underbit Technologies, Inc.
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.
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.
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
19 * $Id$
22 # ifdef HAVE_CONFIG_H
23 # include "config.h"
24 # endif
26 # include "global.h"
28 # include "fixed.h"
29 # include "frame.h"
30 # include "synth.h"
33 * NAME: synth->init()
34 * DESCRIPTION: initialize synth struct
36 void mad_synth_init(struct mad_synth *synth)
38 mad_synth_mute(synth);
40 synth->phase = 0;
42 synth->pcm.samplerate = 0;
43 synth->pcm.channels = 0;
44 synth->pcm.length = 0;
45 #if defined(CPU_COLDFIRE)
46 /* init the emac unit here, since this function should always be called
47 before using libmad */
48 coldfire_set_macsr(EMAC_FRACTIONAL | EMAC_SATURATE | EMAC_ROUND);
49 #endif
53 * NAME: synth->mute()
54 * DESCRIPTION: zero all polyphase filterbank values, resetting synthesis
56 void mad_synth_mute(struct mad_synth *synth)
58 memset(synth->filter, 0, sizeof(synth->filter));
61 #if 0 /* dct32 asm implementation is slower on current arm systems */
62 /* #ifdef FPM_ARM */
64 void dct32(mad_fixed_t const in[32], unsigned int slot,
65 mad_fixed_t lo[16][8], mad_fixed_t hi[16][8]);
67 #else
70 * An optional optimization called here the Subband Synthesis Optimization
71 * (SSO) improves the performance of subband synthesis at the expense of
72 * accuracy.
74 * The idea is to simplify 32x32->64-bit multiplication to 32x32->32 such
75 * that extra scaling and rounding are not necessary. This often allows the
76 * compiler to use faster 32-bit multiply-accumulate instructions instead of
77 * explicit 64-bit multiply, shift, and add instructions.
79 * SSO works like this: a full 32x32->64-bit multiply of two mad_fixed_t
80 * values requires the result to be right-shifted 28 bits to be properly
81 * scaled to the same fixed-point format. Right shifts can be applied at any
82 * time to either operand or to the result, so the optimization involves
83 * careful placement of these shifts to minimize the loss of accuracy.
85 * First, a 14-bit shift is applied with rounding at compile-time to the D[]
86 * table of coefficients for the subband synthesis window. This only loses 2
87 * bits of accuracy because the lower 12 bits are always zero. A second
88 * 12-bit shift occurs after the DCT calculation. This loses 12 bits of
89 * accuracy. Finally, a third 2-bit shift occurs just before the sample is
90 * saved in the PCM buffer. 14 + 12 + 2 == 28 bits.
93 /* FPM_DEFAULT without OPT_SSO will actually lose accuracy and performance */
95 # if defined(FPM_DEFAULT) && !defined(OPT_SSO)
96 # define OPT_SSO
97 # endif
99 /* second SSO shift, with rounding */
101 # if defined(OPT_SSO)
102 # define SHIFT(x) (((x) + (1L << 11)) >> 12)
103 # else
104 # define SHIFT(x) (x)
105 # endif
107 /* possible DCT speed optimization */
109 /* This is a Coldfire version of the OPT_SPEED optimisation below, but in the
110 case of Coldfire it doesn't lose any more precision than we would ordinarily
111 lose, */
112 # ifdef FPM_COLDFIRE_EMAC
113 # define OPT_DCTO
114 # define MUL(x, y) \
115 ({ \
116 mad_fixed64hi_t hi; \
117 asm volatile("mac.l %[a], %[b], %%acc0\n\t" \
118 "movclr.l %%acc0, %[hi]" \
119 : [hi] "=r" (hi) \
120 : [a] "r" ((x)), [b] "r" ((y))); \
121 hi; \
123 # elif defined(OPT_SPEED) && defined(MAD_F_MLX)
124 # define OPT_DCTO
125 # define MUL(x, y) \
126 ({ mad_fixed64hi_t hi; \
127 mad_fixed64lo_t lo; \
128 MAD_F_MLX(hi, lo, (x), (y)); \
129 hi << (32 - MAD_F_SCALEBITS - 3); \
131 # else
132 # undef OPT_DCTO
133 # define MUL(x, y) mad_f_mul((x), (y))
134 # endif
137 * NAME: dct32()
138 * DESCRIPTION: perform fast in[32]->out[32] DCT
140 static
141 void dct32(mad_fixed_t const in[32], unsigned int slot,
142 mad_fixed_t lo[16][8], mad_fixed_t hi[16][8])
144 mad_fixed_t t0, t1, t2, t3, t4, t5, t6, t7;
145 mad_fixed_t t8, t9, t10, t11, t12, t13, t14, t15;
146 mad_fixed_t t16, t17, t18, t19, t20, t21, t22, t23;
147 mad_fixed_t t24, t25, t26, t27, t28, t29, t30, t31;
148 mad_fixed_t t32, t33, t34, t35, t36, t37, t38, t39;
149 mad_fixed_t t40, t41, t42, t43, t44, t45, t46, t47;
150 mad_fixed_t t48, t49, t50, t51, t52, t53, t54, t55;
151 mad_fixed_t t56, t57, t58, t59, t60, t61, t62, t63;
152 mad_fixed_t t64, t65, t66, t67, t68, t69, t70, t71;
153 mad_fixed_t t72, t73, t74, t75, t76, t77, t78, t79;
154 mad_fixed_t t80, t81, t82, t83, t84, t85, t86, t87;
155 mad_fixed_t t88, t89, t90, t91, t92, t93, t94, t95;
156 mad_fixed_t t96, t97, t98, t99, t100, t101, t102, t103;
157 mad_fixed_t t104, t105, t106, t107, t108, t109, t110, t111;
158 mad_fixed_t t112, t113, t114, t115, t116, t117, t118, t119;
159 mad_fixed_t t120, t121, t122, t123, t124, t125, t126, t127;
160 mad_fixed_t t128, t129, t130, t131, t132, t133, t134, t135;
161 mad_fixed_t t136, t137, t138, t139, t140, t141, t142, t143;
162 mad_fixed_t t144, t145, t146, t147, t148, t149, t150, t151;
163 mad_fixed_t t152, t153, t154, t155, t156, t157, t158, t159;
164 mad_fixed_t t160, t161, t162, t163, t164, t165, t166, t167;
165 mad_fixed_t t168, t169, t170, t171, t172, t173, t174, t175;
166 mad_fixed_t t176;
168 /* costab[i] = cos(PI / (2 * 32) * i) */
170 # if defined(OPT_DCTO)
171 # define costab1 MAD_F(0x7fd8878e)
172 # define costab2 MAD_F(0x7f62368f)
173 # define costab3 MAD_F(0x7e9d55fc)
174 # define costab4 MAD_F(0x7d8a5f40)
175 # define costab5 MAD_F(0x7c29fbee)
176 # define costab6 MAD_F(0x7a7d055b)
177 # define costab7 MAD_F(0x78848414)
178 # define costab8 MAD_F(0x7641af3d)
179 # define costab9 MAD_F(0x73b5ebd1)
180 # define costab10 MAD_F(0x70e2cbc6)
181 # define costab11 MAD_F(0x6dca0d14)
182 # define costab12 MAD_F(0x6a5d98a4)
183 # define costab13 MAD_F(0x66cf8120)
184 # define costab14 MAD_F(0x62f201ac)
185 # define costab15 MAD_F(0x5ed77c8a)
186 # define costab16 MAD_F(0x5a82799a)
187 # define costab17 MAD_F(0x55f5a4d2)
188 # define costab18 MAD_F(0x5133cc94)
189 # define costab19 MAD_F(0x4c3fdff4)
190 # define costab20 MAD_F(0x471cece7)
191 # define costab21 MAD_F(0x41ce1e65)
192 # define costab22 MAD_F(0x3c56ba70)
193 # define costab23 MAD_F(0x36ba2014)
194 # define costab24 MAD_F(0x30fbc54d)
195 # define costab25 MAD_F(0x2b1f34eb)
196 # define costab26 MAD_F(0x25280c5e)
197 # define costab27 MAD_F(0x1f19f97b)
198 # define costab28 MAD_F(0x18f8b83c)
199 # define costab29 MAD_F(0x12c8106f)
200 # define costab30 MAD_F(0x0c8bd35e)
201 # define costab31 MAD_F(0x0647d97c)
202 # else
203 # define costab1 MAD_F(0x0ffb10f2) /* 0.998795456 */
204 # define costab2 MAD_F(0x0fec46d2) /* 0.995184727 */
205 # define costab3 MAD_F(0x0fd3aac0) /* 0.989176510 */
206 # define costab4 MAD_F(0x0fb14be8) /* 0.980785280 */
207 # define costab5 MAD_F(0x0f853f7e) /* 0.970031253 */
208 # define costab6 MAD_F(0x0f4fa0ab) /* 0.956940336 */
209 # define costab7 MAD_F(0x0f109082) /* 0.941544065 */
210 # define costab8 MAD_F(0x0ec835e8) /* 0.923879533 */
211 # define costab9 MAD_F(0x0e76bd7a) /* 0.903989293 */
212 # define costab10 MAD_F(0x0e1c5979) /* 0.881921264 */
213 # define costab11 MAD_F(0x0db941a3) /* 0.857728610 */
214 # define costab12 MAD_F(0x0d4db315) /* 0.831469612 */
215 # define costab13 MAD_F(0x0cd9f024) /* 0.803207531 */
216 # define costab14 MAD_F(0x0c5e4036) /* 0.773010453 */
217 # define costab15 MAD_F(0x0bdaef91) /* 0.740951125 */
218 # define costab16 MAD_F(0x0b504f33) /* 0.707106781 */
219 # define costab17 MAD_F(0x0abeb49a) /* 0.671558955 */
220 # define costab18 MAD_F(0x0a267993) /* 0.634393284 */
221 # define costab19 MAD_F(0x0987fbfe) /* 0.595699304 */
222 # define costab20 MAD_F(0x08e39d9d) /* 0.555570233 */
223 # define costab21 MAD_F(0x0839c3cd) /* 0.514102744 */
224 # define costab22 MAD_F(0x078ad74e) /* 0.471396737 */
225 # define costab23 MAD_F(0x06d74402) /* 0.427555093 */
226 # define costab24 MAD_F(0x061f78aa) /* 0.382683432 */
227 # define costab25 MAD_F(0x0563e69d) /* 0.336889853 */
228 # define costab26 MAD_F(0x04a5018c) /* 0.290284677 */
229 # define costab27 MAD_F(0x03e33f2f) /* 0.242980180 */
230 # define costab28 MAD_F(0x031f1708) /* 0.195090322 */
231 # define costab29 MAD_F(0x0259020e) /* 0.146730474 */
232 # define costab30 MAD_F(0x01917a5c) /* 0.098017140 */
233 # define costab31 MAD_F(0x00c8fb30) /* 0.049067674 */
234 # endif
236 t0 = in[0] + in[31]; t16 = MUL(in[0] - in[31], costab1);
237 t1 = in[15] + in[16]; t17 = MUL(in[15] - in[16], costab31);
239 t41 = t16 + t17;
240 t59 = MUL(t16 - t17, costab2);
241 t33 = t0 + t1;
242 t50 = MUL(t0 - t1, costab2);
244 t2 = in[7] + in[24]; t18 = MUL(in[7] - in[24], costab15);
245 t3 = in[8] + in[23]; t19 = MUL(in[8] - in[23], costab17);
247 t42 = t18 + t19;
248 t60 = MUL(t18 - t19, costab30);
249 t34 = t2 + t3;
250 t51 = MUL(t2 - t3, costab30);
252 t4 = in[3] + in[28]; t20 = MUL(in[3] - in[28], costab7);
253 t5 = in[12] + in[19]; t21 = MUL(in[12] - in[19], costab25);
255 t43 = t20 + t21;
256 t61 = MUL(t20 - t21, costab14);
257 t35 = t4 + t5;
258 t52 = MUL(t4 - t5, costab14);
260 t6 = in[4] + in[27]; t22 = MUL(in[4] - in[27], costab9);
261 t7 = in[11] + in[20]; t23 = MUL(in[11] - in[20], costab23);
263 t44 = t22 + t23;
264 t62 = MUL(t22 - t23, costab18);
265 t36 = t6 + t7;
266 t53 = MUL(t6 - t7, costab18);
268 t8 = in[1] + in[30]; t24 = MUL(in[1] - in[30], costab3);
269 t9 = in[14] + in[17]; t25 = MUL(in[14] - in[17], costab29);
271 t45 = t24 + t25;
272 t63 = MUL(t24 - t25, costab6);
273 t37 = t8 + t9;
274 t54 = MUL(t8 - t9, costab6);
276 t10 = in[6] + in[25]; t26 = MUL(in[6] - in[25], costab13);
277 t11 = in[9] + in[22]; t27 = MUL(in[9] - in[22], costab19);
279 t46 = t26 + t27;
280 t64 = MUL(t26 - t27, costab26);
281 t38 = t10 + t11;
282 t55 = MUL(t10 - t11, costab26);
284 t12 = in[2] + in[29]; t28 = MUL(in[2] - in[29], costab5);
285 t13 = in[13] + in[18]; t29 = MUL(in[13] - in[18], costab27);
287 t47 = t28 + t29;
288 t65 = MUL(t28 - t29, costab10);
289 t39 = t12 + t13;
290 t56 = MUL(t12 - t13, costab10);
292 t14 = in[5] + in[26]; t30 = MUL(in[5] - in[26], costab11);
293 t15 = in[10] + in[21]; t31 = MUL(in[10] - in[21], costab21);
295 t48 = t30 + t31;
296 t66 = MUL(t30 - t31, costab22);
297 t40 = t14 + t15;
298 t57 = MUL(t14 - t15, costab22);
300 t69 = t33 + t34; t89 = MUL(t33 - t34, costab4);
301 t70 = t35 + t36; t90 = MUL(t35 - t36, costab28);
302 t71 = t37 + t38; t91 = MUL(t37 - t38, costab12);
303 t72 = t39 + t40; t92 = MUL(t39 - t40, costab20);
304 t73 = t41 + t42; t94 = MUL(t41 - t42, costab4);
305 t74 = t43 + t44; t95 = MUL(t43 - t44, costab28);
306 t75 = t45 + t46; t96 = MUL(t45 - t46, costab12);
307 t76 = t47 + t48; t97 = MUL(t47 - t48, costab20);
309 t78 = t50 + t51; t100 = MUL(t50 - t51, costab4);
310 t79 = t52 + t53; t101 = MUL(t52 - t53, costab28);
311 t80 = t54 + t55; t102 = MUL(t54 - t55, costab12);
312 t81 = t56 + t57; t103 = MUL(t56 - t57, costab20);
314 t83 = t59 + t60; t106 = MUL(t59 - t60, costab4);
315 t84 = t61 + t62; t107 = MUL(t61 - t62, costab28);
316 t85 = t63 + t64; t108 = MUL(t63 - t64, costab12);
317 t86 = t65 + t66; t109 = MUL(t65 - t66, costab20);
319 t113 = t69 + t70;
320 t114 = t71 + t72;
322 /* 0 */ hi[15][slot] = SHIFT(t113 + t114);
323 /* 16 */ lo[ 0][slot] = SHIFT(MUL(t113 - t114, costab16));
325 t115 = t73 + t74;
326 t116 = t75 + t76;
328 t32 = t115 + t116;
330 /* 1 */ hi[14][slot] = SHIFT(t32);
332 t118 = t78 + t79;
333 t119 = t80 + t81;
335 t58 = t118 + t119;
337 /* 2 */ hi[13][slot] = SHIFT(t58);
339 t121 = t83 + t84;
340 t122 = t85 + t86;
342 t67 = t121 + t122;
344 t49 = (t67 * 2) - t32;
346 /* 3 */ hi[12][slot] = SHIFT(t49);
348 t125 = t89 + t90;
349 t126 = t91 + t92;
351 t93 = t125 + t126;
353 /* 4 */ hi[11][slot] = SHIFT(t93);
355 t128 = t94 + t95;
356 t129 = t96 + t97;
358 t98 = t128 + t129;
360 t68 = (t98 * 2) - t49;
362 /* 5 */ hi[10][slot] = SHIFT(t68);
364 t132 = t100 + t101;
365 t133 = t102 + t103;
367 t104 = t132 + t133;
369 t82 = (t104 * 2) - t58;
371 /* 6 */ hi[ 9][slot] = SHIFT(t82);
373 t136 = t106 + t107;
374 t137 = t108 + t109;
376 t110 = t136 + t137;
378 t87 = (t110 * 2) - t67;
380 t77 = (t87 * 2) - t68;
382 /* 7 */ hi[ 8][slot] = SHIFT(t77);
384 t141 = MUL(t69 - t70, costab8);
385 t142 = MUL(t71 - t72, costab24);
386 t143 = t141 + t142;
388 /* 8 */ hi[ 7][slot] = SHIFT(t143);
389 /* 24 */ lo[ 8][slot] =
390 SHIFT((MUL(t141 - t142, costab16) * 2) - t143);
392 t144 = MUL(t73 - t74, costab8);
393 t145 = MUL(t75 - t76, costab24);
394 t146 = t144 + t145;
396 t88 = (t146 * 2) - t77;
398 /* 9 */ hi[ 6][slot] = SHIFT(t88);
400 t148 = MUL(t78 - t79, costab8);
401 t149 = MUL(t80 - t81, costab24);
402 t150 = t148 + t149;
404 t105 = (t150 * 2) - t82;
406 /* 10 */ hi[ 5][slot] = SHIFT(t105);
408 t152 = MUL(t83 - t84, costab8);
409 t153 = MUL(t85 - t86, costab24);
410 t154 = t152 + t153;
412 t111 = (t154 * 2) - t87;
414 t99 = (t111 * 2) - t88;
416 /* 11 */ hi[ 4][slot] = SHIFT(t99);
418 t157 = MUL(t89 - t90, costab8);
419 t158 = MUL(t91 - t92, costab24);
420 t159 = t157 + t158;
422 t127 = (t159 * 2) - t93;
424 /* 12 */ hi[ 3][slot] = SHIFT(t127);
426 t160 = (MUL(t125 - t126, costab16) * 2) - t127;
428 /* 20 */ lo[ 4][slot] = SHIFT(t160);
429 /* 28 */ lo[12][slot] =
430 SHIFT((((MUL(t157 - t158, costab16) * 2) - t159) * 2) - t160);
432 t161 = MUL(t94 - t95, costab8);
433 t162 = MUL(t96 - t97, costab24);
434 t163 = t161 + t162;
436 t130 = (t163 * 2) - t98;
438 t112 = (t130 * 2) - t99;
440 /* 13 */ hi[ 2][slot] = SHIFT(t112);
442 t164 = (MUL(t128 - t129, costab16) * 2) - t130;
444 t166 = MUL(t100 - t101, costab8);
445 t167 = MUL(t102 - t103, costab24);
446 t168 = t166 + t167;
448 t134 = (t168 * 2) - t104;
450 t120 = (t134 * 2) - t105;
452 /* 14 */ hi[ 1][slot] = SHIFT(t120);
454 t135 = (MUL(t118 - t119, costab16) * 2) - t120;
456 /* 18 */ lo[ 2][slot] = SHIFT(t135);
458 t169 = (MUL(t132 - t133, costab16) * 2) - t134;
460 t151 = (t169 * 2) - t135;
462 /* 22 */ lo[ 6][slot] = SHIFT(t151);
464 t170 = (((MUL(t148 - t149, costab16) * 2) - t150) * 2) - t151;
466 /* 26 */ lo[10][slot] = SHIFT(t170);
467 /* 30 */ lo[14][slot] =
468 SHIFT((((((MUL(t166 - t167, costab16) * 2) -
469 t168) * 2) - t169) * 2) - t170);
471 t171 = MUL(t106 - t107, costab8);
472 t172 = MUL(t108 - t109, costab24);
473 t173 = t171 + t172;
475 t138 = (t173 * 2) - t110;
477 t123 = (t138 * 2) - t111;
479 t139 = (MUL(t121 - t122, costab16) * 2) - t123;
481 t117 = (t123 * 2) - t112;
483 /* 15 */ hi[ 0][slot] = SHIFT(t117);
485 t124 = (MUL(t115 - t116, costab16) * 2) - t117;
487 /* 17 */ lo[ 1][slot] = SHIFT(t124);
489 t131 = (t139 * 2) - t124;
491 /* 19 */ lo[ 3][slot] = SHIFT(t131);
493 t140 = (t164 * 2) - t131;
495 /* 21 */ lo[ 5][slot] = SHIFT(t140);
497 t174 = (MUL(t136 - t137, costab16) * 2) - t138;
499 t155 = (t174 * 2) - t139;
501 t147 = (t155 * 2) - t140;
503 /* 23 */ lo[ 7][slot] = SHIFT(t147);
505 t156 = (((MUL(t144 - t145, costab16) * 2) - t146) * 2) - t147;
507 /* 25 */ lo[ 9][slot] = SHIFT(t156);
509 t175 = (((MUL(t152 - t153, costab16) * 2) - t154) * 2) - t155;
511 t165 = (t175 * 2) - t156;
513 /* 27 */ lo[11][slot] = SHIFT(t165);
515 t176 = (((((MUL(t161 - t162, costab16) * 2) -
516 t163) * 2) - t164) * 2) - t165;
518 /* 29 */ lo[13][slot] = SHIFT(t176);
519 /* 31 */ lo[15][slot] =
520 SHIFT((((((((MUL(t171 - t172, costab16) * 2) -
521 t173) * 2) - t174) * 2) - t175) * 2) - t176);
524 * Totals:
525 * 80 multiplies
526 * 80 additions
527 * 119 subtractions
528 * 49 shifts (not counting SSO)
532 # undef MUL
533 # undef SHIFT
535 #endif
537 /* third SSO shift and/or D[] optimization preshift */
539 # if defined(OPT_SSO)
540 # if MAD_F_FRACBITS != 28
541 # error "MAD_F_FRACBITS must be 28 to use OPT_SSO"
542 # endif
543 # define ML0(hi, lo, x, y) ((lo) = (x) * (y))
544 # define MLA(hi, lo, x, y) ((lo) += (x) * (y))
545 # define MLN(hi, lo) ((lo) = -(lo))
546 # define MLZ(hi, lo) ((void) (hi), (mad_fixed_t) (lo))
547 # define SHIFT(x) ((x) >> 2)
548 # define PRESHIFT(x) ((MAD_F(x) + (1L << 13)) >> 14)
549 # else
550 # define ML0(hi, lo, x, y) MAD_F_ML0((hi), (lo), (x), (y))
551 # define MLA(hi, lo, x, y) MAD_F_MLA((hi), (lo), (x), (y))
552 # define MLN(hi, lo) MAD_F_MLN((hi), (lo))
553 # define MLZ(hi, lo) MAD_F_MLZ((hi), (lo))
554 # define SHIFT(x) (x)
555 # if defined(MAD_F_SCALEBITS)
556 # undef MAD_F_SCALEBITS
557 # define MAD_F_SCALEBITS (MAD_F_FRACBITS - 12)
558 # define PRESHIFT(x) (MAD_F(x) >> 12)
559 # else
560 # define PRESHIFT(x) MAD_F(x)
561 # endif
562 # endif
564 static
565 mad_fixed_t const D[17][32] ICONST_ATTR = {
566 # include "D.dat"
569 # if defined(ASO_SYNTH)
570 void synth_full(struct mad_synth *, struct mad_frame const *,
571 unsigned int, unsigned int);
572 # else
574 * NAME: synth->full()
575 * DESCRIPTION: perform full frequency PCM synthesis
578 /* optimised version of synth_full */
579 # ifdef FPM_COLDFIRE_EMAC
581 #define SYNTH_EMAC1(res, f1, pD) \
582 asm volatile( \
583 "movem.l (%0), %%d0-%%d7 \n\t" \
584 "move.l (%1), %%a5 \n\t" \
585 "mac.l %%d0, %%a5, 56(%1), %%a5, %%acc0\n\t" \
586 "mac.l %%d1, %%a5, 48(%1), %%a5, %%acc0\n\t" \
587 "mac.l %%d2, %%a5, 40(%1), %%a5, %%acc0\n\t" \
588 "mac.l %%d3, %%a5, 32(%1), %%a5, %%acc0\n\t" \
589 "mac.l %%d4, %%a5, 24(%1), %%a5, %%acc0\n\t" \
590 "mac.l %%d5, %%a5, 16(%1), %%a5, %%acc0\n\t" \
591 "mac.l %%d6, %%a5, 8(%1), %%a5, %%acc0\n\t" \
592 "mac.l %%d7, %%a5, %%acc0\n\t" \
594 : "a" (*f1), "a" (*pD) \
595 : "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7", "a5"); \
596 asm volatile ( \
597 "movclr.l %%acc0, %0 \n\t" \
598 : "=d" (res));
600 #define SYNTH_EMAC2(res, f1, f2, pD) \
601 asm volatile( \
602 "movem.l (%0), %%d0-%%d7 \n\t" \
603 "move.l 4(%1), %%a5 \n\t" \
604 "msac.l %%d0, %%a5, 60(%1), %%a5, %%acc0\n\t" \
605 "msac.l %%d1, %%a5, 52(%1), %%a5, %%acc0\n\t" \
606 "msac.l %%d2, %%a5, 44(%1), %%a5, %%acc0\n\t" \
607 "msac.l %%d3, %%a5, 36(%1), %%a5, %%acc0\n\t" \
608 "msac.l %%d4, %%a5, 28(%1), %%a5, %%acc0\n\t" \
609 "msac.l %%d5, %%a5, 20(%1), %%a5, %%acc0\n\t" \
610 "msac.l %%d6, %%a5, 12(%1), %%a5, %%acc0\n\t" \
611 "msac.l %%d7, %%a5, (%1), %%a5, %%acc0\n\t" \
612 "movem.l (%2), %%d0-%%d7 \n\t" \
613 "mac.l %%d0, %%a5, 56(%1), %%a5, %%acc0\n\t" \
614 "mac.l %%d1, %%a5, 48(%1), %%a5, %%acc0\n\t" \
615 "mac.l %%d2, %%a5, 40(%1), %%a5, %%acc0\n\t" \
616 "mac.l %%d3, %%a5, 32(%1), %%a5, %%acc0\n\t" \
617 "mac.l %%d4, %%a5, 24(%1), %%a5, %%acc0\n\t" \
618 "mac.l %%d5, %%a5, 16(%1), %%a5, %%acc0\n\t" \
619 "mac.l %%d6, %%a5, 8(%1), %%a5, %%acc0\n\t" \
620 "mac.l %%d7, %%a5, %%acc0\n\t" \
622 : "a" (*f1), "a" (*pD), "a" (*f2) \
623 : "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7", "a5", "memory"); \
624 asm volatile ( \
625 "movclr.l %%acc0, %0 \n\t" \
626 : "=d" (res));
628 #define SYNTH_EMAC_ODD_SBSAMPLE(f1, f2, pD1, pD2, res1, res2) \
629 asm volatile ( \
630 "movem.l (%0), %%d0-%%d7 \n\t" \
631 "move.l 4(%2), %%a5 \n\t" \
632 "msac.l %%d0, %%a5, 60(%2), %%a5, %%acc0\n\t" \
633 "msac.l %%d1, %%a5, 52(%2), %%a5, %%acc0\n\t" \
634 "msac.l %%d2, %%a5, 44(%2), %%a5, %%acc0\n\t" \
635 "msac.l %%d3, %%a5, 36(%2), %%a5, %%acc0\n\t" \
636 "msac.l %%d4, %%a5, 28(%2), %%a5, %%acc0\n\t" \
637 "msac.l %%d5, %%a5, 20(%2), %%a5, %%acc0\n\t" \
638 "msac.l %%d6, %%a5, 12(%2), %%a5, %%acc0\n\t" \
639 "msac.l %%d7, %%a5, 112(%3), %%a5, %%acc0\n\t" \
640 "mac.l %%d7, %%a5, 104(%3), %%a5, %%acc1\n\t" \
641 "mac.l %%d6, %%a5, 96(%3), %%a5, %%acc1\n\t" \
642 "mac.l %%d5, %%a5, 88(%3), %%a5, %%acc1\n\t" \
643 "mac.l %%d4, %%a5, 80(%3), %%a5, %%acc1\n\t" \
644 "mac.l %%d3, %%a5, 72(%3), %%a5, %%acc1\n\t" \
645 "mac.l %%d2, %%a5, 64(%3), %%a5, %%acc1\n\t" \
646 "mac.l %%d1, %%a5, 120(%3), %%a5, %%acc1\n\t" \
647 "mac.l %%d0, %%a5, 8(%2), %%a5, %%acc1\n\t" \
648 "movem.l (%1), %%d0-%%d7 \n\t" \
649 "mac.l %%d7, %%a5, 16(%2), %%a5, %%acc0\n\t" \
650 "mac.l %%d6, %%a5, 24(%2), %%a5, %%acc0\n\t" \
651 "mac.l %%d5, %%a5, 32(%2), %%a5, %%acc0\n\t" \
652 "mac.l %%d4, %%a5, 40(%2), %%a5, %%acc0\n\t" \
653 "mac.l %%d3, %%a5, 48(%2), %%a5, %%acc0\n\t" \
654 "mac.l %%d2, %%a5, 56(%2), %%a5, %%acc0\n\t" \
655 "mac.l %%d1, %%a5, (%2), %%a5, %%acc0\n\t" \
656 "mac.l %%d0, %%a5, 60(%3), %%a5, %%acc0\n\t" \
657 "mac.l %%d0, %%a5, 68(%3), %%a5, %%acc1\n\t" \
658 "mac.l %%d1, %%a5, 76(%3), %%a5, %%acc1\n\t" \
659 "mac.l %%d2, %%a5, 84(%3), %%a5, %%acc1\n\t" \
660 "mac.l %%d3, %%a5, 92(%3), %%a5, %%acc1\n\t" \
661 "mac.l %%d4, %%a5, 100(%3), %%a5, %%acc1\n\t" \
662 "mac.l %%d5, %%a5, 108(%3), %%a5, %%acc1\n\t" \
663 "mac.l %%d6, %%a5, 116(%3), %%a5, %%acc1\n\t" \
664 "mac.l %%d7, %%a5, %%acc1\n\t" \
666 : "a" (*f1), "a" (*f2), "a" (*pD1), "a" (*pD2) \
667 : "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7", "a5", "memory"); \
668 asm volatile( \
669 "movclr.l %%acc0, %0\n\t" \
670 "movclr.l %%acc1, %1\n\t" \
671 : "=d" (res1), "=d" (res2) );
673 #define SYNTH_EMAC_EVEN_SBSAMPLE(f1, f2, pD1, pD2, res1, res2) \
674 asm volatile ( \
675 "movem.l (%0), %%d0-%%d7 \n\t" \
676 "move.l (%2), %%a5 \n\t" \
677 "msac.l %%d0, %%a5, 56(%2), %%a5, %%acc0\n\t" \
678 "msac.l %%d1, %%a5, 48(%2), %%a5, %%acc0\n\t" \
679 "msac.l %%d2, %%a5, 40(%2), %%a5, %%acc0\n\t" \
680 "msac.l %%d3, %%a5, 32(%2), %%a5, %%acc0\n\t" \
681 "msac.l %%d4, %%a5, 24(%2), %%a5, %%acc0\n\t" \
682 "msac.l %%d5, %%a5, 16(%2), %%a5, %%acc0\n\t" \
683 "msac.l %%d6, %%a5, 8(%2), %%a5, %%acc0\n\t" \
684 "msac.l %%d7, %%a5, 116(%3), %%a5, %%acc0\n\t" \
685 "mac.l %%d7, %%a5, 108(%3), %%a5, %%acc1\n\t" \
686 "mac.l %%d6, %%a5, 100(%3), %%a5, %%acc1\n\t" \
687 "mac.l %%d5, %%a5, 92(%3), %%a5, %%acc1\n\t" \
688 "mac.l %%d4, %%a5, 84(%3), %%a5, %%acc1\n\t" \
689 "mac.l %%d3, %%a5, 76(%3), %%a5, %%acc1\n\t" \
690 "mac.l %%d2, %%a5, 68(%3), %%a5, %%acc1\n\t" \
691 "mac.l %%d1, %%a5, 60(%3), %%a5, %%acc1\n\t" \
692 "mac.l %%d0, %%a5, 12(%2), %%a5, %%acc1\n\t" \
693 "movem.l (%1), %%d0-%%d7 \n\t" \
694 "mac.l %%d7, %%a5, 20(%2), %%a5, %%acc0\n\t" \
695 "mac.l %%d6, %%a5, 28(%2), %%a5, %%acc0\n\t" \
696 "mac.l %%d5, %%a5, 36(%2), %%a5, %%acc0\n\t" \
697 "mac.l %%d4, %%a5, 44(%2), %%a5, %%acc0\n\t" \
698 "mac.l %%d3, %%a5, 52(%2), %%a5, %%acc0\n\t" \
699 "mac.l %%d2, %%a5, 60(%2), %%a5, %%acc0\n\t" \
700 "mac.l %%d1, %%a5, 4(%2), %%a5, %%acc0\n\t" \
701 "mac.l %%d0, %%a5, 120(%3), %%a5, %%acc0\n\t" \
702 "mac.l %%d0, %%a5, 64(%3), %%a5, %%acc1\n\t" \
703 "mac.l %%d1, %%a5, 72(%3), %%a5, %%acc1\n\t" \
704 "mac.l %%d2, %%a5, 80(%3), %%a5, %%acc1\n\t" \
705 "mac.l %%d3, %%a5, 88(%3), %%a5, %%acc1\n\t" \
706 "mac.l %%d4, %%a5, 96(%3), %%a5, %%acc1\n\t" \
707 "mac.l %%d5, %%a5, 104(%3), %%a5, %%acc1\n\t" \
708 "mac.l %%d6, %%a5, 112(%3), %%a5, %%acc1\n\t" \
709 "mac.l %%d7, %%a5, %%acc1\n\t" \
711 : "a" (*f1), "a" (*f2), "a" (*pD1), "a" (*pD2) \
712 : "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7", "a5", "memory"); \
713 asm volatile( \
714 "movclr.l %%acc0, %0\n\t" \
715 "movclr.l %%acc1, %1\n\t" \
716 : "=d" (res1), "=d" (res2) );
718 static
719 void synth_full(struct mad_synth *synth, struct mad_frame const *frame,
720 unsigned int nch, unsigned int ns)
722 int sb;
723 unsigned int phase, ch, s, p;
724 mad_fixed_t *pcm, (*filter)[2][2][16][8];
725 mad_fixed_t (*sbsample)[36][32];
726 mad_fixed_t (*fe)[8], (*fx)[8], (*fo)[8];
727 mad_fixed_t const (*D0ptr)[32];
728 mad_fixed_t const (*D1ptr)[32];
729 mad_fixed64hi_t hi0, hi1;
731 for (ch = 0; ch < nch; ++ch) {
732 sbsample = &(*frame->sbsample_prev)[ch];
733 filter = &synth->filter[ch];
734 phase = synth->phase;
735 pcm = synth->pcm.samples[ch];
737 for (s = 0; s < ns; ++s) {
738 dct32((*sbsample)[s], phase >> 1,
739 (*filter)[0][phase & 1], (*filter)[1][phase & 1]);
741 p = (phase - 1) & 0xf;
743 /* calculate 32 samples */
744 fe = &(*filter)[0][ phase & 1][0];
745 fx = &(*filter)[0][~phase & 1][0];
746 fo = &(*filter)[1][~phase & 1][0];
748 D0ptr = (void*)&D[0][ p];
749 D1ptr = (void*)&D[0][-p];
751 if(s & 1)
753 SYNTH_EMAC2(hi0, fx, fe, D0ptr);
754 pcm[0] = hi0 << 3; /* shift result to libmad's fixed point format */
755 pcm += 16;
757 for (sb = 15; sb; sb--, fo++) {
758 ++fe;
759 ++D0ptr;
760 ++D1ptr;
762 /* D[32 - sb][i] == -D[sb][31 - i] */
763 SYNTH_EMAC_ODD_SBSAMPLE(fo, fe, D0ptr, D1ptr, hi0, hi1);
764 pcm[-sb] = hi0 << 3;
765 pcm[ sb] = hi1 << 3;
768 ++D0ptr;
769 SYNTH_EMAC1(hi0, fo, D0ptr+1);
770 pcm[0] = -(hi0 << 3);
772 else
774 SYNTH_EMAC2(hi0, fe, fx, D0ptr);
775 pcm[0] = -(hi0 << 3); /* shift result to libmad's fixed point format */
776 pcm += 16;
778 for (sb = 15; sb; sb--, fo++) {
779 ++fe;
780 ++D0ptr;
781 ++D1ptr;
783 /* D[32 - sb][i] == -D[sb][31 - i] */
784 SYNTH_EMAC_EVEN_SBSAMPLE(fo, fe, D0ptr, D1ptr, hi0, hi1);
785 pcm[-sb] = hi0 << 3;
786 pcm[ sb] = hi1 << 3;
789 ++D0ptr;
790 SYNTH_EMAC1(hi0, fo, D0ptr);
791 pcm[0] = -(hi0 << 3);
793 pcm += 16;
794 phase = (phase + 1) % 16;
799 #elif defined(FPM_ARM)
801 #define PROD_O(hi, lo, f, ptr) \
802 ({ \
803 mad_fixed_t *__p = (f); \
804 asm volatile ( \
805 "ldmia %2!, {r0, r1, r2, r3} \n\t" \
806 "ldr r4, [%3, #0] \n\t" \
807 "smull %0, %1, r0, r4 \n\t" \
808 "ldr r4, [%3, #56] \n\t" \
809 "smlal %0, %1, r1, r4 \n\t" \
810 "ldr r4, [%3, #48] \n\t" \
811 "smlal %0, %1, r2, r4 \n\t" \
812 "ldr r4, [%3, #40] \n\t" \
813 "smlal %0, %1, r3, r4 \n\t" \
814 "ldmia %2, {r0, r1, r2, r3} \n\t" \
815 "ldr r4, [%3, #32] \n\t" \
816 "smlal %0, %1, r0, r4 \n\t" \
817 "ldr r4, [%3, #24] \n\t" \
818 "smlal %0, %1, r1, r4 \n\t" \
819 "ldr r4, [%3, #16] \n\t" \
820 "smlal %0, %1, r2, r4 \n\t" \
821 "ldr r4, [%3, #8] \n\t" \
822 "smlal %0, %1, r3, r4 \n\t" \
823 : "=&r" (lo), "=&r" (hi), "+r" (__p) \
824 : "r" (ptr) \
825 : "r0", "r1", "r2", "r3", "r4", "memory"); \
828 #define PROD_A(hi, lo, f, ptr) \
829 ({ \
830 mad_fixed_t *__p = (f); \
831 asm volatile ( \
832 "ldmia %2!, {r0, r1, r2, r3} \n\t" \
833 "ldr r4, [%3, #0] \n\t" \
834 "smlal %0, %1, r0, r4 \n\t" \
835 "ldr r4, [%3, #56] \n\t" \
836 "smlal %0, %1, r1, r4 \n\t" \
837 "ldr r4, [%3, #48] \n\t" \
838 "smlal %0, %1, r2, r4 \n\t" \
839 "ldr r4, [%3, #40] \n\t" \
840 "smlal %0, %1, r3, r4 \n\t" \
841 "ldmia %2, {r0, r1, r2, r3} \n\t" \
842 "ldr r4, [%3, #32] \n\t" \
843 "smlal %0, %1, r0, r4 \n\t" \
844 "ldr r4, [%3, #24] \n\t" \
845 "smlal %0, %1, r1, r4 \n\t" \
846 "ldr r4, [%3, #16] \n\t" \
847 "smlal %0, %1, r2, r4 \n\t" \
848 "ldr r4, [%3, #8] \n\t" \
849 "smlal %0, %1, r3, r4 \n\t" \
850 : "+r" (lo), "+r" (hi), "+r" (__p) \
851 : "r" (ptr) \
852 : "r0", "r1", "r2", "r3", "r4", "memory"); \
855 void synth_full_odd_sbsample (mad_fixed_t *pcm,
856 mad_fixed_t (*fo)[8],
857 mad_fixed_t (*fe)[8],
858 mad_fixed_t const (*D0ptr)[32],
859 mad_fixed_t const (*D1ptr)[32]);
860 void synth_full_even_sbsample(mad_fixed_t *pcm,
861 mad_fixed_t (*fo)[8],
862 mad_fixed_t (*fe)[8],
863 mad_fixed_t const (*D0ptr)[32],
864 mad_fixed_t const (*D1ptr)[32]);
866 static
867 void synth_full(struct mad_synth *synth, struct mad_frame const *frame,
868 unsigned int nch, unsigned int ns) ICODE_ATTR_MPA_SYNTH;
869 static
870 void synth_full(struct mad_synth *synth, struct mad_frame const *frame,
871 unsigned int nch, unsigned int ns)
873 int p;
874 unsigned int phase, ch, s;
875 mad_fixed_t *pcm, (*filter)[2][2][16][8];
876 mad_fixed_t (*sbsample)[36][32];
877 mad_fixed_t (*fe)[8], (*fx)[8], (*fo)[8];
878 mad_fixed_t const (*D0ptr)[32], *ptr;
879 mad_fixed_t const (*D1ptr)[32];
880 mad_fixed64hi_t hi;
881 mad_fixed64lo_t lo;
883 for (ch = 0; ch < nch; ++ch) {
884 sbsample = &(*frame->sbsample_prev)[ch];
885 filter = &synth->filter[ch];
886 phase = synth->phase;
887 pcm = synth->pcm.samples[ch];
889 for (s = 0; s < ns; ++s) {
890 dct32((*sbsample)[s], phase >> 1,
891 (*filter)[0][phase & 1], (*filter)[1][phase & 1]);
893 p = (phase - 1) & 0xf;
895 /* calculate 32 samples */
896 fe = &(*filter)[0][ phase & 1][0];
897 fx = &(*filter)[0][~phase & 1][0];
898 fo = &(*filter)[1][~phase & 1][0];
900 D0ptr = (void*)&D[0][ p];
901 D1ptr = (void*)&D[0][-p];
903 if(s & 1)
905 ptr = *D0ptr;
906 PROD_O(hi, lo, *fx, ptr+1);
907 MLN(hi, lo);
908 PROD_A(hi, lo, *fe, ptr);
909 pcm[0] = SHIFT(MLZ(hi, lo));
910 pcm += 16;
912 synth_full_odd_sbsample(pcm, fo, fe, D0ptr, D1ptr);
913 D0ptr += 15;
914 D1ptr += 15;
915 fo += 15;
916 fe += 15;
918 ptr = *(D0ptr + 1);
919 PROD_O(hi, lo, *fo, ptr+1);
920 pcm[0] = SHIFT(-MLZ(hi, lo));
922 else
924 ptr = *D0ptr;
925 PROD_O(hi, lo, *fx, ptr);
926 MLN(hi, lo);
927 PROD_A(hi, lo, *fe, ptr+1);
928 pcm[0] = SHIFT(MLZ(hi, lo));
929 pcm += 16;
931 synth_full_even_sbsample(pcm, fo, fe, D0ptr, D1ptr);
932 D0ptr += 15;
933 D1ptr += 15;
934 fo += 15;
935 fe += 15;
937 ptr = *(D0ptr + 1);
938 PROD_O(hi, lo, *fo, ptr);
939 pcm[0] = SHIFT(-MLZ(hi, lo));
942 pcm += 16;
943 phase = (phase + 1) % 16;
948 # else /* not FPM_COLDFIRE_EMAC and not FPM_ARM */
950 #define PROD_O(hi, lo, f, ptr, offset) \
951 ML0(hi, lo, (*f)[0], ptr[ 0+offset]); \
952 MLA(hi, lo, (*f)[1], ptr[14+offset]); \
953 MLA(hi, lo, (*f)[2], ptr[12+offset]); \
954 MLA(hi, lo, (*f)[3], ptr[10+offset]); \
955 MLA(hi, lo, (*f)[4], ptr[ 8+offset]); \
956 MLA(hi, lo, (*f)[5], ptr[ 6+offset]); \
957 MLA(hi, lo, (*f)[6], ptr[ 4+offset]); \
958 MLA(hi, lo, (*f)[7], ptr[ 2+offset]);
960 #define PROD_A(hi, lo, f, ptr, offset) \
961 MLA(hi, lo, (*f)[0], ptr[ 0+offset]); \
962 MLA(hi, lo, (*f)[1], ptr[14+offset]); \
963 MLA(hi, lo, (*f)[2], ptr[12+offset]); \
964 MLA(hi, lo, (*f)[3], ptr[10+offset]); \
965 MLA(hi, lo, (*f)[4], ptr[ 8+offset]); \
966 MLA(hi, lo, (*f)[5], ptr[ 6+offset]); \
967 MLA(hi, lo, (*f)[6], ptr[ 4+offset]); \
968 MLA(hi, lo, (*f)[7], ptr[ 2+offset]);
970 #define PROD_SB(hi, lo, ptr, offset, first_idx, last_idx) \
971 ML0(hi, lo, (*fe)[0], ptr[first_idx]); \
972 MLA(hi, lo, (*fe)[1], ptr[16+offset]); \
973 MLA(hi, lo, (*fe)[2], ptr[18+offset]); \
974 MLA(hi, lo, (*fe)[3], ptr[20+offset]); \
975 MLA(hi, lo, (*fe)[4], ptr[22+offset]); \
976 MLA(hi, lo, (*fe)[5], ptr[24+offset]); \
977 MLA(hi, lo, (*fe)[6], ptr[26+offset]); \
978 MLA(hi, lo, (*fe)[7], ptr[28+offset]); \
979 MLA(hi, lo, (*fo)[7], ptr[29-offset]); \
980 MLA(hi, lo, (*fo)[6], ptr[27-offset]); \
981 MLA(hi, lo, (*fo)[5], ptr[25-offset]); \
982 MLA(hi, lo, (*fo)[4], ptr[23-offset]); \
983 MLA(hi, lo, (*fo)[3], ptr[21-offset]); \
984 MLA(hi, lo, (*fo)[2], ptr[19-offset]); \
985 MLA(hi, lo, (*fo)[1], ptr[17-offset]); \
986 MLA(hi, lo, (*fo)[0], ptr[last_idx ]);
988 static
989 void synth_full(struct mad_synth *synth, struct mad_frame const *frame,
990 unsigned int nch, unsigned int ns)
992 int p, sb;
993 unsigned int phase, ch, s;
994 mad_fixed_t *pcm, (*filter)[2][2][16][8];
995 mad_fixed_t (*sbsample)[36][32];
996 mad_fixed_t (*fe)[8], (*fx)[8], (*fo)[8];
997 mad_fixed_t const (*D0ptr)[32], *ptr;
998 mad_fixed_t const (*D1ptr)[32];
999 mad_fixed64hi_t hi;
1000 mad_fixed64lo_t lo;
1002 for (ch = 0; ch < nch; ++ch) {
1003 sbsample = &(*frame->sbsample_prev)[ch];
1004 filter = &synth->filter[ch];
1005 phase = synth->phase;
1006 pcm = synth->pcm.samples[ch];
1008 for (s = 0; s < ns; ++s) {
1009 dct32((*sbsample)[s], phase >> 1,
1010 (*filter)[0][phase & 1], (*filter)[1][phase & 1]);
1012 p = (phase - 1) & 0xf;
1014 /* calculate 32 samples */
1015 fe = &(*filter)[0][ phase & 1][0];
1016 fx = &(*filter)[0][~phase & 1][0];
1017 fo = &(*filter)[1][~phase & 1][0];
1019 D0ptr = (void*)&D[0][ p];
1020 D1ptr = (void*)&D[0][-p];
1022 if(s & 1)
1024 ptr = *D0ptr;
1025 PROD_O(hi, lo, fx, ptr, 1)
1026 MLN(hi, lo);
1027 PROD_A(hi, lo, fe, ptr, 0)
1028 pcm[0] = SHIFT(MLZ(hi, lo));
1029 pcm += 16;
1031 for (sb = 15; sb; sb--, fo++)
1033 ++fe;
1034 ++D0ptr;
1035 ++D1ptr;
1037 /* D[32 - sb][i] == -D[sb][31 - i] */
1038 ptr = *D0ptr;
1039 PROD_O(hi, lo, fo, ptr, 1)
1040 MLN(hi, lo);
1041 PROD_A(hi, lo, fe, ptr, 0)
1042 pcm[-sb] = SHIFT(MLZ(hi, lo));
1044 ptr = *D1ptr;
1045 PROD_SB(hi, lo, ptr, 1, 15, 30)
1046 pcm[sb] = SHIFT(MLZ(hi, lo));
1049 ptr = *(D0ptr + 1);
1050 PROD_O(hi, lo, fo, ptr, 1)
1051 pcm[0] = SHIFT(-MLZ(hi, lo));
1053 else
1055 ptr = *D0ptr;
1056 PROD_O(hi, lo, fx, ptr, 0)
1057 MLN(hi, lo);
1058 PROD_A(hi, lo, fe, ptr, 1)
1059 pcm[0] = SHIFT(MLZ(hi, lo));
1060 pcm += 16;
1062 for (sb = 15; sb; sb--, fo++)
1064 ++fe;
1065 ++D0ptr;
1066 ++D1ptr;
1068 /* D[32 - sb][i] == -D[sb][31 - i] */
1069 ptr = *D0ptr;
1070 PROD_O(hi, lo, fo, ptr, 0)
1071 MLN(hi, lo);
1072 PROD_A(hi, lo, fe, ptr, 1)
1073 pcm[-sb] = SHIFT(MLZ(hi, lo));
1075 ptr = *D1ptr;
1076 PROD_SB(hi, lo, ptr, 0, 30, 15)
1077 pcm[sb] = SHIFT(MLZ(hi, lo));
1080 ptr = *(D0ptr + 1);
1081 PROD_O(hi, lo, fo, ptr, 0)
1082 pcm[0] = SHIFT(-MLZ(hi, lo));
1085 pcm += 16;
1086 phase = (phase + 1) % 16;
1091 # endif
1092 # endif
1094 #if 0 /* rockbox: unused */
1096 * NAME: synth->half()
1097 * DESCRIPTION: perform half frequency PCM synthesis
1099 static
1100 void synth_half(struct mad_synth *synth, struct mad_frame const *frame,
1101 unsigned int nch, unsigned int ns)
1103 unsigned int phase, ch, s, sb, pe, po;
1104 mad_fixed_t *pcm1, *pcm2, (*filter)[2][2][16][8];
1105 mad_fixed_t (*sbsample)[36][32];
1106 register mad_fixed_t (*fe)[8], (*fx)[8], (*fo)[8];
1107 register mad_fixed_t const (*Dptr)[32], *ptr;
1108 register mad_fixed64hi_t hi;
1109 register mad_fixed64lo_t lo;
1111 for (ch = 0; ch < nch; ++ch) {
1112 sbsample = &(*frame->sbsample_prev)[ch];
1113 filter = &synth->filter[ch];
1114 phase = synth->phase;
1115 pcm1 = synth->pcm.samples[ch];
1117 for (s = 0; s < ns; ++s) {
1118 dct32((*sbsample)[s], phase >> 1,
1119 (*filter)[0][phase & 1], (*filter)[1][phase & 1]);
1121 pe = phase & ~1;
1122 po = ((phase - 1) & 0xf) | 1;
1124 /* calculate 16 samples */
1126 fe = &(*filter)[0][ phase & 1][0];
1127 fx = &(*filter)[0][~phase & 1][0];
1128 fo = &(*filter)[1][~phase & 1][0];
1130 Dptr = &D[0];
1132 ptr = *Dptr + po;
1133 ML0(hi, lo, (*fx)[0], ptr[ 0]);
1134 MLA(hi, lo, (*fx)[1], ptr[14]);
1135 MLA(hi, lo, (*fx)[2], ptr[12]);
1136 MLA(hi, lo, (*fx)[3], ptr[10]);
1137 MLA(hi, lo, (*fx)[4], ptr[ 8]);
1138 MLA(hi, lo, (*fx)[5], ptr[ 6]);
1139 MLA(hi, lo, (*fx)[6], ptr[ 4]);
1140 MLA(hi, lo, (*fx)[7], ptr[ 2]);
1141 MLN(hi, lo);
1143 ptr = *Dptr + pe;
1144 MLA(hi, lo, (*fe)[0], ptr[ 0]);
1145 MLA(hi, lo, (*fe)[1], ptr[14]);
1146 MLA(hi, lo, (*fe)[2], ptr[12]);
1147 MLA(hi, lo, (*fe)[3], ptr[10]);
1148 MLA(hi, lo, (*fe)[4], ptr[ 8]);
1149 MLA(hi, lo, (*fe)[5], ptr[ 6]);
1150 MLA(hi, lo, (*fe)[6], ptr[ 4]);
1151 MLA(hi, lo, (*fe)[7], ptr[ 2]);
1153 *pcm1++ = SHIFT(MLZ(hi, lo));
1155 pcm2 = pcm1 + 14;
1157 for (sb = 1; sb < 16; ++sb) {
1158 ++fe;
1159 ++Dptr;
1161 /* D[32 - sb][i] == -D[sb][31 - i] */
1163 if (!(sb & 1)) {
1164 ptr = *Dptr + po;
1165 ML0(hi, lo, (*fo)[0], ptr[ 0]);
1166 MLA(hi, lo, (*fo)[1], ptr[14]);
1167 MLA(hi, lo, (*fo)[2], ptr[12]);
1168 MLA(hi, lo, (*fo)[3], ptr[10]);
1169 MLA(hi, lo, (*fo)[4], ptr[ 8]);
1170 MLA(hi, lo, (*fo)[5], ptr[ 6]);
1171 MLA(hi, lo, (*fo)[6], ptr[ 4]);
1172 MLA(hi, lo, (*fo)[7], ptr[ 2]);
1173 MLN(hi, lo);
1175 ptr = *Dptr + pe;
1176 MLA(hi, lo, (*fe)[7], ptr[ 2]);
1177 MLA(hi, lo, (*fe)[6], ptr[ 4]);
1178 MLA(hi, lo, (*fe)[5], ptr[ 6]);
1179 MLA(hi, lo, (*fe)[4], ptr[ 8]);
1180 MLA(hi, lo, (*fe)[3], ptr[10]);
1181 MLA(hi, lo, (*fe)[2], ptr[12]);
1182 MLA(hi, lo, (*fe)[1], ptr[14]);
1183 MLA(hi, lo, (*fe)[0], ptr[ 0]);
1185 *pcm1++ = SHIFT(MLZ(hi, lo));
1187 ptr = *Dptr - po;
1188 ML0(hi, lo, (*fo)[7], ptr[31 - 2]);
1189 MLA(hi, lo, (*fo)[6], ptr[31 - 4]);
1190 MLA(hi, lo, (*fo)[5], ptr[31 - 6]);
1191 MLA(hi, lo, (*fo)[4], ptr[31 - 8]);
1192 MLA(hi, lo, (*fo)[3], ptr[31 - 10]);
1193 MLA(hi, lo, (*fo)[2], ptr[31 - 12]);
1194 MLA(hi, lo, (*fo)[1], ptr[31 - 14]);
1195 MLA(hi, lo, (*fo)[0], ptr[31 - 16]);
1197 ptr = *Dptr - pe;
1198 MLA(hi, lo, (*fe)[0], ptr[31 - 16]);
1199 MLA(hi, lo, (*fe)[1], ptr[31 - 14]);
1200 MLA(hi, lo, (*fe)[2], ptr[31 - 12]);
1201 MLA(hi, lo, (*fe)[3], ptr[31 - 10]);
1202 MLA(hi, lo, (*fe)[4], ptr[31 - 8]);
1203 MLA(hi, lo, (*fe)[5], ptr[31 - 6]);
1204 MLA(hi, lo, (*fe)[6], ptr[31 - 4]);
1205 MLA(hi, lo, (*fe)[7], ptr[31 - 2]);
1207 *pcm2-- = SHIFT(MLZ(hi, lo));
1210 ++fo;
1213 ++Dptr;
1215 ptr = *Dptr + po;
1216 ML0(hi, lo, (*fo)[0], ptr[ 0]);
1217 MLA(hi, lo, (*fo)[1], ptr[14]);
1218 MLA(hi, lo, (*fo)[2], ptr[12]);
1219 MLA(hi, lo, (*fo)[3], ptr[10]);
1220 MLA(hi, lo, (*fo)[4], ptr[ 8]);
1221 MLA(hi, lo, (*fo)[5], ptr[ 6]);
1222 MLA(hi, lo, (*fo)[6], ptr[ 4]);
1223 MLA(hi, lo, (*fo)[7], ptr[ 2]);
1225 *pcm1 = SHIFT(-MLZ(hi, lo));
1226 pcm1 += 8;
1228 phase = (phase + 1) % 16;
1232 #endif /* unused */
1235 * NAME: synth->frame()
1236 * DESCRIPTION: perform PCM synthesis of frame subband samples
1238 void mad_synth_frame(struct mad_synth *synth, struct mad_frame const *frame)
1240 unsigned int nch, ns;
1241 #if 0 /* rockbox: unused */
1242 void (*synth_frame)(struct mad_synth *, struct mad_frame const *,
1243 unsigned int, unsigned int);
1244 #endif
1246 nch = MAD_NCHANNELS(&frame->header);
1247 ns = MAD_NSBSAMPLES(&frame->header);
1249 synth->pcm.samplerate = frame->header.samplerate;
1250 synth->pcm.channels = nch;
1251 synth->pcm.length = 32 * ns;
1253 #if 0 /* rockbox: unused */
1254 synth_frame = synth_full;
1256 if (frame->options & MAD_OPTION_HALFSAMPLERATE) {
1257 synth->pcm.samplerate /= 2;
1258 synth->pcm.length /= 2;
1260 synth_frame = synth_half;
1263 synth_frame(synth, frame, nch, ns);
1264 #else
1265 synth_full(synth, frame, nch, ns);
1266 #endif
1268 synth->phase = (synth->phase + ns) % 16;