annotate src/libmad-0.15.1b/synth.c @ 169:223a55898ab9 tip default

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