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
34 * DESCRIPTION: initialize synth struct
36 void mad_synth_init(struct mad_synth
*synth
)
38 mad_synth_mute(synth
);
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
);
54 * DESCRIPTION: zero all polyphase filterbank values, resetting synthesis
56 void mad_synth_mute(struct mad_synth
*synth
)
58 unsigned int ch
, s
, v
;
60 for (ch
= 0; ch
< 2; ++ch
) {
61 for (s
= 0; s
< 16; ++s
) {
62 for (v
= 0; v
< 8; ++v
) {
63 synth
->filter
[ch
][0][0][s
][v
] = synth
->filter
[ch
][0][1][s
][v
] =
64 synth
->filter
[ch
][1][0][s
][v
] = synth
->filter
[ch
][1][1][s
][v
] = 0;
70 #if 0 /* dct32 asm implementation is slower on current arm systems */
73 void dct32(mad_fixed_t
const in
[32], unsigned int slot
,
74 mad_fixed_t lo
[16][8], mad_fixed_t hi
[16][8]);
79 * An optional optimization called here the Subband Synthesis Optimization
80 * (SSO) improves the performance of subband synthesis at the expense of
83 * The idea is to simplify 32x32->64-bit multiplication to 32x32->32 such
84 * that extra scaling and rounding are not necessary. This often allows the
85 * compiler to use faster 32-bit multiply-accumulate instructions instead of
86 * explicit 64-bit multiply, shift, and add instructions.
88 * SSO works like this: a full 32x32->64-bit multiply of two mad_fixed_t
89 * values requires the result to be right-shifted 28 bits to be properly
90 * scaled to the same fixed-point format. Right shifts can be applied at any
91 * time to either operand or to the result, so the optimization involves
92 * careful placement of these shifts to minimize the loss of accuracy.
94 * First, a 14-bit shift is applied with rounding at compile-time to the D[]
95 * table of coefficients for the subband synthesis window. This only loses 2
96 * bits of accuracy because the lower 12 bits are always zero. A second
97 * 12-bit shift occurs after the DCT calculation. This loses 12 bits of
98 * accuracy. Finally, a third 2-bit shift occurs just before the sample is
99 * saved in the PCM buffer. 14 + 12 + 2 == 28 bits.
102 /* FPM_DEFAULT without OPT_SSO will actually lose accuracy and performance */
104 # if defined(FPM_DEFAULT) && !defined(OPT_SSO)
108 /* second SSO shift, with rounding */
110 # if defined(OPT_SSO)
111 # define SHIFT(x) (((x) + (1L << 11)) >> 12)
113 # define SHIFT(x) (x)
116 /* possible DCT speed optimization */
118 /* This is a Coldfire version of the OPT_SPEED optimisation below, but in the
119 case of Coldfire it doesn't lose any more precision than we would ordinarily
121 # ifdef FPM_COLDFIRE_EMAC
125 mad_fixed64hi_t hi; \
126 asm volatile("mac.l %[a], %[b], %%acc0\n\t" \
127 "movclr.l %%acc0, %[hi]" \
129 : [a] "r" ((x)), [b] "r" ((y))); \
132 # elif defined(OPT_SPEED) && defined(MAD_F_MLX)
135 ({ mad_fixed64hi_t hi; \
136 mad_fixed64lo_t lo; \
137 MAD_F_MLX(hi, lo, (x), (y)); \
138 hi << (32 - MAD_F_SCALEBITS - 3); \
142 # define MUL(x, y) mad_f_mul((x), (y))
147 * DESCRIPTION: perform fast in[32]->out[32] DCT
150 void dct32(mad_fixed_t
const in
[32], unsigned int slot
,
151 mad_fixed_t lo
[16][8], mad_fixed_t hi
[16][8])
153 mad_fixed_t t0
, t1
, t2
, t3
, t4
, t5
, t6
, t7
;
154 mad_fixed_t t8
, t9
, t10
, t11
, t12
, t13
, t14
, t15
;
155 mad_fixed_t t16
, t17
, t18
, t19
, t20
, t21
, t22
, t23
;
156 mad_fixed_t t24
, t25
, t26
, t27
, t28
, t29
, t30
, t31
;
157 mad_fixed_t t32
, t33
, t34
, t35
, t36
, t37
, t38
, t39
;
158 mad_fixed_t t40
, t41
, t42
, t43
, t44
, t45
, t46
, t47
;
159 mad_fixed_t t48
, t49
, t50
, t51
, t52
, t53
, t54
, t55
;
160 mad_fixed_t t56
, t57
, t58
, t59
, t60
, t61
, t62
, t63
;
161 mad_fixed_t t64
, t65
, t66
, t67
, t68
, t69
, t70
, t71
;
162 mad_fixed_t t72
, t73
, t74
, t75
, t76
, t77
, t78
, t79
;
163 mad_fixed_t t80
, t81
, t82
, t83
, t84
, t85
, t86
, t87
;
164 mad_fixed_t t88
, t89
, t90
, t91
, t92
, t93
, t94
, t95
;
165 mad_fixed_t t96
, t97
, t98
, t99
, t100
, t101
, t102
, t103
;
166 mad_fixed_t t104
, t105
, t106
, t107
, t108
, t109
, t110
, t111
;
167 mad_fixed_t t112
, t113
, t114
, t115
, t116
, t117
, t118
, t119
;
168 mad_fixed_t t120
, t121
, t122
, t123
, t124
, t125
, t126
, t127
;
169 mad_fixed_t t128
, t129
, t130
, t131
, t132
, t133
, t134
, t135
;
170 mad_fixed_t t136
, t137
, t138
, t139
, t140
, t141
, t142
, t143
;
171 mad_fixed_t t144
, t145
, t146
, t147
, t148
, t149
, t150
, t151
;
172 mad_fixed_t t152
, t153
, t154
, t155
, t156
, t157
, t158
, t159
;
173 mad_fixed_t t160
, t161
, t162
, t163
, t164
, t165
, t166
, t167
;
174 mad_fixed_t t168
, t169
, t170
, t171
, t172
, t173
, t174
, t175
;
177 /* costab[i] = cos(PI / (2 * 32) * i) */
179 # if defined(OPT_DCTO)
180 # define costab1 MAD_F(0x7fd8878e)
181 # define costab2 MAD_F(0x7f62368f)
182 # define costab3 MAD_F(0x7e9d55fc)
183 # define costab4 MAD_F(0x7d8a5f40)
184 # define costab5 MAD_F(0x7c29fbee)
185 # define costab6 MAD_F(0x7a7d055b)
186 # define costab7 MAD_F(0x78848414)
187 # define costab8 MAD_F(0x7641af3d)
188 # define costab9 MAD_F(0x73b5ebd1)
189 # define costab10 MAD_F(0x70e2cbc6)
190 # define costab11 MAD_F(0x6dca0d14)
191 # define costab12 MAD_F(0x6a5d98a4)
192 # define costab13 MAD_F(0x66cf8120)
193 # define costab14 MAD_F(0x62f201ac)
194 # define costab15 MAD_F(0x5ed77c8a)
195 # define costab16 MAD_F(0x5a82799a)
196 # define costab17 MAD_F(0x55f5a4d2)
197 # define costab18 MAD_F(0x5133cc94)
198 # define costab19 MAD_F(0x4c3fdff4)
199 # define costab20 MAD_F(0x471cece7)
200 # define costab21 MAD_F(0x41ce1e65)
201 # define costab22 MAD_F(0x3c56ba70)
202 # define costab23 MAD_F(0x36ba2014)
203 # define costab24 MAD_F(0x30fbc54d)
204 # define costab25 MAD_F(0x2b1f34eb)
205 # define costab26 MAD_F(0x25280c5e)
206 # define costab27 MAD_F(0x1f19f97b)
207 # define costab28 MAD_F(0x18f8b83c)
208 # define costab29 MAD_F(0x12c8106f)
209 # define costab30 MAD_F(0x0c8bd35e)
210 # define costab31 MAD_F(0x0647d97c)
212 # define costab1 MAD_F(0x0ffb10f2) /* 0.998795456 */
213 # define costab2 MAD_F(0x0fec46d2) /* 0.995184727 */
214 # define costab3 MAD_F(0x0fd3aac0) /* 0.989176510 */
215 # define costab4 MAD_F(0x0fb14be8) /* 0.980785280 */
216 # define costab5 MAD_F(0x0f853f7e) /* 0.970031253 */
217 # define costab6 MAD_F(0x0f4fa0ab) /* 0.956940336 */
218 # define costab7 MAD_F(0x0f109082) /* 0.941544065 */
219 # define costab8 MAD_F(0x0ec835e8) /* 0.923879533 */
220 # define costab9 MAD_F(0x0e76bd7a) /* 0.903989293 */
221 # define costab10 MAD_F(0x0e1c5979) /* 0.881921264 */
222 # define costab11 MAD_F(0x0db941a3) /* 0.857728610 */
223 # define costab12 MAD_F(0x0d4db315) /* 0.831469612 */
224 # define costab13 MAD_F(0x0cd9f024) /* 0.803207531 */
225 # define costab14 MAD_F(0x0c5e4036) /* 0.773010453 */
226 # define costab15 MAD_F(0x0bdaef91) /* 0.740951125 */
227 # define costab16 MAD_F(0x0b504f33) /* 0.707106781 */
228 # define costab17 MAD_F(0x0abeb49a) /* 0.671558955 */
229 # define costab18 MAD_F(0x0a267993) /* 0.634393284 */
230 # define costab19 MAD_F(0x0987fbfe) /* 0.595699304 */
231 # define costab20 MAD_F(0x08e39d9d) /* 0.555570233 */
232 # define costab21 MAD_F(0x0839c3cd) /* 0.514102744 */
233 # define costab22 MAD_F(0x078ad74e) /* 0.471396737 */
234 # define costab23 MAD_F(0x06d74402) /* 0.427555093 */
235 # define costab24 MAD_F(0x061f78aa) /* 0.382683432 */
236 # define costab25 MAD_F(0x0563e69d) /* 0.336889853 */
237 # define costab26 MAD_F(0x04a5018c) /* 0.290284677 */
238 # define costab27 MAD_F(0x03e33f2f) /* 0.242980180 */
239 # define costab28 MAD_F(0x031f1708) /* 0.195090322 */
240 # define costab29 MAD_F(0x0259020e) /* 0.146730474 */
241 # define costab30 MAD_F(0x01917a5c) /* 0.098017140 */
242 # define costab31 MAD_F(0x00c8fb30) /* 0.049067674 */
245 t0
= in
[0] + in
[31]; t16
= MUL(in
[0] - in
[31], costab1
);
246 t1
= in
[15] + in
[16]; t17
= MUL(in
[15] - in
[16], costab31
);
249 t59
= MUL(t16
- t17
, costab2
);
251 t50
= MUL(t0
- t1
, costab2
);
253 t2
= in
[7] + in
[24]; t18
= MUL(in
[7] - in
[24], costab15
);
254 t3
= in
[8] + in
[23]; t19
= MUL(in
[8] - in
[23], costab17
);
257 t60
= MUL(t18
- t19
, costab30
);
259 t51
= MUL(t2
- t3
, costab30
);
261 t4
= in
[3] + in
[28]; t20
= MUL(in
[3] - in
[28], costab7
);
262 t5
= in
[12] + in
[19]; t21
= MUL(in
[12] - in
[19], costab25
);
265 t61
= MUL(t20
- t21
, costab14
);
267 t52
= MUL(t4
- t5
, costab14
);
269 t6
= in
[4] + in
[27]; t22
= MUL(in
[4] - in
[27], costab9
);
270 t7
= in
[11] + in
[20]; t23
= MUL(in
[11] - in
[20], costab23
);
273 t62
= MUL(t22
- t23
, costab18
);
275 t53
= MUL(t6
- t7
, costab18
);
277 t8
= in
[1] + in
[30]; t24
= MUL(in
[1] - in
[30], costab3
);
278 t9
= in
[14] + in
[17]; t25
= MUL(in
[14] - in
[17], costab29
);
281 t63
= MUL(t24
- t25
, costab6
);
283 t54
= MUL(t8
- t9
, costab6
);
285 t10
= in
[6] + in
[25]; t26
= MUL(in
[6] - in
[25], costab13
);
286 t11
= in
[9] + in
[22]; t27
= MUL(in
[9] - in
[22], costab19
);
289 t64
= MUL(t26
- t27
, costab26
);
291 t55
= MUL(t10
- t11
, costab26
);
293 t12
= in
[2] + in
[29]; t28
= MUL(in
[2] - in
[29], costab5
);
294 t13
= in
[13] + in
[18]; t29
= MUL(in
[13] - in
[18], costab27
);
297 t65
= MUL(t28
- t29
, costab10
);
299 t56
= MUL(t12
- t13
, costab10
);
301 t14
= in
[5] + in
[26]; t30
= MUL(in
[5] - in
[26], costab11
);
302 t15
= in
[10] + in
[21]; t31
= MUL(in
[10] - in
[21], costab21
);
305 t66
= MUL(t30
- t31
, costab22
);
307 t57
= MUL(t14
- t15
, costab22
);
309 t69
= t33
+ t34
; t89
= MUL(t33
- t34
, costab4
);
310 t70
= t35
+ t36
; t90
= MUL(t35
- t36
, costab28
);
311 t71
= t37
+ t38
; t91
= MUL(t37
- t38
, costab12
);
312 t72
= t39
+ t40
; t92
= MUL(t39
- t40
, costab20
);
313 t73
= t41
+ t42
; t94
= MUL(t41
- t42
, costab4
);
314 t74
= t43
+ t44
; t95
= MUL(t43
- t44
, costab28
);
315 t75
= t45
+ t46
; t96
= MUL(t45
- t46
, costab12
);
316 t76
= t47
+ t48
; t97
= MUL(t47
- t48
, costab20
);
318 t78
= t50
+ t51
; t100
= MUL(t50
- t51
, costab4
);
319 t79
= t52
+ t53
; t101
= MUL(t52
- t53
, costab28
);
320 t80
= t54
+ t55
; t102
= MUL(t54
- t55
, costab12
);
321 t81
= t56
+ t57
; t103
= MUL(t56
- t57
, costab20
);
323 t83
= t59
+ t60
; t106
= MUL(t59
- t60
, costab4
);
324 t84
= t61
+ t62
; t107
= MUL(t61
- t62
, costab28
);
325 t85
= t63
+ t64
; t108
= MUL(t63
- t64
, costab12
);
326 t86
= t65
+ t66
; t109
= MUL(t65
- t66
, costab20
);
331 /* 0 */ hi
[15][slot
] = SHIFT(t113
+ t114
);
332 /* 16 */ lo
[ 0][slot
] = SHIFT(MUL(t113
- t114
, costab16
));
339 /* 1 */ hi
[14][slot
] = SHIFT(t32
);
346 /* 2 */ hi
[13][slot
] = SHIFT(t58
);
353 t49
= (t67
* 2) - t32
;
355 /* 3 */ hi
[12][slot
] = SHIFT(t49
);
362 /* 4 */ hi
[11][slot
] = SHIFT(t93
);
369 t68
= (t98
* 2) - t49
;
371 /* 5 */ hi
[10][slot
] = SHIFT(t68
);
378 t82
= (t104
* 2) - t58
;
380 /* 6 */ hi
[ 9][slot
] = SHIFT(t82
);
387 t87
= (t110
* 2) - t67
;
389 t77
= (t87
* 2) - t68
;
391 /* 7 */ hi
[ 8][slot
] = SHIFT(t77
);
393 t141
= MUL(t69
- t70
, costab8
);
394 t142
= MUL(t71
- t72
, costab24
);
397 /* 8 */ hi
[ 7][slot
] = SHIFT(t143
);
398 /* 24 */ lo
[ 8][slot
] =
399 SHIFT((MUL(t141
- t142
, costab16
) * 2) - t143
);
401 t144
= MUL(t73
- t74
, costab8
);
402 t145
= MUL(t75
- t76
, costab24
);
405 t88
= (t146
* 2) - t77
;
407 /* 9 */ hi
[ 6][slot
] = SHIFT(t88
);
409 t148
= MUL(t78
- t79
, costab8
);
410 t149
= MUL(t80
- t81
, costab24
);
413 t105
= (t150
* 2) - t82
;
415 /* 10 */ hi
[ 5][slot
] = SHIFT(t105
);
417 t152
= MUL(t83
- t84
, costab8
);
418 t153
= MUL(t85
- t86
, costab24
);
421 t111
= (t154
* 2) - t87
;
423 t99
= (t111
* 2) - t88
;
425 /* 11 */ hi
[ 4][slot
] = SHIFT(t99
);
427 t157
= MUL(t89
- t90
, costab8
);
428 t158
= MUL(t91
- t92
, costab24
);
431 t127
= (t159
* 2) - t93
;
433 /* 12 */ hi
[ 3][slot
] = SHIFT(t127
);
435 t160
= (MUL(t125
- t126
, costab16
) * 2) - t127
;
437 /* 20 */ lo
[ 4][slot
] = SHIFT(t160
);
438 /* 28 */ lo
[12][slot
] =
439 SHIFT((((MUL(t157
- t158
, costab16
) * 2) - t159
) * 2) - t160
);
441 t161
= MUL(t94
- t95
, costab8
);
442 t162
= MUL(t96
- t97
, costab24
);
445 t130
= (t163
* 2) - t98
;
447 t112
= (t130
* 2) - t99
;
449 /* 13 */ hi
[ 2][slot
] = SHIFT(t112
);
451 t164
= (MUL(t128
- t129
, costab16
) * 2) - t130
;
453 t166
= MUL(t100
- t101
, costab8
);
454 t167
= MUL(t102
- t103
, costab24
);
457 t134
= (t168
* 2) - t104
;
459 t120
= (t134
* 2) - t105
;
461 /* 14 */ hi
[ 1][slot
] = SHIFT(t120
);
463 t135
= (MUL(t118
- t119
, costab16
) * 2) - t120
;
465 /* 18 */ lo
[ 2][slot
] = SHIFT(t135
);
467 t169
= (MUL(t132
- t133
, costab16
) * 2) - t134
;
469 t151
= (t169
* 2) - t135
;
471 /* 22 */ lo
[ 6][slot
] = SHIFT(t151
);
473 t170
= (((MUL(t148
- t149
, costab16
) * 2) - t150
) * 2) - t151
;
475 /* 26 */ lo
[10][slot
] = SHIFT(t170
);
476 /* 30 */ lo
[14][slot
] =
477 SHIFT((((((MUL(t166
- t167
, costab16
) * 2) -
478 t168
) * 2) - t169
) * 2) - t170
);
480 t171
= MUL(t106
- t107
, costab8
);
481 t172
= MUL(t108
- t109
, costab24
);
484 t138
= (t173
* 2) - t110
;
486 t123
= (t138
* 2) - t111
;
488 t139
= (MUL(t121
- t122
, costab16
) * 2) - t123
;
490 t117
= (t123
* 2) - t112
;
492 /* 15 */ hi
[ 0][slot
] = SHIFT(t117
);
494 t124
= (MUL(t115
- t116
, costab16
) * 2) - t117
;
496 /* 17 */ lo
[ 1][slot
] = SHIFT(t124
);
498 t131
= (t139
* 2) - t124
;
500 /* 19 */ lo
[ 3][slot
] = SHIFT(t131
);
502 t140
= (t164
* 2) - t131
;
504 /* 21 */ lo
[ 5][slot
] = SHIFT(t140
);
506 t174
= (MUL(t136
- t137
, costab16
) * 2) - t138
;
508 t155
= (t174
* 2) - t139
;
510 t147
= (t155
* 2) - t140
;
512 /* 23 */ lo
[ 7][slot
] = SHIFT(t147
);
514 t156
= (((MUL(t144
- t145
, costab16
) * 2) - t146
) * 2) - t147
;
516 /* 25 */ lo
[ 9][slot
] = SHIFT(t156
);
518 t175
= (((MUL(t152
- t153
, costab16
) * 2) - t154
) * 2) - t155
;
520 t165
= (t175
* 2) - t156
;
522 /* 27 */ lo
[11][slot
] = SHIFT(t165
);
524 t176
= (((((MUL(t161
- t162
, costab16
) * 2) -
525 t163
) * 2) - t164
) * 2) - t165
;
527 /* 29 */ lo
[13][slot
] = SHIFT(t176
);
528 /* 31 */ lo
[15][slot
] =
529 SHIFT((((((((MUL(t171
- t172
, costab16
) * 2) -
530 t173
) * 2) - t174
) * 2) - t175
) * 2) - t176
);
537 * 49 shifts (not counting SSO)
546 /* third SSO shift and/or D[] optimization preshift */
548 # if defined(OPT_SSO)
549 # if MAD_F_FRACBITS != 28
550 # error "MAD_F_FRACBITS must be 28 to use OPT_SSO"
552 # define ML0(hi, lo, x, y) ((lo) = (x) * (y))
553 # define MLA(hi, lo, x, y) ((lo) += (x) * (y))
554 # define MLN(hi, lo) ((lo) = -(lo))
555 # define MLZ(hi, lo) ((void) (hi), (mad_fixed_t) (lo))
556 # define SHIFT(x) ((x) >> 2)
557 # define PRESHIFT(x) ((MAD_F(x) + (1L << 13)) >> 14)
559 # define ML0(hi, lo, x, y) MAD_F_ML0((hi), (lo), (x), (y))
560 # define MLA(hi, lo, x, y) MAD_F_MLA((hi), (lo), (x), (y))
561 # define MLN(hi, lo) MAD_F_MLN((hi), (lo))
562 # define MLZ(hi, lo) MAD_F_MLZ((hi), (lo))
563 # define SHIFT(x) (x)
564 # if defined(MAD_F_SCALEBITS)
565 # undef MAD_F_SCALEBITS
566 # define MAD_F_SCALEBITS (MAD_F_FRACBITS - 12)
567 # define PRESHIFT(x) (MAD_F(x) >> 12)
569 # define PRESHIFT(x) MAD_F(x)
574 mad_fixed_t
const D
[17][32] ICONST_ATTR
= {
578 # if defined(ASO_SYNTH)
579 void synth_full(struct mad_synth
*, struct mad_frame
const *,
580 unsigned int, unsigned int);
583 * NAME: synth->full()
584 * DESCRIPTION: perform full frequency PCM synthesis
587 /* optimised version of synth_full */
588 # ifdef FPM_COLDFIRE_EMAC
590 void synth_full(struct mad_synth
*synth
, struct mad_frame
const *frame
,
591 unsigned int nch
, unsigned int ns
)
594 unsigned int phase
, ch
, s
, p
;
595 mad_fixed_t
*pcm
, (*filter
)[2][2][16][8];
596 mad_fixed_t (*sbsample
)[36][32];
597 mad_fixed_t (*fe
)[8], (*fx
)[8], (*fo
)[8];
598 mad_fixed_t
const (*D0ptr
)[32];
599 mad_fixed_t
const (*D1ptr
)[32];
600 mad_fixed64hi_t hi0
, hi1
;
602 for (ch
= 0; ch
< nch
; ++ch
) {
603 sbsample
= &(*frame
->sbsample_prev
)[ch
];
604 filter
= &synth
->filter
[ch
];
605 phase
= synth
->phase
;
606 pcm
= synth
->pcm
.samples
[ch
];
608 for (s
= 0; s
< ns
; ++s
) {
609 dct32((*sbsample
)[s
], phase
>> 1,
610 (*filter
)[0][phase
& 1], (*filter
)[1][phase
& 1]);
612 p
= (phase
- 1) & 0xf;
614 /* calculate 32 samples */
615 fe
= &(*filter
)[0][ phase
& 1][0];
616 fx
= &(*filter
)[0][~phase
& 1][0];
617 fo
= &(*filter
)[1][~phase
& 1][0];
619 D0ptr
= (void*)&D
[0][ p
];
620 D1ptr
= (void*)&D
[0][-p
];
625 "movem.l (%1), %%d0-%%d7\n\t"
626 "move.l 4(%2), %%a5\n\t"
627 "msac.l %%d0, %%a5, 60(%2), %%a5, %%acc0\n\t"
628 "msac.l %%d1, %%a5, 52(%2), %%a5, %%acc0\n\t"
629 "msac.l %%d2, %%a5, 44(%2), %%a5, %%acc0\n\t"
630 "msac.l %%d3, %%a5, 36(%2), %%a5, %%acc0\n\t"
631 "msac.l %%d4, %%a5, 28(%2), %%a5, %%acc0\n\t"
632 "msac.l %%d5, %%a5, 20(%2), %%a5, %%acc0\n\t"
633 "msac.l %%d6, %%a5, 12(%2), %%a5, %%acc0\n\t"
634 "msac.l %%d7, %%a5, (%2), %%a5, %%acc0\n\t"
636 "movem.l (%3), %%d0-%%d7\n\t"
637 "mac.l %%d0, %%a5, 56(%2), %%a5, %%acc0\n\t"
638 "mac.l %%d1, %%a5, 48(%2), %%a5, %%acc0\n\t"
639 "mac.l %%d2, %%a5, 40(%2), %%a5, %%acc0\n\t"
640 "mac.l %%d3, %%a5, 32(%2), %%a5, %%acc0\n\t"
641 "mac.l %%d4, %%a5, 24(%2), %%a5, %%acc0\n\t"
642 "mac.l %%d5, %%a5, 16(%2), %%a5, %%acc0\n\t"
643 "mac.l %%d6, %%a5, 8(%2), %%a5, %%acc0\n\t"
644 "mac.l %%d7, %%a5, %%acc0\n\t"
645 "movclr.l %%acc0, %0\n\t"
646 : "=r" (hi0
) : "a" (*fx
), "a" (*D0ptr
), "a" (*fe
)
647 : "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7", "a5");
649 pcm
[0] = hi0
<< 3; /* shift result to libmad's fixed point format */
652 for (sb
= 15; sb
; sb
--, fo
++) {
657 /* D[32 - sb][i] == -D[sb][31 - i] */
659 "movem.l (%0), %%d0-%%d7\n\t"
660 "move.l 4(%2), %%a5\n\t"
661 "msac.l %%d0, %%a5, 60(%2), %%a5, %%acc0\n\t"
662 "msac.l %%d1, %%a5, 52(%2), %%a5, %%acc0\n\t"
663 "msac.l %%d2, %%a5, 44(%2), %%a5, %%acc0\n\t"
664 "msac.l %%d3, %%a5, 36(%2), %%a5, %%acc0\n\t"
665 "msac.l %%d4, %%a5, 28(%2), %%a5, %%acc0\n\t"
666 "msac.l %%d5, %%a5, 20(%2), %%a5, %%acc0\n\t"
667 "msac.l %%d6, %%a5, 12(%2), %%a5, %%acc0\n\t"
668 "msac.l %%d7, %%a5, 112(%3), %%a5, %%acc0\n\t"
669 "mac.l %%d7, %%a5, 104(%3), %%a5, %%acc1\n\t"
670 "mac.l %%d6, %%a5, 96(%3), %%a5, %%acc1\n\t"
671 "mac.l %%d5, %%a5, 88(%3), %%a5, %%acc1\n\t"
672 "mac.l %%d4, %%a5, 80(%3), %%a5, %%acc1\n\t"
673 "mac.l %%d3, %%a5, 72(%3), %%a5, %%acc1\n\t"
674 "mac.l %%d2, %%a5, 64(%3), %%a5, %%acc1\n\t"
675 "mac.l %%d1, %%a5, 120(%3), %%a5, %%acc1\n\t"
676 "mac.l %%d0, %%a5, 8(%2), %%a5, %%acc1\n\t"
677 "movem.l (%1), %%d0-%%d7\n\t"
678 "mac.l %%d7, %%a5, 16(%2), %%a5, %%acc0\n\t"
679 "mac.l %%d6, %%a5, 24(%2), %%a5, %%acc0\n\t"
680 "mac.l %%d5, %%a5, 32(%2), %%a5, %%acc0\n\t"
681 "mac.l %%d4, %%a5, 40(%2), %%a5, %%acc0\n\t"
682 "mac.l %%d3, %%a5, 48(%2), %%a5, %%acc0\n\t"
683 "mac.l %%d2, %%a5, 56(%2), %%a5, %%acc0\n\t"
684 "mac.l %%d1, %%a5, (%2), %%a5, %%acc0\n\t"
685 "mac.l %%d0, %%a5, 60(%3), %%a5, %%acc0\n\t"
686 "mac.l %%d0, %%a5, 68(%3), %%a5, %%acc1\n\t"
687 "mac.l %%d1, %%a5, 76(%3), %%a5, %%acc1\n\t"
688 "mac.l %%d2, %%a5, 84(%3), %%a5, %%acc1\n\t"
689 "mac.l %%d3, %%a5, 92(%3), %%a5, %%acc1\n\t"
690 "mac.l %%d4, %%a5, 100(%3), %%a5, %%acc1\n\t"
691 "mac.l %%d5, %%a5, 108(%3), %%a5, %%acc1\n\t"
692 "mac.l %%d6, %%a5, 116(%3), %%a5, %%acc1\n\t"
693 "mac.l %%d7, %%a5, %%acc1\n\t"
694 : : "a" (*fo
), "a" (*fe
), "a" (*D0ptr
), "a" (*D1ptr
)
695 : "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7", "a5");
698 "movclr.l %%acc0, %0\n\t"
699 "movclr.l %%acc1, %1\n\t" : "=d" (hi0
), "=d" (hi1
) );
707 "movem.l (%1), %%d0-%%d7\n\t"
708 "move.l 4(%2), %%a5\n\t"
709 "mac.l %%d0, %%a5, 60(%2), %%a5, %%acc0\n\t"
710 "mac.l %%d1, %%a5, 52(%2), %%a5, %%acc0\n\t"
711 "mac.l %%d2, %%a5, 44(%2), %%a5, %%acc0\n\t"
712 "mac.l %%d3, %%a5, 36(%2), %%a5, %%acc0\n\t"
713 "mac.l %%d4, %%a5, 28(%2), %%a5, %%acc0\n\t"
714 "mac.l %%d5, %%a5, 20(%2), %%a5, %%acc0\n\t"
715 "mac.l %%d6, %%a5, 12(%2), %%a5, %%acc0\n\t"
716 "mac.l %%d7, %%a5, %%acc0\n\t"
717 "movclr.l %%acc0, %0\n\t"
718 : "=r" (hi0
) : "a" (*fo
), "a" (*D0ptr
)
719 : "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7", "a5");
721 pcm
[0] = -(hi0
<< 3);
726 "movem.l (%1), %%d0-%%d7\n\t"
727 "move.l (%2), %%a5\n\t"
728 "msac.l %%d0, %%a5, 56(%2), %%a5, %%acc0\n\t"
729 "msac.l %%d1, %%a5, 48(%2), %%a5, %%acc0\n\t"
730 "msac.l %%d2, %%a5, 40(%2), %%a5, %%acc0\n\t"
731 "msac.l %%d3, %%a5, 32(%2), %%a5, %%acc0\n\t"
732 "msac.l %%d4, %%a5, 24(%2), %%a5, %%acc0\n\t"
733 "msac.l %%d5, %%a5, 16(%2), %%a5, %%acc0\n\t"
734 "msac.l %%d6, %%a5, 8(%2), %%a5, %%acc0\n\t"
735 "msac.l %%d7, %%a5, 4(%2), %%a5, %%acc0\n\t"
737 "movem.l (%3), %%d0-%%d7\n\t"
738 "mac.l %%d0, %%a5, 60(%2), %%a5, %%acc0\n\t"
739 "mac.l %%d1, %%a5, 52(%2), %%a5, %%acc0\n\t"
740 "mac.l %%d2, %%a5, 44(%2), %%a5, %%acc0\n\t"
741 "mac.l %%d3, %%a5, 36(%2), %%a5, %%acc0\n\t"
742 "mac.l %%d4, %%a5, 28(%2), %%a5, %%acc0\n\t"
743 "mac.l %%d5, %%a5, 20(%2), %%a5, %%acc0\n\t"
744 "mac.l %%d6, %%a5, 12(%2), %%a5, %%acc0\n\t"
745 "mac.l %%d7, %%a5, %%acc0\n\t"
746 "movclr.l %%acc0, %0\n\t"
747 : "=r" (hi0
) : "a" (*fx
), "a" (*D0ptr
), "a" (*fe
)
748 : "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7", "a5");
750 pcm
[0] = hi0
<< 3; /* shift result to libmad's fixed point format */
753 for (sb
= 15; sb
; sb
--, fo
++) {
758 /* D[32 - sb][i] == -D[sb][31 - i] */
760 "movem.l (%0), %%d0-%%d7\n\t"
761 "move.l (%2), %%a5\n\t"
762 "msac.l %%d0, %%a5, 56(%2), %%a5, %%acc0\n\t"
763 "msac.l %%d1, %%a5, 48(%2), %%a5, %%acc0\n\t"
764 "msac.l %%d2, %%a5, 40(%2), %%a5, %%acc0\n\t"
765 "msac.l %%d3, %%a5, 32(%2), %%a5, %%acc0\n\t"
766 "msac.l %%d4, %%a5, 24(%2), %%a5, %%acc0\n\t"
767 "msac.l %%d5, %%a5, 16(%2), %%a5, %%acc0\n\t"
768 "msac.l %%d6, %%a5, 8(%2), %%a5, %%acc0\n\t"
769 "msac.l %%d7, %%a5, 116(%3), %%a5, %%acc0\n\t"
770 "mac.l %%d7, %%a5, 108(%3), %%a5, %%acc1\n\t"
771 "mac.l %%d6, %%a5, 100(%3), %%a5, %%acc1\n\t"
772 "mac.l %%d5, %%a5, 92(%3), %%a5, %%acc1\n\t"
773 "mac.l %%d4, %%a5, 84(%3), %%a5, %%acc1\n\t"
774 "mac.l %%d3, %%a5, 76(%3), %%a5, %%acc1\n\t"
775 "mac.l %%d2, %%a5, 68(%3), %%a5, %%acc1\n\t"
776 "mac.l %%d1, %%a5, 60(%3), %%a5, %%acc1\n\t"
777 "mac.l %%d0, %%a5, 12(%2), %%a5, %%acc1\n\t"
778 "movem.l (%1), %%d0-%%d7\n\t"
779 "mac.l %%d7, %%a5, 20(%2), %%a5, %%acc0\n\t"
780 "mac.l %%d6, %%a5, 28(%2), %%a5, %%acc0\n\t"
781 "mac.l %%d5, %%a5, 36(%2), %%a5, %%acc0\n\t"
782 "mac.l %%d4, %%a5, 44(%2), %%a5, %%acc0\n\t"
783 "mac.l %%d3, %%a5, 52(%2), %%a5, %%acc0\n\t"
784 "mac.l %%d2, %%a5, 60(%2), %%a5, %%acc0\n\t"
785 "mac.l %%d1, %%a5, 4(%2), %%a5, %%acc0\n\t"
786 "mac.l %%d0, %%a5, 120(%3), %%a5, %%acc0\n\t"
787 "mac.l %%d0, %%a5, 64(%3), %%a5, %%acc1\n\t"
788 "mac.l %%d1, %%a5, 72(%3), %%a5, %%acc1\n\t"
789 "mac.l %%d2, %%a5, 80(%3), %%a5, %%acc1\n\t"
790 "mac.l %%d3, %%a5, 88(%3), %%a5, %%acc1\n\t"
791 "mac.l %%d4, %%a5, 96(%3), %%a5, %%acc1\n\t"
792 "mac.l %%d5, %%a5, 104(%3), %%a5, %%acc1\n\t"
793 "mac.l %%d6, %%a5, 112(%3), %%a5, %%acc1\n\t"
794 "mac.l %%d7, %%a5, %%acc1\n\t"
795 : : "a" (*fo
), "a" (*fe
), "a" (*D0ptr
), "a" (*D1ptr
)
796 : "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7", "a5");
799 "movclr.l %%acc0, %0\n\t"
800 "movclr.l %%acc1, %1\n\t" : "=d" (hi0
), "=d" (hi1
) );
808 "movem.l (%1), %%d0-%%d7\n\t"
809 "move.l (%2), %%a5\n\t"
810 "mac.l %%d0, %%a5, 56(%2), %%a5, %%acc0\n\t"
811 "mac.l %%d1, %%a5, 48(%2), %%a5, %%acc0\n\t"
812 "mac.l %%d2, %%a5, 40(%2), %%a5, %%acc0\n\t"
813 "mac.l %%d3, %%a5, 32(%2), %%a5, %%acc0\n\t"
814 "mac.l %%d4, %%a5, 24(%2), %%a5, %%acc0\n\t"
815 "mac.l %%d5, %%a5, 16(%2), %%a5, %%acc0\n\t"
816 "mac.l %%d6, %%a5, 8(%2), %%a5, %%acc0\n\t"
817 "mac.l %%d7, %%a5, %%acc0\n\t"
818 "movclr.l %%acc0, %0\n\t"
819 : "=r" (hi0
) : "a" (*fo
), "a" (*D0ptr
)
820 : "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7", "a5");
822 pcm
[0] = -(hi0
<< 3);
825 phase
= (phase
+ 1) % 16;
830 #elif defined(FPM_ARM)
832 #define PROD_O(hi, lo, f, ptr) \
834 mad_fixed_t *__p = (f); \
836 "ldmia %2!, {r0, r1, r2, r3} \n\t" \
837 "ldr r4, [%3, #0] \n\t" \
838 "smull %0, %1, r0, r4 \n\t" \
839 "ldr r4, [%3, #56] \n\t" \
840 "smlal %0, %1, r1, r4 \n\t" \
841 "ldr r4, [%3, #48] \n\t" \
842 "smlal %0, %1, r2, r4 \n\t" \
843 "ldr r4, [%3, #40] \n\t" \
844 "smlal %0, %1, r3, r4 \n\t" \
845 "ldmia %2, {r0, r1, r2, r3} \n\t" \
846 "ldr r4, [%3, #32] \n\t" \
847 "smlal %0, %1, r0, r4 \n\t" \
848 "ldr r4, [%3, #24] \n\t" \
849 "smlal %0, %1, r1, r4 \n\t" \
850 "ldr r4, [%3, #16] \n\t" \
851 "smlal %0, %1, r2, r4 \n\t" \
852 "ldr r4, [%3, #8] \n\t" \
853 "smlal %0, %1, r3, r4 \n\t" \
854 : "=&r" (lo), "=&r" (hi), "+r" (__p) \
856 : "r0", "r1", "r2", "r3", "r4", "memory"); \
859 #define PROD_A(hi, lo, f, ptr) \
861 mad_fixed_t *__p = (f); \
863 "ldmia %2!, {r0, r1, r2, r3} \n\t" \
864 "ldr r4, [%3, #0] \n\t" \
865 "smlal %0, %1, r0, r4 \n\t" \
866 "ldr r4, [%3, #56] \n\t" \
867 "smlal %0, %1, r1, r4 \n\t" \
868 "ldr r4, [%3, #48] \n\t" \
869 "smlal %0, %1, r2, r4 \n\t" \
870 "ldr r4, [%3, #40] \n\t" \
871 "smlal %0, %1, r3, r4 \n\t" \
872 "ldmia %2, {r0, r1, r2, r3} \n\t" \
873 "ldr r4, [%3, #32] \n\t" \
874 "smlal %0, %1, r0, r4 \n\t" \
875 "ldr r4, [%3, #24] \n\t" \
876 "smlal %0, %1, r1, r4 \n\t" \
877 "ldr r4, [%3, #16] \n\t" \
878 "smlal %0, %1, r2, r4 \n\t" \
879 "ldr r4, [%3, #8] \n\t" \
880 "smlal %0, %1, r3, r4 \n\t" \
881 : "+r" (lo), "+r" (hi), "+r" (__p) \
883 : "r0", "r1", "r2", "r3", "r4", "memory"); \
886 void synth_full_odd_sbsample (mad_fixed_t
*pcm
,
887 mad_fixed_t (*fo
)[8],
888 mad_fixed_t (*fe
)[8],
889 mad_fixed_t
const (*D0ptr
)[32],
890 mad_fixed_t
const (*D1ptr
)[32]);
891 void synth_full_even_sbsample(mad_fixed_t
*pcm
,
892 mad_fixed_t (*fo
)[8],
893 mad_fixed_t (*fe
)[8],
894 mad_fixed_t
const (*D0ptr
)[32],
895 mad_fixed_t
const (*D1ptr
)[32]);
898 void synth_full(struct mad_synth
*synth
, struct mad_frame
const *frame
,
899 unsigned int nch
, unsigned int ns
) ICODE_ATTR_MPA_SYNTH
;
901 void synth_full(struct mad_synth
*synth
, struct mad_frame
const *frame
,
902 unsigned int nch
, unsigned int ns
)
905 unsigned int phase
, ch
, s
;
906 mad_fixed_t
*pcm
, (*filter
)[2][2][16][8];
907 mad_fixed_t (*sbsample
)[36][32];
908 mad_fixed_t (*fe
)[8], (*fx
)[8], (*fo
)[8];
909 mad_fixed_t
const (*D0ptr
)[32], *ptr
;
910 mad_fixed_t
const (*D1ptr
)[32];
914 for (ch
= 0; ch
< nch
; ++ch
) {
915 sbsample
= &(*frame
->sbsample_prev
)[ch
];
916 filter
= &synth
->filter
[ch
];
917 phase
= synth
->phase
;
918 pcm
= synth
->pcm
.samples
[ch
];
920 for (s
= 0; s
< ns
; ++s
) {
921 dct32((*sbsample
)[s
], phase
>> 1,
922 (*filter
)[0][phase
& 1], (*filter
)[1][phase
& 1]);
924 p
= (phase
- 1) & 0xf;
926 /* calculate 32 samples */
927 fe
= &(*filter
)[0][ phase
& 1][0];
928 fx
= &(*filter
)[0][~phase
& 1][0];
929 fo
= &(*filter
)[1][~phase
& 1][0];
931 D0ptr
= (void*)&D
[0][ p
];
932 D1ptr
= (void*)&D
[0][-p
];
937 PROD_O(hi
, lo
, *fx
, ptr
+1);
939 PROD_A(hi
, lo
, *fe
, ptr
);
940 pcm
[0] = SHIFT(MLZ(hi
, lo
));
943 synth_full_odd_sbsample(pcm
, fo
, fe
, D0ptr
, D1ptr
);
950 PROD_O(hi
, lo
, *fo
, ptr
+1);
951 pcm
[0] = SHIFT(-MLZ(hi
, lo
));
956 PROD_O(hi
, lo
, *fx
, ptr
);
958 PROD_A(hi
, lo
, *fe
, ptr
+1);
959 pcm
[0] = SHIFT(MLZ(hi
, lo
));
962 synth_full_even_sbsample(pcm
, fo
, fe
, D0ptr
, D1ptr
);
969 PROD_O(hi
, lo
, *fo
, ptr
);
970 pcm
[0] = SHIFT(-MLZ(hi
, lo
));
974 phase
= (phase
+ 1) % 16;
979 # else /* not FPM_COLDFIRE_EMAC and not FPM_ARM */
982 void synth_full(struct mad_synth
*synth
, struct mad_frame
const *frame
,
983 unsigned int nch
, unsigned int ns
)
986 unsigned int phase
, ch
, s
;
987 mad_fixed_t
*pcm
, (*filter
)[2][2][16][8];
988 mad_fixed_t (*sbsample
)[36][32];
989 mad_fixed_t (*fe
)[8], (*fx
)[8], (*fo
)[8];
990 mad_fixed_t
const (*D0ptr
)[32], *ptr
;
991 mad_fixed_t
const (*D1ptr
)[32];
995 for (ch
= 0; ch
< nch
; ++ch
) {
996 sbsample
= &(*frame
->sbsample_prev
)[ch
];
997 filter
= &synth
->filter
[ch
];
998 phase
= synth
->phase
;
999 pcm
= synth
->pcm
.samples
[ch
];
1001 for (s
= 0; s
< ns
; ++s
) {
1002 dct32((*sbsample
)[s
], phase
>> 1,
1003 (*filter
)[0][phase
& 1], (*filter
)[1][phase
& 1]);
1005 p
= (phase
- 1) & 0xf;
1007 /* calculate 32 samples */
1008 fe
= &(*filter
)[0][ phase
& 1][0];
1009 fx
= &(*filter
)[0][~phase
& 1][0];
1010 fo
= &(*filter
)[1][~phase
& 1][0];
1012 D0ptr
= (void*)&D
[0][ p
];
1013 D1ptr
= (void*)&D
[0][-p
];
1018 ML0(hi
, lo
, (*fx
)[0], ptr
[ 1]);
1019 MLA(hi
, lo
, (*fx
)[1], ptr
[15]);
1020 MLA(hi
, lo
, (*fx
)[2], ptr
[13]);
1021 MLA(hi
, lo
, (*fx
)[3], ptr
[11]);
1022 MLA(hi
, lo
, (*fx
)[4], ptr
[ 9]);
1023 MLA(hi
, lo
, (*fx
)[5], ptr
[ 7]);
1024 MLA(hi
, lo
, (*fx
)[6], ptr
[ 5]);
1025 MLA(hi
, lo
, (*fx
)[7], ptr
[ 3]);
1027 MLA(hi
, lo
, (*fe
)[0], ptr
[ 0]);
1028 MLA(hi
, lo
, (*fe
)[1], ptr
[14]);
1029 MLA(hi
, lo
, (*fe
)[2], ptr
[12]);
1030 MLA(hi
, lo
, (*fe
)[3], ptr
[10]);
1031 MLA(hi
, lo
, (*fe
)[4], ptr
[ 8]);
1032 MLA(hi
, lo
, (*fe
)[5], ptr
[ 6]);
1033 MLA(hi
, lo
, (*fe
)[6], ptr
[ 4]);
1034 MLA(hi
, lo
, (*fe
)[7], ptr
[ 2]);
1035 pcm
[0] = SHIFT(MLZ(hi
, lo
));
1038 for (sb
= 15; sb
; sb
--, fo
++)
1044 /* D[32 - sb][i] == -D[sb][31 - i] */
1046 ML0(hi
, lo
, (*fo
)[0], ptr
[ 1]);
1047 MLA(hi
, lo
, (*fo
)[1], ptr
[15]);
1048 MLA(hi
, lo
, (*fo
)[2], ptr
[13]);
1049 MLA(hi
, lo
, (*fo
)[3], ptr
[11]);
1050 MLA(hi
, lo
, (*fo
)[4], ptr
[ 9]);
1051 MLA(hi
, lo
, (*fo
)[5], ptr
[ 7]);
1052 MLA(hi
, lo
, (*fo
)[6], ptr
[ 5]);
1053 MLA(hi
, lo
, (*fo
)[7], ptr
[ 3]);
1055 MLA(hi
, lo
, (*fe
)[7], ptr
[ 2]);
1056 MLA(hi
, lo
, (*fe
)[6], ptr
[ 4]);
1057 MLA(hi
, lo
, (*fe
)[5], ptr
[ 6]);
1058 MLA(hi
, lo
, (*fe
)[4], ptr
[ 8]);
1059 MLA(hi
, lo
, (*fe
)[3], ptr
[10]);
1060 MLA(hi
, lo
, (*fe
)[2], ptr
[12]);
1061 MLA(hi
, lo
, (*fe
)[1], ptr
[14]);
1062 MLA(hi
, lo
, (*fe
)[0], ptr
[ 0]);
1063 pcm
[-sb
] = SHIFT(MLZ(hi
, lo
));
1066 ML0(hi
, lo
, (*fe
)[0], ptr
[31 - 16]);
1067 MLA(hi
, lo
, (*fe
)[1], ptr
[31 - 14]);
1068 MLA(hi
, lo
, (*fe
)[2], ptr
[31 - 12]);
1069 MLA(hi
, lo
, (*fe
)[3], ptr
[31 - 10]);
1070 MLA(hi
, lo
, (*fe
)[4], ptr
[31 - 8]);
1071 MLA(hi
, lo
, (*fe
)[5], ptr
[31 - 6]);
1072 MLA(hi
, lo
, (*fe
)[6], ptr
[31 - 4]);
1073 MLA(hi
, lo
, (*fe
)[7], ptr
[31 - 2]);
1074 MLA(hi
, lo
, (*fo
)[7], ptr
[31 - 3]);
1075 MLA(hi
, lo
, (*fo
)[6], ptr
[31 - 5]);
1076 MLA(hi
, lo
, (*fo
)[5], ptr
[31 - 7]);
1077 MLA(hi
, lo
, (*fo
)[4], ptr
[31 - 9]);
1078 MLA(hi
, lo
, (*fo
)[3], ptr
[31 - 11]);
1079 MLA(hi
, lo
, (*fo
)[2], ptr
[31 - 13]);
1080 MLA(hi
, lo
, (*fo
)[1], ptr
[31 - 15]);
1081 MLA(hi
, lo
, (*fo
)[0], ptr
[31 - 1]);
1082 pcm
[sb
] = SHIFT(MLZ(hi
, lo
));
1086 ML0(hi
, lo
, (*fo
)[0], ptr
[ 1]);
1087 MLA(hi
, lo
, (*fo
)[1], ptr
[15]);
1088 MLA(hi
, lo
, (*fo
)[2], ptr
[13]);
1089 MLA(hi
, lo
, (*fo
)[3], ptr
[11]);
1090 MLA(hi
, lo
, (*fo
)[4], ptr
[ 9]);
1091 MLA(hi
, lo
, (*fo
)[5], ptr
[ 7]);
1092 MLA(hi
, lo
, (*fo
)[6], ptr
[ 5]);
1093 MLA(hi
, lo
, (*fo
)[7], ptr
[ 3]);
1094 pcm
[0] = SHIFT(-MLZ(hi
, lo
));
1099 ML0(hi
, lo
, (*fx
)[0], ptr
[ 0]);
1100 MLA(hi
, lo
, (*fx
)[1], ptr
[14]);
1101 MLA(hi
, lo
, (*fx
)[2], ptr
[12]);
1102 MLA(hi
, lo
, (*fx
)[3], ptr
[10]);
1103 MLA(hi
, lo
, (*fx
)[4], ptr
[ 8]);
1104 MLA(hi
, lo
, (*fx
)[5], ptr
[ 6]);
1105 MLA(hi
, lo
, (*fx
)[6], ptr
[ 4]);
1106 MLA(hi
, lo
, (*fx
)[7], ptr
[ 2]);
1108 MLA(hi
, lo
, (*fe
)[0], ptr
[ 1]);
1109 MLA(hi
, lo
, (*fe
)[1], ptr
[15]);
1110 MLA(hi
, lo
, (*fe
)[2], ptr
[13]);
1111 MLA(hi
, lo
, (*fe
)[3], ptr
[11]);
1112 MLA(hi
, lo
, (*fe
)[4], ptr
[ 9]);
1113 MLA(hi
, lo
, (*fe
)[5], ptr
[ 7]);
1114 MLA(hi
, lo
, (*fe
)[6], ptr
[ 5]);
1115 MLA(hi
, lo
, (*fe
)[7], ptr
[ 3]);
1116 pcm
[0] = SHIFT(MLZ(hi
, lo
));
1119 for (sb
= 15; sb
; sb
--, fo
++)
1125 /* D[32 - sb][i] == -D[sb][31 - i] */
1127 ML0(hi
, lo
, (*fo
)[0], ptr
[ 0]);
1128 MLA(hi
, lo
, (*fo
)[1], ptr
[14]);
1129 MLA(hi
, lo
, (*fo
)[2], ptr
[12]);
1130 MLA(hi
, lo
, (*fo
)[3], ptr
[10]);
1131 MLA(hi
, lo
, (*fo
)[4], ptr
[ 8]);
1132 MLA(hi
, lo
, (*fo
)[5], ptr
[ 6]);
1133 MLA(hi
, lo
, (*fo
)[6], ptr
[ 4]);
1134 MLA(hi
, lo
, (*fo
)[7], ptr
[ 2]);
1136 MLA(hi
, lo
, (*fe
)[7], ptr
[ 3]);
1137 MLA(hi
, lo
, (*fe
)[6], ptr
[ 5]);
1138 MLA(hi
, lo
, (*fe
)[5], ptr
[ 7]);
1139 MLA(hi
, lo
, (*fe
)[4], ptr
[ 9]);
1140 MLA(hi
, lo
, (*fe
)[3], ptr
[11]);
1141 MLA(hi
, lo
, (*fe
)[2], ptr
[13]);
1142 MLA(hi
, lo
, (*fe
)[1], ptr
[15]);
1143 MLA(hi
, lo
, (*fe
)[0], ptr
[ 1]);
1144 pcm
[-sb
] = SHIFT(MLZ(hi
, lo
));
1147 ML0(hi
, lo
, (*fe
)[0], ptr
[31 - 1]);
1148 MLA(hi
, lo
, (*fe
)[1], ptr
[31 - 15]);
1149 MLA(hi
, lo
, (*fe
)[2], ptr
[31 - 13]);
1150 MLA(hi
, lo
, (*fe
)[3], ptr
[31 - 11]);
1151 MLA(hi
, lo
, (*fe
)[4], ptr
[31 - 9]);
1152 MLA(hi
, lo
, (*fe
)[5], ptr
[31 - 7]);
1153 MLA(hi
, lo
, (*fe
)[6], ptr
[31 - 5]);
1154 MLA(hi
, lo
, (*fe
)[7], ptr
[31 - 3]);
1155 MLA(hi
, lo
, (*fo
)[7], ptr
[31 - 2]);
1156 MLA(hi
, lo
, (*fo
)[6], ptr
[31 - 4]);
1157 MLA(hi
, lo
, (*fo
)[5], ptr
[31 - 6]);
1158 MLA(hi
, lo
, (*fo
)[4], ptr
[31 - 8]);
1159 MLA(hi
, lo
, (*fo
)[3], ptr
[31 - 10]);
1160 MLA(hi
, lo
, (*fo
)[2], ptr
[31 - 12]);
1161 MLA(hi
, lo
, (*fo
)[1], ptr
[31 - 14]);
1162 MLA(hi
, lo
, (*fo
)[0], ptr
[31 - 16]);
1163 pcm
[sb
] = SHIFT(MLZ(hi
, lo
));
1167 ML0(hi
, lo
, (*fo
)[0], ptr
[ 0]);
1168 MLA(hi
, lo
, (*fo
)[1], ptr
[14]);
1169 MLA(hi
, lo
, (*fo
)[2], ptr
[12]);
1170 MLA(hi
, lo
, (*fo
)[3], ptr
[10]);
1171 MLA(hi
, lo
, (*fo
)[4], ptr
[ 8]);
1172 MLA(hi
, lo
, (*fo
)[5], ptr
[ 6]);
1173 MLA(hi
, lo
, (*fo
)[6], ptr
[ 4]);
1174 MLA(hi
, lo
, (*fo
)[7], ptr
[ 2]);
1175 pcm
[0] = SHIFT(-MLZ(hi
, lo
));
1179 phase
= (phase
+ 1) % 16;
1188 * NAME: synth->half()
1189 * DESCRIPTION: perform half frequency PCM synthesis
1192 void synth_half(struct mad_synth
*synth
, struct mad_frame
const *frame
,
1193 unsigned int nch
, unsigned int ns
)
1195 unsigned int phase
, ch
, s
, sb
, pe
, po
;
1196 mad_fixed_t
*pcm1
, *pcm2
, (*filter
)[2][2][16][8];
1197 mad_fixed_t (*sbsample
)[36][32];
1198 register mad_fixed_t (*fe
)[8], (*fx
)[8], (*fo
)[8];
1199 register mad_fixed_t
const (*Dptr
)[32], *ptr
;
1200 register mad_fixed64hi_t hi
;
1201 register mad_fixed64lo_t lo
;
1203 for (ch
= 0; ch
< nch
; ++ch
) {
1204 sbsample
= &(*frame
->sbsample_prev
)[ch
];
1205 filter
= &synth
->filter
[ch
];
1206 phase
= synth
->phase
;
1207 pcm1
= synth
->pcm
.samples
[ch
];
1209 for (s
= 0; s
< ns
; ++s
) {
1210 dct32((*sbsample
)[s
], phase
>> 1,
1211 (*filter
)[0][phase
& 1], (*filter
)[1][phase
& 1]);
1214 po
= ((phase
- 1) & 0xf) | 1;
1216 /* calculate 16 samples */
1218 fe
= &(*filter
)[0][ phase
& 1][0];
1219 fx
= &(*filter
)[0][~phase
& 1][0];
1220 fo
= &(*filter
)[1][~phase
& 1][0];
1225 ML0(hi
, lo
, (*fx
)[0], ptr
[ 0]);
1226 MLA(hi
, lo
, (*fx
)[1], ptr
[14]);
1227 MLA(hi
, lo
, (*fx
)[2], ptr
[12]);
1228 MLA(hi
, lo
, (*fx
)[3], ptr
[10]);
1229 MLA(hi
, lo
, (*fx
)[4], ptr
[ 8]);
1230 MLA(hi
, lo
, (*fx
)[5], ptr
[ 6]);
1231 MLA(hi
, lo
, (*fx
)[6], ptr
[ 4]);
1232 MLA(hi
, lo
, (*fx
)[7], ptr
[ 2]);
1236 MLA(hi
, lo
, (*fe
)[0], ptr
[ 0]);
1237 MLA(hi
, lo
, (*fe
)[1], ptr
[14]);
1238 MLA(hi
, lo
, (*fe
)[2], ptr
[12]);
1239 MLA(hi
, lo
, (*fe
)[3], ptr
[10]);
1240 MLA(hi
, lo
, (*fe
)[4], ptr
[ 8]);
1241 MLA(hi
, lo
, (*fe
)[5], ptr
[ 6]);
1242 MLA(hi
, lo
, (*fe
)[6], ptr
[ 4]);
1243 MLA(hi
, lo
, (*fe
)[7], ptr
[ 2]);
1245 *pcm1
++ = SHIFT(MLZ(hi
, lo
));
1249 for (sb
= 1; sb
< 16; ++sb
) {
1253 /* D[32 - sb][i] == -D[sb][31 - i] */
1257 ML0(hi
, lo
, (*fo
)[0], ptr
[ 0]);
1258 MLA(hi
, lo
, (*fo
)[1], ptr
[14]);
1259 MLA(hi
, lo
, (*fo
)[2], ptr
[12]);
1260 MLA(hi
, lo
, (*fo
)[3], ptr
[10]);
1261 MLA(hi
, lo
, (*fo
)[4], ptr
[ 8]);
1262 MLA(hi
, lo
, (*fo
)[5], ptr
[ 6]);
1263 MLA(hi
, lo
, (*fo
)[6], ptr
[ 4]);
1264 MLA(hi
, lo
, (*fo
)[7], ptr
[ 2]);
1268 MLA(hi
, lo
, (*fe
)[7], ptr
[ 2]);
1269 MLA(hi
, lo
, (*fe
)[6], ptr
[ 4]);
1270 MLA(hi
, lo
, (*fe
)[5], ptr
[ 6]);
1271 MLA(hi
, lo
, (*fe
)[4], ptr
[ 8]);
1272 MLA(hi
, lo
, (*fe
)[3], ptr
[10]);
1273 MLA(hi
, lo
, (*fe
)[2], ptr
[12]);
1274 MLA(hi
, lo
, (*fe
)[1], ptr
[14]);
1275 MLA(hi
, lo
, (*fe
)[0], ptr
[ 0]);
1277 *pcm1
++ = SHIFT(MLZ(hi
, lo
));
1280 ML0(hi
, lo
, (*fo
)[7], ptr
[31 - 2]);
1281 MLA(hi
, lo
, (*fo
)[6], ptr
[31 - 4]);
1282 MLA(hi
, lo
, (*fo
)[5], ptr
[31 - 6]);
1283 MLA(hi
, lo
, (*fo
)[4], ptr
[31 - 8]);
1284 MLA(hi
, lo
, (*fo
)[3], ptr
[31 - 10]);
1285 MLA(hi
, lo
, (*fo
)[2], ptr
[31 - 12]);
1286 MLA(hi
, lo
, (*fo
)[1], ptr
[31 - 14]);
1287 MLA(hi
, lo
, (*fo
)[0], ptr
[31 - 16]);
1290 MLA(hi
, lo
, (*fe
)[0], ptr
[31 - 16]);
1291 MLA(hi
, lo
, (*fe
)[1], ptr
[31 - 14]);
1292 MLA(hi
, lo
, (*fe
)[2], ptr
[31 - 12]);
1293 MLA(hi
, lo
, (*fe
)[3], ptr
[31 - 10]);
1294 MLA(hi
, lo
, (*fe
)[4], ptr
[31 - 8]);
1295 MLA(hi
, lo
, (*fe
)[5], ptr
[31 - 6]);
1296 MLA(hi
, lo
, (*fe
)[6], ptr
[31 - 4]);
1297 MLA(hi
, lo
, (*fe
)[7], ptr
[31 - 2]);
1299 *pcm2
-- = SHIFT(MLZ(hi
, lo
));
1308 ML0(hi
, lo
, (*fo
)[0], ptr
[ 0]);
1309 MLA(hi
, lo
, (*fo
)[1], ptr
[14]);
1310 MLA(hi
, lo
, (*fo
)[2], ptr
[12]);
1311 MLA(hi
, lo
, (*fo
)[3], ptr
[10]);
1312 MLA(hi
, lo
, (*fo
)[4], ptr
[ 8]);
1313 MLA(hi
, lo
, (*fo
)[5], ptr
[ 6]);
1314 MLA(hi
, lo
, (*fo
)[6], ptr
[ 4]);
1315 MLA(hi
, lo
, (*fo
)[7], ptr
[ 2]);
1317 *pcm1
= SHIFT(-MLZ(hi
, lo
));
1320 phase
= (phase
+ 1) % 16;
1326 * NAME: synth->frame()
1327 * DESCRIPTION: perform PCM synthesis of frame subband samples
1329 void mad_synth_frame(struct mad_synth
*synth
, struct mad_frame
const *frame
)
1331 unsigned int nch
, ns
;
1332 void (*synth_frame
)(struct mad_synth
*, struct mad_frame
const *,
1333 unsigned int, unsigned int);
1335 nch
= MAD_NCHANNELS(&frame
->header
);
1336 ns
= MAD_NSBSAMPLES(&frame
->header
);
1338 synth
->pcm
.samplerate
= frame
->header
.samplerate
;
1339 synth
->pcm
.channels
= nch
;
1340 synth
->pcm
.length
= 32 * ns
;
1342 synth_frame
= synth_full
;
1344 if (frame
->options
& MAD_OPTION_HALFSAMPLERATE
) {
1345 synth
->pcm
.samplerate
/= 2;
1346 synth
->pcm
.length
/= 2;
1348 synth_frame
= synth_half
;
1351 synth_frame(synth
, frame
, nch
, ns
);
1353 synth
->phase
= (synth
->phase
+ ns
) % 16;