2 * mad - MPEG audio decoder
3 * Copyright (C) 2000-2001 Robert Leslie
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;
49 * DESCRIPTION: zero all polyphase filterbank values, resetting synthesis
51 void mad_synth_mute(struct mad_synth
*synth
)
53 unsigned int ch
, s
, v
;
55 for (ch
= 0; ch
< 2; ++ch
) {
56 for (s
= 0; s
< 16; ++s
) {
57 for (v
= 0; v
< 8; ++v
) {
58 synth
->filter
[ch
][0][0][s
][v
] = synth
->filter
[ch
][0][1][s
][v
] =
59 synth
->filter
[ch
][1][0][s
][v
] = synth
->filter
[ch
][1][1][s
][v
] = 0;
66 * An optional optimization called here the Subband Synthesis Optimization
67 * (SSO) improves the performance of subband synthesis at the expense of
70 * The idea is to simplify 32x32->64-bit multiplication to 32x32->32 such
71 * that extra scaling and rounding are not necessary. This often allows the
72 * compiler to use faster 32-bit multiply-accumulate instructions instead of
73 * explicit 64-bit multiply, shift, and add instructions.
75 * SSO works like this: a full 32x32->64-bit multiply of two mad_fixed_t
76 * values requires the result to be right-shifted 28 bits to be properly
77 * scaled to the same fixed-point format. Right shifts can be applied at any
78 * time to either operand or to the result, so the optimization involves
79 * careful placement of these shifts to minimize the loss of accuracy.
81 * First, a 14-bit shift is applied with rounding at compile-time to the D[]
82 * table of coefficients for the subband synthesis window. This only loses 2
83 * bits of accuracy because the lower 12 bits are always zero. A second
84 * 12-bit shift occurs after the DCT calculation. This loses 12 bits of
85 * accuracy. Finally, a third 2-bit shift occurs just before the sample is
86 * saved in the PCM buffer. 14 + 12 + 2 == 28 bits.
89 /* FPM_DEFAULT without OPT_SSO will actually lose accuracy and performance */
91 # if defined(FPM_DEFAULT) && !defined(OPT_SSO)
95 /* second SSO shift, with rounding */
98 # define SHIFT(x) (((x) + (1L << 11)) >> 12)
100 # define SHIFT(x) (x)
103 /* possible DCT speed optimization */
105 # if defined(OPT_SPEED) && defined(MAD_F_MLX)
108 ({ mad_fixed64hi_t hi; \
109 mad_fixed64lo_t lo; \
110 MAD_F_MLX(hi, lo, (x), (y)); \
111 hi << (32 - MAD_F_SCALEBITS - 3); \
115 # define MUL(x, y) mad_f_mul((x), (y))
120 * DESCRIPTION: perform fast in[32]->out[32] DCT
123 void dct32(mad_fixed_t
const in
[32], unsigned int slot
,
124 mad_fixed_t lo
[16][8], mad_fixed_t hi
[16][8])
126 mad_fixed_t t0
, t1
, t2
, t3
, t4
, t5
, t6
, t7
;
127 mad_fixed_t t8
, t9
, t10
, t11
, t12
, t13
, t14
, t15
;
128 mad_fixed_t t16
, t17
, t18
, t19
, t20
, t21
, t22
, t23
;
129 mad_fixed_t t24
, t25
, t26
, t27
, t28
, t29
, t30
, t31
;
130 mad_fixed_t t32
, t33
, t34
, t35
, t36
, t37
, t38
, t39
;
131 mad_fixed_t t40
, t41
, t42
, t43
, t44
, t45
, t46
, t47
;
132 mad_fixed_t t48
, t49
, t50
, t51
, t52
, t53
, t54
, t55
;
133 mad_fixed_t t56
, t57
, t58
, t59
, t60
, t61
, t62
, t63
;
134 mad_fixed_t t64
, t65
, t66
, t67
, t68
, t69
, t70
, t71
;
135 mad_fixed_t t72
, t73
, t74
, t75
, t76
, t77
, t78
, t79
;
136 mad_fixed_t t80
, t81
, t82
, t83
, t84
, t85
, t86
, t87
;
137 mad_fixed_t t88
, t89
, t90
, t91
, t92
, t93
, t94
, t95
;
138 mad_fixed_t t96
, t97
, t98
, t99
, t100
, t101
, t102
, t103
;
139 mad_fixed_t t104
, t105
, t106
, t107
, t108
, t109
, t110
, t111
;
140 mad_fixed_t t112
, t113
, t114
, t115
, t116
, t117
, t118
, t119
;
141 mad_fixed_t t120
, t121
, t122
, t123
, t124
, t125
, t126
, t127
;
142 mad_fixed_t t128
, t129
, t130
, t131
, t132
, t133
, t134
, t135
;
143 mad_fixed_t t136
, t137
, t138
, t139
, t140
, t141
, t142
, t143
;
144 mad_fixed_t t144
, t145
, t146
, t147
, t148
, t149
, t150
, t151
;
145 mad_fixed_t t152
, t153
, t154
, t155
, t156
, t157
, t158
, t159
;
146 mad_fixed_t t160
, t161
, t162
, t163
, t164
, t165
, t166
, t167
;
147 mad_fixed_t t168
, t169
, t170
, t171
, t172
, t173
, t174
, t175
;
150 /* costab[i] = cos(PI / (2 * 32) * i) */
152 # if defined(OPT_DCTO)
154 costab1
= MAD_F(0x7fd8878e),
155 costab2
= MAD_F(0x7f62368f),
156 costab3
= MAD_F(0x7e9d55fc),
157 costab4
= MAD_F(0x7d8a5f40),
158 costab5
= MAD_F(0x7c29fbee),
159 costab6
= MAD_F(0x7a7d055b),
160 costab7
= MAD_F(0x78848414),
161 costab8
= MAD_F(0x7641af3d),
162 costab9
= MAD_F(0x73b5ebd1),
163 costab10
= MAD_F(0x70e2cbc6),
164 costab11
= MAD_F(0x6dca0d14),
165 costab12
= MAD_F(0x6a6d98a4),
166 costab13
= MAD_F(0x66cf8120),
167 costab14
= MAD_F(0x62f201ac),
168 costab15
= MAD_F(0x5ed77c8a),
169 costab16
= MAD_F(0x5a82799a),
170 costab17
= MAD_F(0x55f5a4d2),
171 costab18
= MAD_F(0x5133cc94),
172 costab19
= MAD_F(0x4c3fdff4),
173 costab20
= MAD_F(0x471cece7),
174 costab21
= MAD_F(0x41ce1e65),
175 costab22
= MAD_F(0x3c56ba70),
176 costab23
= MAD_F(0x36ba2014),
177 costab24
= MAD_F(0x30fbc54d),
178 costab25
= MAD_F(0x2b1f34eb),
179 costab26
= MAD_F(0x25280c5e),
180 costab27
= MAD_F(0x1f19f97b),
181 costab28
= MAD_F(0x18f8b83c),
182 costab29
= MAD_F(0x12c8106f),
183 costab30
= MAD_F(0x0c8bd35e),
184 costab31
= MAD_F(0x0647d97c)
188 costab1
= MAD_F(0x0ffb10f2), /* 0.998795456 */
189 costab2
= MAD_F(0x0fec46d2), /* 0.995184727 */
190 costab3
= MAD_F(0x0fd3aac0), /* 0.989176510 */
191 costab4
= MAD_F(0x0fb14be8), /* 0.980785280 */
192 costab5
= MAD_F(0x0f853f7e), /* 0.970031253 */
193 costab6
= MAD_F(0x0f4fa0ab), /* 0.956940336 */
194 costab7
= MAD_F(0x0f109082), /* 0.941544065 */
195 costab8
= MAD_F(0x0ec835e8), /* 0.923879533 */
196 costab9
= MAD_F(0x0e76bd7a), /* 0.903989293 */
197 costab10
= MAD_F(0x0e1c5979), /* 0.881921264 */
198 costab11
= MAD_F(0x0db941a3), /* 0.857728610 */
199 costab12
= MAD_F(0x0d4db315), /* 0.831469612 */
200 costab13
= MAD_F(0x0cd9f024), /* 0.803207531 */
201 costab14
= MAD_F(0x0c5e4036), /* 0.773010453 */
202 costab15
= MAD_F(0x0bdaef91), /* 0.740951125 */
203 costab16
= MAD_F(0x0b504f33), /* 0.707106781 */
204 costab17
= MAD_F(0x0abeb49a), /* 0.671558955 */
205 costab18
= MAD_F(0x0a267993), /* 0.634393284 */
206 costab19
= MAD_F(0x0987fbfe), /* 0.595699304 */
207 costab20
= MAD_F(0x08e39d9d), /* 0.555570233 */
208 costab21
= MAD_F(0x0839c3cd), /* 0.514102744 */
209 costab22
= MAD_F(0x078ad74e), /* 0.471396737 */
210 costab23
= MAD_F(0x06d74402), /* 0.427555093 */
211 costab24
= MAD_F(0x061f78aa), /* 0.382683432 */
212 costab25
= MAD_F(0x0563e69d), /* 0.336889853 */
213 costab26
= MAD_F(0x04a5018c), /* 0.290284677 */
214 costab27
= MAD_F(0x03e33f2f), /* 0.242980180 */
215 costab28
= MAD_F(0x031f1708), /* 0.195090322 */
216 costab29
= MAD_F(0x0259020e), /* 0.146730474 */
217 costab30
= MAD_F(0x01917a6c), /* 0.098017140 */
218 costab31
= MAD_F(0x00c8fb30) /* 0.049067674 */
222 t0
= in
[0] + in
[31]; t16
= MUL(in
[0] - in
[31], costab1
);
223 t1
= in
[15] + in
[16]; t17
= MUL(in
[15] - in
[16], costab31
);
226 t59
= MUL(t16
- t17
, costab2
);
228 t50
= MUL(t0
- t1
, costab2
);
230 t2
= in
[7] + in
[24]; t18
= MUL(in
[7] - in
[24], costab15
);
231 t3
= in
[8] + in
[23]; t19
= MUL(in
[8] - in
[23], costab17
);
234 t60
= MUL(t18
- t19
, costab30
);
236 t51
= MUL(t2
- t3
, costab30
);
238 t4
= in
[3] + in
[28]; t20
= MUL(in
[3] - in
[28], costab7
);
239 t5
= in
[12] + in
[19]; t21
= MUL(in
[12] - in
[19], costab25
);
242 t61
= MUL(t20
- t21
, costab14
);
244 t52
= MUL(t4
- t5
, costab14
);
246 t6
= in
[4] + in
[27]; t22
= MUL(in
[4] - in
[27], costab9
);
247 t7
= in
[11] + in
[20]; t23
= MUL(in
[11] - in
[20], costab23
);
250 t62
= MUL(t22
- t23
, costab18
);
252 t53
= MUL(t6
- t7
, costab18
);
254 t8
= in
[1] + in
[30]; t24
= MUL(in
[1] - in
[30], costab3
);
255 t9
= in
[14] + in
[17]; t25
= MUL(in
[14] - in
[17], costab29
);
258 t63
= MUL(t24
- t25
, costab6
);
260 t54
= MUL(t8
- t9
, costab6
);
262 t10
= in
[6] + in
[25]; t26
= MUL(in
[6] - in
[25], costab13
);
263 t11
= in
[9] + in
[22]; t27
= MUL(in
[9] - in
[22], costab19
);
266 t64
= MUL(t26
- t27
, costab26
);
268 t55
= MUL(t10
- t11
, costab26
);
270 t12
= in
[2] + in
[29]; t28
= MUL(in
[2] - in
[29], costab5
);
271 t13
= in
[13] + in
[18]; t29
= MUL(in
[13] - in
[18], costab27
);
274 t65
= MUL(t28
- t29
, costab10
);
276 t56
= MUL(t12
- t13
, costab10
);
278 t14
= in
[5] + in
[26]; t30
= MUL(in
[5] - in
[26], costab11
);
279 t15
= in
[10] + in
[21]; t31
= MUL(in
[10] - in
[21], costab21
);
282 t66
= MUL(t30
- t31
, costab22
);
284 t57
= MUL(t14
- t15
, costab22
);
286 t69
= t33
+ t34
; t89
= MUL(t33
- t34
, costab4
);
287 t70
= t35
+ t36
; t90
= MUL(t35
- t36
, costab28
);
288 t71
= t37
+ t38
; t91
= MUL(t37
- t38
, costab12
);
289 t72
= t39
+ t40
; t92
= MUL(t39
- t40
, costab20
);
290 t73
= t41
+ t42
; t94
= MUL(t41
- t42
, costab4
);
291 t74
= t43
+ t44
; t95
= MUL(t43
- t44
, costab28
);
292 t75
= t45
+ t46
; t96
= MUL(t45
- t46
, costab12
);
293 t76
= t47
+ t48
; t97
= MUL(t47
- t48
, costab20
);
295 t78
= t50
+ t51
; t100
= MUL(t50
- t51
, costab4
);
296 t79
= t52
+ t53
; t101
= MUL(t52
- t53
, costab28
);
297 t80
= t54
+ t55
; t102
= MUL(t54
- t55
, costab12
);
298 t81
= t56
+ t57
; t103
= MUL(t56
- t57
, costab20
);
300 t83
= t59
+ t60
; t106
= MUL(t59
- t60
, costab4
);
301 t84
= t61
+ t62
; t107
= MUL(t61
- t62
, costab28
);
302 t85
= t63
+ t64
; t108
= MUL(t63
- t64
, costab12
);
303 t86
= t65
+ t66
; t109
= MUL(t65
- t66
, costab20
);
308 /* 0 */ hi
[15][slot
] = SHIFT(t113
+ t114
);
309 /* 16 */ lo
[ 0][slot
] = SHIFT(MUL(t113
- t114
, costab16
));
316 /* 1 */ hi
[14][slot
] = SHIFT(t32
);
323 /* 2 */ hi
[13][slot
] = SHIFT(t58
);
330 t49
= (t67
<< 1) - t32
;
332 /* 3 */ hi
[12][slot
] = SHIFT(t49
);
339 /* 4 */ hi
[11][slot
] = SHIFT(t93
);
346 t68
= (t98
<< 1) - t49
;
348 /* 5 */ hi
[10][slot
] = SHIFT(t68
);
355 t82
= (t104
<< 1) - t58
;
357 /* 6 */ hi
[ 9][slot
] = SHIFT(t82
);
364 t87
= (t110
<< 1) - t67
;
366 t77
= (t87
<< 1) - t68
;
368 /* 7 */ hi
[ 8][slot
] = SHIFT(t77
);
370 t141
= MUL(t69
- t70
, costab8
);
371 t142
= MUL(t71
- t72
, costab24
);
374 /* 8 */ hi
[ 7][slot
] = SHIFT(t143
);
375 /* 24 */ lo
[ 8][slot
] =
376 SHIFT((MUL(t141
- t142
, costab16
) << 1) - t143
);
378 t144
= MUL(t73
- t74
, costab8
);
379 t145
= MUL(t75
- t76
, costab24
);
382 t88
= (t146
<< 1) - t77
;
384 /* 9 */ hi
[ 6][slot
] = SHIFT(t88
);
386 t148
= MUL(t78
- t79
, costab8
);
387 t149
= MUL(t80
- t81
, costab24
);
390 t105
= (t150
<< 1) - t82
;
392 /* 10 */ hi
[ 5][slot
] = SHIFT(t105
);
394 t152
= MUL(t83
- t84
, costab8
);
395 t153
= MUL(t85
- t86
, costab24
);
398 t111
= (t154
<< 1) - t87
;
400 t99
= (t111
<< 1) - t88
;
402 /* 11 */ hi
[ 4][slot
] = SHIFT(t99
);
404 t157
= MUL(t89
- t90
, costab8
);
405 t158
= MUL(t91
- t92
, costab24
);
408 t127
= (t159
<< 1) - t93
;
410 /* 12 */ hi
[ 3][slot
] = SHIFT(t127
);
412 t160
= (MUL(t125
- t126
, costab16
) << 1) - t127
;
414 /* 20 */ lo
[ 4][slot
] = SHIFT(t160
);
415 /* 28 */ lo
[12][slot
] =
416 SHIFT((((MUL(t157
- t158
, costab16
) << 1) - t159
) << 1) - t160
);
418 t161
= MUL(t94
- t95
, costab8
);
419 t162
= MUL(t96
- t97
, costab24
);
422 t130
= (t163
<< 1) - t98
;
424 t112
= (t130
<< 1) - t99
;
426 /* 13 */ hi
[ 2][slot
] = SHIFT(t112
);
428 t164
= (MUL(t128
- t129
, costab16
) << 1) - t130
;
430 t166
= MUL(t100
- t101
, costab8
);
431 t167
= MUL(t102
- t103
, costab24
);
434 t134
= (t168
<< 1) - t104
;
436 t120
= (t134
<< 1) - t105
;
438 /* 14 */ hi
[ 1][slot
] = SHIFT(t120
);
440 t135
= (MUL(t118
- t119
, costab16
) << 1) - t120
;
442 /* 18 */ lo
[ 2][slot
] = SHIFT(t135
);
444 t169
= (MUL(t132
- t133
, costab16
) << 1) - t134
;
446 t151
= (t169
<< 1) - t135
;
448 /* 22 */ lo
[ 6][slot
] = SHIFT(t151
);
450 t170
= (((MUL(t148
- t149
, costab16
) << 1) - t150
) << 1) - t151
;
452 /* 26 */ lo
[10][slot
] = SHIFT(t170
);
453 /* 30 */ lo
[14][slot
] =
454 SHIFT((((((MUL(t166
- t167
, costab16
) << 1) -
455 t168
) << 1) - t169
) << 1) - t170
);
457 t171
= MUL(t106
- t107
, costab8
);
458 t172
= MUL(t108
- t109
, costab24
);
461 t138
= (t173
<< 1) - t110
;
463 t123
= (t138
<< 1) - t111
;
465 t139
= (MUL(t121
- t122
, costab16
) << 1) - t123
;
467 t117
= (t123
<< 1) - t112
;
469 /* 15 */ hi
[ 0][slot
] = SHIFT(t117
);
471 t124
= (MUL(t115
- t116
, costab16
) << 1) - t117
;
473 /* 17 */ lo
[ 1][slot
] = SHIFT(t124
);
475 t131
= (t139
<< 1) - t124
;
477 /* 19 */ lo
[ 3][slot
] = SHIFT(t131
);
479 t140
= (t164
<< 1) - t131
;
481 /* 21 */ lo
[ 5][slot
] = SHIFT(t140
);
483 t174
= (MUL(t136
- t137
, costab16
) << 1) - t138
;
485 t155
= (t174
<< 1) - t139
;
487 t147
= (t155
<< 1) - t140
;
489 /* 23 */ lo
[ 7][slot
] = SHIFT(t147
);
491 t156
= (((MUL(t144
- t145
, costab16
) << 1) - t146
) << 1) - t147
;
493 /* 25 */ lo
[ 9][slot
] = SHIFT(t156
);
495 t175
= (((MUL(t152
- t153
, costab16
) << 1) - t154
) << 1) - t155
;
497 t165
= (t175
<< 1) - t156
;
499 /* 27 */ lo
[11][slot
] = SHIFT(t165
);
501 t176
= (((((MUL(t161
- t162
, costab16
) << 1) -
502 t163
) << 1) - t164
) << 1) - t165
;
504 /* 29 */ lo
[13][slot
] = SHIFT(t176
);
505 /* 31 */ lo
[15][slot
] =
506 SHIFT((((((((MUL(t171
- t172
, costab16
) << 1) -
507 t173
) << 1) - t174
) << 1) - t175
) << 1) - t176
);
514 * 49 shifts (not counting SSO)
521 /* third SSO shift and/or D[] optimization preshift */
523 # if defined(OPT_SSO)
524 # if MAD_F_FRACBITS != 28
525 # error "MAD_F_FRACBITS must be 28 to use OPT_SSO"
527 # define ML0(hi, lo, x, y) ((lo) = (x) * (y))
528 # define MLA(hi, lo, x, y) ((lo) += (x) * (y))
529 # define MLZ(hi, lo) ((void) (hi), (mad_fixed_t) (lo))
530 # define SHIFT(x) ((x) >> 2)
531 # define PRESHIFT(x) ((MAD_F(x) + (1L << 13)) >> 14)
533 # define ML0(hi, lo, x, y) MAD_F_ML0((hi), (lo), (x), (y))
534 # define MLA(hi, lo, x, y) MAD_F_MLA((hi), (lo), (x), (y))
535 # define MLZ(hi, lo) MAD_F_MLZ((hi), (lo))
536 # define SHIFT(x) (x)
537 # if defined(MAD_F_SCALEBITS)
538 # undef MAD_F_SCALEBITS
539 # define MAD_F_SCALEBITS (MAD_F_FRACBITS - 12)
540 # define PRESHIFT(x) (MAD_F(x) >> 12)
542 # define PRESHIFT(x) MAD_F(x)
547 mad_fixed_t
const D
[17][32] = {
551 # if defined(ASO_SYNTH)
552 void synth_full(struct mad_synth
*, struct mad_frame
const *,
553 unsigned int, unsigned int);
556 * NAME: synth->full()
557 * DESCRIPTION: perform full frequency PCM synthesis
560 void synth_full(struct mad_synth
*synth
, struct mad_frame
const *frame
,
561 unsigned int nch
, unsigned int ns
)
563 unsigned int phase
, ch
, s
, sb
, pe
, po
;
564 mad_fixed_t
*pcm1
, *pcm2
, (*filter
)[2][2][16][8];
565 mad_fixed_t
const (*sbsample
)[36][32];
566 register mad_fixed_t (*fe
)[8], (*fx
)[8], (*fo
)[8];
567 register mad_fixed_t
const (*Dptr
)[32], *ptr
;
568 register mad_fixed64hi_t hi
;
569 register mad_fixed64lo_t lo
;
571 for (ch
= 0; ch
< nch
; ++ch
) {
572 sbsample
= &frame
->sbsample
[ch
];
573 filter
= &synth
->filter
[ch
];
574 phase
= synth
->phase
;
575 pcm1
= synth
->pcm
.samples
[ch
];
577 for (s
= 0; s
< ns
; ++s
) {
578 dct32((*sbsample
)[s
], phase
>> 1,
579 (*filter
)[0][phase
& 1], (*filter
)[1][phase
& 1]);
582 po
= ((phase
- 1) & 0xf) | 1;
584 /* calculate 32 samples */
586 fe
= &(*filter
)[0][ phase
& 1][0];
587 fx
= &(*filter
)[0][~phase
& 1][0];
588 fo
= &(*filter
)[1][~phase
& 1][0];
593 ML0(hi
, lo
, (*fe
)[0], ptr
[ 0]);
594 MLA(hi
, lo
, (*fe
)[1], ptr
[14]);
595 MLA(hi
, lo
, (*fe
)[2], ptr
[12]);
596 MLA(hi
, lo
, (*fe
)[3], ptr
[10]);
597 MLA(hi
, lo
, (*fe
)[4], ptr
[ 8]);
598 MLA(hi
, lo
, (*fe
)[5], ptr
[ 6]);
599 MLA(hi
, lo
, (*fe
)[6], ptr
[ 4]);
600 MLA(hi
, lo
, (*fe
)[7], ptr
[ 2]);
603 MLA(hi
, lo
, (*fx
)[0], -ptr
[ 0]);
604 MLA(hi
, lo
, (*fx
)[1], -ptr
[14]);
605 MLA(hi
, lo
, (*fx
)[2], -ptr
[12]);
606 MLA(hi
, lo
, (*fx
)[3], -ptr
[10]);
607 MLA(hi
, lo
, (*fx
)[4], -ptr
[ 8]);
608 MLA(hi
, lo
, (*fx
)[5], -ptr
[ 6]);
609 MLA(hi
, lo
, (*fx
)[6], -ptr
[ 4]);
610 MLA(hi
, lo
, (*fx
)[7], -ptr
[ 2]);
612 *pcm1
++ = SHIFT(MLZ(hi
, lo
));
616 for (sb
= 1; sb
< 16; ++sb
) {
620 /* D[32 - sb][i] == -D[sb][31 - i] */
623 ML0(hi
, lo
, (*fe
)[7], ptr
[ 2]);
624 MLA(hi
, lo
, (*fe
)[6], ptr
[ 4]);
625 MLA(hi
, lo
, (*fe
)[5], ptr
[ 6]);
626 MLA(hi
, lo
, (*fe
)[4], ptr
[ 8]);
627 MLA(hi
, lo
, (*fe
)[3], ptr
[10]);
628 MLA(hi
, lo
, (*fe
)[2], ptr
[12]);
629 MLA(hi
, lo
, (*fe
)[1], ptr
[14]);
630 MLA(hi
, lo
, (*fe
)[0], ptr
[ 0]);
633 MLA(hi
, lo
, (*fo
)[0], -ptr
[ 0]);
634 MLA(hi
, lo
, (*fo
)[1], -ptr
[14]);
635 MLA(hi
, lo
, (*fo
)[2], -ptr
[12]);
636 MLA(hi
, lo
, (*fo
)[3], -ptr
[10]);
637 MLA(hi
, lo
, (*fo
)[4], -ptr
[ 8]);
638 MLA(hi
, lo
, (*fo
)[5], -ptr
[ 6]);
639 MLA(hi
, lo
, (*fo
)[6], -ptr
[ 4]);
640 MLA(hi
, lo
, (*fo
)[7], -ptr
[ 2]);
642 *pcm1
++ = SHIFT(MLZ(hi
, lo
));
645 ML0(hi
, lo
, (*fo
)[7], ptr
[31 - 2]);
646 MLA(hi
, lo
, (*fo
)[6], ptr
[31 - 4]);
647 MLA(hi
, lo
, (*fo
)[5], ptr
[31 - 6]);
648 MLA(hi
, lo
, (*fo
)[4], ptr
[31 - 8]);
649 MLA(hi
, lo
, (*fo
)[3], ptr
[31 - 10]);
650 MLA(hi
, lo
, (*fo
)[2], ptr
[31 - 12]);
651 MLA(hi
, lo
, (*fo
)[1], ptr
[31 - 14]);
652 MLA(hi
, lo
, (*fo
)[0], ptr
[31 - 16]);
655 MLA(hi
, lo
, (*fe
)[0], ptr
[31 - 16]);
656 MLA(hi
, lo
, (*fe
)[1], ptr
[31 - 14]);
657 MLA(hi
, lo
, (*fe
)[2], ptr
[31 - 12]);
658 MLA(hi
, lo
, (*fe
)[3], ptr
[31 - 10]);
659 MLA(hi
, lo
, (*fe
)[4], ptr
[31 - 8]);
660 MLA(hi
, lo
, (*fe
)[5], ptr
[31 - 6]);
661 MLA(hi
, lo
, (*fe
)[6], ptr
[31 - 4]);
662 MLA(hi
, lo
, (*fe
)[7], ptr
[31 - 2]);
664 *pcm2
-- = SHIFT(MLZ(hi
, lo
));
672 ML0(hi
, lo
, (*fo
)[0], ptr
[ 0]);
673 MLA(hi
, lo
, (*fo
)[1], ptr
[14]);
674 MLA(hi
, lo
, (*fo
)[2], ptr
[12]);
675 MLA(hi
, lo
, (*fo
)[3], ptr
[10]);
676 MLA(hi
, lo
, (*fo
)[4], ptr
[ 8]);
677 MLA(hi
, lo
, (*fo
)[5], ptr
[ 6]);
678 MLA(hi
, lo
, (*fo
)[6], ptr
[ 4]);
679 MLA(hi
, lo
, (*fo
)[7], ptr
[ 2]);
681 *pcm1
= SHIFT(-MLZ(hi
, lo
));
684 phase
= (phase
+ 1) % 16;
691 * NAME: synth->half()
692 * DESCRIPTION: perform half frequency PCM synthesis
695 void synth_half(struct mad_synth
*synth
, struct mad_frame
const *frame
,
696 unsigned int nch
, unsigned int ns
)
698 unsigned int phase
, ch
, s
, sb
, pe
, po
;
699 mad_fixed_t
*pcm1
, *pcm2
, (*filter
)[2][2][16][8];
700 mad_fixed_t
const (*sbsample
)[36][32];
701 register mad_fixed_t (*fe
)[8], (*fx
)[8], (*fo
)[8];
702 register mad_fixed_t
const (*Dptr
)[32], *ptr
;
703 register mad_fixed64hi_t hi
;
704 register mad_fixed64lo_t lo
;
706 for (ch
= 0; ch
< nch
; ++ch
) {
707 sbsample
= &frame
->sbsample
[ch
];
708 filter
= &synth
->filter
[ch
];
709 phase
= synth
->phase
;
710 pcm1
= synth
->pcm
.samples
[ch
];
712 for (s
= 0; s
< ns
; ++s
) {
713 dct32((*sbsample
)[s
], phase
>> 1,
714 (*filter
)[0][phase
& 1], (*filter
)[1][phase
& 1]);
717 po
= ((phase
- 1) & 0xf) | 1;
719 /* calculate 16 samples */
721 fe
= &(*filter
)[0][ phase
& 1][0];
722 fx
= &(*filter
)[0][~phase
& 1][0];
723 fo
= &(*filter
)[1][~phase
& 1][0];
728 ML0(hi
, lo
, (*fe
)[0], ptr
[ 0]);
729 MLA(hi
, lo
, (*fe
)[1], ptr
[14]);
730 MLA(hi
, lo
, (*fe
)[2], ptr
[12]);
731 MLA(hi
, lo
, (*fe
)[3], ptr
[10]);
732 MLA(hi
, lo
, (*fe
)[4], ptr
[ 8]);
733 MLA(hi
, lo
, (*fe
)[5], ptr
[ 6]);
734 MLA(hi
, lo
, (*fe
)[6], ptr
[ 4]);
735 MLA(hi
, lo
, (*fe
)[7], ptr
[ 2]);
738 MLA(hi
, lo
, (*fx
)[0], -ptr
[ 0]);
739 MLA(hi
, lo
, (*fx
)[1], -ptr
[14]);
740 MLA(hi
, lo
, (*fx
)[2], -ptr
[12]);
741 MLA(hi
, lo
, (*fx
)[3], -ptr
[10]);
742 MLA(hi
, lo
, (*fx
)[4], -ptr
[ 8]);
743 MLA(hi
, lo
, (*fx
)[5], -ptr
[ 6]);
744 MLA(hi
, lo
, (*fx
)[6], -ptr
[ 4]);
745 MLA(hi
, lo
, (*fx
)[7], -ptr
[ 2]);
747 *pcm1
++ = SHIFT(MLZ(hi
, lo
));
751 for (sb
= 1; sb
< 16; ++sb
) {
755 /* D[32 - sb][i] == -D[sb][31 - i] */
759 ML0(hi
, lo
, (*fe
)[7], ptr
[ 2]);
760 MLA(hi
, lo
, (*fe
)[6], ptr
[ 4]);
761 MLA(hi
, lo
, (*fe
)[5], ptr
[ 6]);
762 MLA(hi
, lo
, (*fe
)[4], ptr
[ 8]);
763 MLA(hi
, lo
, (*fe
)[3], ptr
[10]);
764 MLA(hi
, lo
, (*fe
)[2], ptr
[12]);
765 MLA(hi
, lo
, (*fe
)[1], ptr
[14]);
766 MLA(hi
, lo
, (*fe
)[0], ptr
[ 0]);
769 MLA(hi
, lo
, (*fo
)[0], -ptr
[ 0]);
770 MLA(hi
, lo
, (*fo
)[1], -ptr
[14]);
771 MLA(hi
, lo
, (*fo
)[2], -ptr
[12]);
772 MLA(hi
, lo
, (*fo
)[3], -ptr
[10]);
773 MLA(hi
, lo
, (*fo
)[4], -ptr
[ 8]);
774 MLA(hi
, lo
, (*fo
)[5], -ptr
[ 6]);
775 MLA(hi
, lo
, (*fo
)[6], -ptr
[ 4]);
776 MLA(hi
, lo
, (*fo
)[7], -ptr
[ 2]);
778 *pcm1
++ = SHIFT(MLZ(hi
, lo
));
781 ML0(hi
, lo
, (*fo
)[7], ptr
[31 - 2]);
782 MLA(hi
, lo
, (*fo
)[6], ptr
[31 - 4]);
783 MLA(hi
, lo
, (*fo
)[5], ptr
[31 - 6]);
784 MLA(hi
, lo
, (*fo
)[4], ptr
[31 - 8]);
785 MLA(hi
, lo
, (*fo
)[3], ptr
[31 - 10]);
786 MLA(hi
, lo
, (*fo
)[2], ptr
[31 - 12]);
787 MLA(hi
, lo
, (*fo
)[1], ptr
[31 - 14]);
788 MLA(hi
, lo
, (*fo
)[0], ptr
[31 - 16]);
791 MLA(hi
, lo
, (*fe
)[0], ptr
[31 - 16]);
792 MLA(hi
, lo
, (*fe
)[1], ptr
[31 - 14]);
793 MLA(hi
, lo
, (*fe
)[2], ptr
[31 - 12]);
794 MLA(hi
, lo
, (*fe
)[3], ptr
[31 - 10]);
795 MLA(hi
, lo
, (*fe
)[4], ptr
[31 - 8]);
796 MLA(hi
, lo
, (*fe
)[5], ptr
[31 - 6]);
797 MLA(hi
, lo
, (*fe
)[6], ptr
[31 - 4]);
798 MLA(hi
, lo
, (*fe
)[7], ptr
[31 - 2]);
800 *pcm2
-- = SHIFT(MLZ(hi
, lo
));
809 ML0(hi
, lo
, (*fo
)[0], ptr
[ 0]);
810 MLA(hi
, lo
, (*fo
)[1], ptr
[14]);
811 MLA(hi
, lo
, (*fo
)[2], ptr
[12]);
812 MLA(hi
, lo
, (*fo
)[3], ptr
[10]);
813 MLA(hi
, lo
, (*fo
)[4], ptr
[ 8]);
814 MLA(hi
, lo
, (*fo
)[5], ptr
[ 6]);
815 MLA(hi
, lo
, (*fo
)[6], ptr
[ 4]);
816 MLA(hi
, lo
, (*fo
)[7], ptr
[ 2]);
818 *pcm1
= SHIFT(-MLZ(hi
, lo
));
821 phase
= (phase
+ 1) % 16;
827 * NAME: synth->frame()
828 * DESCRIPTION: perform PCM synthesis of frame subband samples
830 void mad_synth_frame(struct mad_synth
*synth
, struct mad_frame
const *frame
)
832 unsigned int nch
, ns
;
833 void (*synth_frame
)(struct mad_synth
*, struct mad_frame
const *,
834 unsigned int, unsigned int);
836 nch
= MAD_NCHANNELS(&frame
->header
);
837 ns
= MAD_NSBSAMPLES(&frame
->header
);
839 synth
->pcm
.samplerate
= frame
->header
.samplerate
;
840 synth
->pcm
.channels
= nch
;
841 synth
->pcm
.length
= 32 * ns
;
843 synth_frame
= synth_full
;
845 if (frame
->options
& MAD_OPTION_HALFSAMPLERATE
) {
846 synth
->pcm
.samplerate
/= 2;
847 synth
->pcm
.length
/= 2;
849 synth_frame
= synth_half
;
852 synth_frame(synth
, frame
, nch
, ns
);
854 synth
->phase
= (synth
->phase
+ ns
) % 16;