| 1 |
|
| /* |
| 2 |
|
| * MPEG Audio decoder |
| 3 |
|
| * Copyright (c) 2001, 2002 Fabrice Bellard. |
| 4 |
|
| * |
| 5 |
|
| * This library is free software; you can redistribute it and/or |
| 6 |
|
| * modify it under the terms of the GNU Lesser General Public |
| 7 |
|
| * License as published by the Free Software Foundation; either |
| 8 |
|
| * version 2 of the License, or (at your option) any later version. |
| 9 |
|
| * |
| 10 |
|
| * This library 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 GNU |
| 13 |
|
| * Lesser General Public License for more details. |
| 14 |
|
| * |
| 15 |
|
| * You should have received a copy of the GNU Lesser General Public |
| 16 |
|
| * License along with this library; if not, write to the Free Software |
| 17 |
|
| * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 18 |
|
| */ |
| 19 |
|
| |
| 20 |
|
| /** |
| 21 |
|
| * @file mpegaudiodec.c |
| 22 |
|
| * MPEG Audio decoder. |
| 23 |
|
| */ |
| 24 |
|
| #undef DEBUG |
| 25 |
|
| |
| 26 |
|
| |
| 27 |
|
| #define inline |
| 28 |
|
| #define assert(X) |
| 29 |
|
| |
| 30 |
|
| // SDP |
| 31 |
|
| //#define DEBUG |
| 32 |
|
| //#define ADEBUG |
| 33 |
|
| |
| 34 |
|
| #ifdef DEBUG |
| 35 |
|
| #define dbg_printf printf |
| 36 |
|
| #else |
| 37 |
0 |
| void dbg_printf(const char* fmt,...) {} |
| 38 |
|
| #endif |
| 39 |
|
| |
| 40 |
|
| #include "common.h" |
| 41 |
|
| |
| 42 |
|
| //#define DEBUG |
| 43 |
|
| #include "avcodec.h" |
| 44 |
|
| //#include "bitstream.h" |
| 45 |
|
| #include "mpegaudio.h" |
| 46 |
|
| //#include "dsputil.h" |
| 47 |
|
| |
| 48 |
|
| /* |
| 49 |
|
| * TODO: |
| 50 |
|
| * - in low precision mode, use more 16 bit multiplies in synth filter |
| 51 |
|
| * - test lsf / mpeg25 extensively. |
| 52 |
|
| */ |
| 53 |
|
| |
| 54 |
|
| /* define USE_HIGHPRECISION to have a bit exact (but slower) mpeg |
| 55 |
|
| audio decoder */ |
| 56 |
|
| #ifdef CONFIG_MPEGAUDIO_HP |
| 57 |
|
| #define USE_HIGHPRECISION |
| 58 |
|
| #endif |
| 59 |
|
| |
| 60 |
|
| #ifdef USE_HIGHPRECISION |
| 61 |
|
| #define FRAC_BITS 23 /* fractional bits for sb_samples and dct */ |
| 62 |
|
| #define WFRAC_BITS 16 /* fractional bits for window */ |
| 63 |
|
| #else |
| 64 |
|
| #define FRAC_BITS 15 /* fractional bits for sb_samples and dct */ |
| 65 |
|
| #define WFRAC_BITS 14 /* fractional bits for window */ |
| 66 |
|
| #endif |
| 67 |
|
| |
| 68 |
|
| #if defined(USE_HIGHPRECISION) && defined(CONFIG_AUDIO_NONSHORT) |
| 69 |
|
| typedef int32_t OUT_INT; |
| 70 |
|
| #define OUT_MAX INT32_MAX |
| 71 |
|
| #define OUT_MIN INT32_MIN |
| 72 |
|
| #define OUT_SHIFT (WFRAC_BITS + FRAC_BITS - 31) |
| 73 |
|
| #else |
| 74 |
|
| typedef short OUT_INT; |
| 75 |
|
| #ifndef INT16_MAX |
| 76 |
|
| #define INT16_MAX 0x7fff |
| 77 |
|
| #endif |
| 78 |
|
| #ifndef INT16_MIN |
| 79 |
|
| #define INT16_MIN -0x7fff |
| 80 |
|
| #endif |
| 81 |
|
| #define OUT_MAX INT16_MAX |
| 82 |
|
| #define OUT_MIN INT16_MIN |
| 83 |
|
| #define OUT_SHIFT (WFRAC_BITS + FRAC_BITS - 15) |
| 84 |
|
| #endif |
| 85 |
|
| |
| 86 |
|
| #define FRAC_ONE (1 << FRAC_BITS) |
| 87 |
|
| |
| 88 |
|
| #define MULL(a,b) (((int64_t)(a) * (int64_t)(b)) >> FRAC_BITS) |
| 89 |
|
| #define MUL64(a,b) ((int64_t)(a) * (int64_t)(b)) |
| 90 |
|
| #define FIX(a) ((int)((a) * FRAC_ONE)) |
| 91 |
|
| /* WARNING: only correct for posititive numbers */ |
| 92 |
|
| #define FIXR(a) ((int)((a) * FRAC_ONE + 0.5)) |
| 93 |
|
| #define FRAC_RND(a) (((a) + (FRAC_ONE/2)) >> FRAC_BITS) |
| 94 |
|
| |
| 95 |
|
| #define FIXHR(a) ((int)((a) * ((int64_t)1<<32) + 0.5)) |
| 96 |
|
| #define MULH(a,b) (((int64_t)(a) * (int64_t)(b))>>32) //gcc 3.4 creates an incredibly bloated mess out of this |
| 97 |
|
| //static int inline MULH (int a, int b){ |
| 98 |
|
| // return ((int64_t)(a) * (int64_t)(b))>>32; |
| 99 |
|
| //} |
| 100 |
|
| |
| 101 |
|
| #if FRAC_BITS <= 15 |
| 102 |
|
| typedef short MPA_INT; |
| 103 |
|
| #else |
| 104 |
|
| typedef int32_t MPA_INT; |
| 105 |
|
| #endif |
| 106 |
|
| |
| 107 |
|
| /****************/ |
| 108 |
|
| |
| 109 |
|
| #define HEADER_SIZE 4 |
| 110 |
|
| #define BACKSTEP_SIZE 512 |
| 111 |
|
| |
| 112 |
|
| //#define uint8_t unsigned char |
| 113 |
|
| //#define int8_t char |
| 114 |
|
| //#define uint32_t unsigned long |
| 115 |
|
| //#define int32_t long |
| 116 |
|
| //#define uint16_t unsigned short |
| 117 |
|
| //#define int16_t short |
| 118 |
|
| // typedef signed __int64 int64_t; |
| 119 |
|
| // typedef unsigned __int64 uint64_t; |
| 120 |
|
| |
| 121 |
0 |
| static inline int ff_mpa_check_header(uint32_t header){ |
| 122 |
|
| /* header */ |
| 123 |
0 |
▶ | if ((header & 0xffe00000) != 0xffe00000) |
Branch: 1 branch
| Branch | True | False | Total |
| if ((header & 0xffe00000) != 0xffe00000) |
0 |
0 |
0 |
|
| 124 |
0 |
| return -1; |
| 125 |
|
| /* layer check */ |
| 126 |
0 |
▶ | if ((header & (3<<17)) == 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if ((header & (3<<17)) == 0) |
0 |
0 |
0 |
|
| 127 |
0 |
| return -1; |
| 128 |
|
| /* bit rate */ |
| 129 |
0 |
▶ | if ((header & (0xf<<12)) == 0xf<<12) |
Branch: 1 branch
| Branch | True | False | Total |
| if ((header & (0xf<<12)) == 0xf<<12) |
0 |
0 |
0 |
|
| 130 |
0 |
| return -1; |
| 131 |
|
| /* frequency */ |
| 132 |
0 |
▶ | if ((header & (3<<10)) == 3<<10) |
Branch: 1 branch
| Branch | True | False | Total |
| if ((header & (3<<10)) == 3<<10) |
0 |
0 |
0 |
|
| 133 |
0 |
| return -1; |
| 134 |
0 |
| return 0; |
| 135 |
|
| } |
| 136 |
|
| |
| 137 |
|
| |
| 138 |
|
| |
| 139 |
|
| #define FF_AA_AUTO 0 |
| 140 |
|
| #define FF_AA_FASTINT 1 //not implemented yet |
| 141 |
|
| #define FF_AA_INT 2 |
| 142 |
|
| #define FF_AA_FLOAT 3 |
| 143 |
|
| |
| 144 |
|
| struct GranuleDef; |
| 145 |
|
| |
| 146 |
|
| typedef struct MPADecodeContext { |
| 147 |
|
| uint8_t inbuf1[2][MPA_MAX_CODED_FRAME_SIZE + BACKSTEP_SIZE]; /* input buffer */ |
| 148 |
|
| int inbuf_index; |
| 149 |
|
| uint8_t *inbuf_ptr, *inbuf; |
| 150 |
|
| int frame_size; |
| 151 |
|
| int free_format_frame_size; /* frame size in case of free format |
| 152 |
|
| (zero if currently unknown) */ |
| 153 |
|
| /* next header (used in free format parsing) */ |
| 154 |
|
| uint32_t free_format_next_header; |
| 155 |
|
| int error_protection; |
| 156 |
|
| int layer; |
| 157 |
|
| int sample_rate; |
| 158 |
|
| int sample_rate_index; /* between 0 and 8 */ |
| 159 |
|
| int bit_rate; |
| 160 |
|
| int old_frame_size; |
| 161 |
|
| GetBitContext gb; |
| 162 |
|
| // int gb; |
| 163 |
|
| int nb_channels; |
| 164 |
|
| int mode; |
| 165 |
|
| int mode_ext; |
| 166 |
|
| int lsf; |
| 167 |
|
| MPA_INT synth_buf[MPA_MAX_CHANNELS][512 * 2] ; // __attribute__((aligned(16))); |
| 168 |
|
| int synth_buf_offset[MPA_MAX_CHANNELS]; |
| 169 |
|
| int32_t sb_samples[MPA_MAX_CHANNELS][36][SBLIMIT]; // __attribute__((aligned(16))); |
| 170 |
|
| int32_t mdct_buf[MPA_MAX_CHANNELS][SBLIMIT * 18]; /* previous samples, for layer 3 MDCT */ |
| 171 |
|
| //#ifdef DEBUG |
| 172 |
|
| int frame_count; |
| 173 |
|
| //#endif |
| 174 |
|
| // void (*compute_antialias)(struct MPADecodeContext *s, struct GranuleDef *g); |
| 175 |
|
| int adu_mode; ///< 0 for standard mp3, 1 for adu formatted mp3 |
| 176 |
|
| unsigned int dither_state; |
| 177 |
|
| } MPADecodeContext; |
| 178 |
|
| |
| 179 |
|
| /* |
| 180 |
|
| typedef struct AVCodecContext{ |
| 181 |
|
| MPADecodeContext *priv_data; |
| 182 |
|
| int sample_fmt; |
| 183 |
|
| int antialias_algo; |
| 184 |
|
| int parse_only; |
| 185 |
|
| int codec_id; |
| 186 |
|
| int frame_size; |
| 187 |
|
| int sample_rate; |
| 188 |
|
| int channels; |
| 189 |
|
| int bit_rate; |
| 190 |
|
| int sub_id; |
| 191 |
|
| |
| 192 |
|
| } AVCodecContext; |
| 193 |
|
| */ |
| 194 |
|
| MPADecodeContext MPAContext; |
| 195 |
|
| |
| 196 |
|
| AVCodecContext CodecContext = { |
| 197 |
|
| &MPAContext, |
| 198 |
|
| 0, |
| 199 |
|
| 0, |
| 200 |
|
| 0, |
| 201 |
|
| 0, |
| 202 |
|
| 0, |
| 203 |
|
| 0, |
| 204 |
|
| 0, |
| 205 |
|
| 0, |
| 206 |
|
| 0 |
| 207 |
|
| }; |
| 208 |
|
| |
| 209 |
|
| AVCodecContext * avctx = &CodecContext; |
| 210 |
|
| |
| 211 |
|
| |
| 212 |
|
| /** |
| 213 |
|
| * Context for MP3On4 decoder |
| 214 |
|
| */ |
| 215 |
|
| typedef struct MP3On4DecodeContext { |
| 216 |
|
| int frames; ///< number of mp3 frames per block (number of mp3 decoder instances) |
| 217 |
|
| int chan_cfg; ///< channel config number |
| 218 |
|
| MPADecodeContext *mp3decctx[5]; ///< MPADecodeContext for every decoder instance |
| 219 |
|
| } MP3On4DecodeContext; |
| 220 |
|
| |
| 221 |
|
| /* layer 3 "granule" */ |
| 222 |
|
| typedef struct GranuleDef { |
| 223 |
|
| uint8_t scfsi; |
| 224 |
|
| int part2_3_length; |
| 225 |
|
| int big_values; |
| 226 |
|
| int global_gain; |
| 227 |
|
| int scalefac_compress; |
| 228 |
|
| uint8_t block_type; |
| 229 |
|
| uint8_t switch_point; |
| 230 |
|
| int table_select[3]; |
| 231 |
|
| int subblock_gain[3]; |
| 232 |
|
| uint8_t scalefac_scale; |
| 233 |
|
| uint8_t count1table_select; |
| 234 |
|
| int region_size[3]; /* number of huffman codes in each region */ |
| 235 |
|
| int preflag; |
| 236 |
|
| int short_start, long_end; /* long/short band indexes */ |
| 237 |
|
| uint8_t scale_factors[40]; |
| 238 |
|
| int32_t sb_hybrid[SBLIMIT * 18]; /* 576 samples */ |
| 239 |
|
| } GranuleDef; |
| 240 |
|
| |
| 241 |
|
| #define MODE_EXT_MS_STEREO 2 |
| 242 |
|
| #define MODE_EXT_I_STEREO 1 |
| 243 |
|
| |
| 244 |
|
| /* layer 3 huffman tables */ |
| 245 |
|
| typedef struct HuffTable { |
| 246 |
|
| int xsize; |
| 247 |
|
| const uint8_t *bits; |
| 248 |
|
| const uint16_t *codes; |
| 249 |
|
| } HuffTable; |
| 250 |
|
| |
| 251 |
|
| #ifndef NULL |
| 252 |
|
| #define NULL 0 |
| 253 |
|
| #endif |
| 254 |
|
| |
| 255 |
|
| #include "mpegaudiodectab.h" |
| 256 |
|
| |
| 257 |
|
| //static void compute_antialias_integer(MPADecodeContext *s, GranuleDef *g); |
| 258 |
|
| //static void compute_antialias_float(MPADecodeContext *s, GranuleDef *g); |
| 259 |
|
| |
| 260 |
|
| /* vlc structure for decoding layer 3 huffman tables */ |
| 261 |
|
| #define VLC_TYPE int16_t |
| 262 |
|
| |
| 263 |
|
| //typedef struct VLC { |
| 264 |
|
| // int bits; |
| 265 |
|
| // VLC_TYPE (*table)[2]; ///< code, bits |
| 266 |
|
| // int table_size, table_allocated; |
| 267 |
|
| //} VLC; |
| 268 |
|
| |
| 269 |
|
| //typedef struct RL_VLC_ELEM { |
| 270 |
|
| // int16_t level; |
| 271 |
|
| // int8_t len; |
| 272 |
|
| // uint8_t run; |
| 273 |
|
| //} RL_VLC_ELEM; |
| 274 |
|
| |
| 275 |
|
| |
| 276 |
|
| static VLC huff_vlc[16]; |
| 277 |
|
| static uint8_t *huff_code_table[16]; |
| 278 |
|
| static VLC huff_quad_vlc[2]; |
| 279 |
|
| /* computed from band_size_long */ |
| 280 |
|
| static uint16_t band_index_long[9][23]; |
| 281 |
|
| /* XXX: free when all decoders are closed */ |
| 282 |
|
| #define TABLE_4_3_SIZE (8191 + 16)*4 |
| 283 |
|
| static int8_t *table_4_3_exp; |
| 284 |
|
| static uint32_t *table_4_3_value; |
| 285 |
|
| /* intensity stereo coef table */ |
| 286 |
|
| static int32_t is_table[2][16]; |
| 287 |
|
| static int32_t is_table_lsf[2][2][16]; |
| 288 |
|
| static int32_t csa_table[8][4]; |
| 289 |
|
| static float csa_table_float[8][4]; |
| 290 |
|
| static int32_t mdct_win[8][36]; |
| 291 |
|
| |
| 292 |
|
| /* lower 2 bits: modulo 3, higher bits: shift */ |
| 293 |
|
| static uint16_t scale_factor_modshift[64]; |
| 294 |
|
| /* [i][j]: 2^(-j/3) * FRAC_ONE * 2^(i+2) / (2^(i+2) - 1) */ |
| 295 |
|
| static int32_t scale_factor_mult[15][3]; |
| 296 |
|
| /* mult table for layer 2 group quantization */ |
| 297 |
|
| |
| 298 |
|
| #define SCALE_GEN(v) \ |
| 299 |
|
| { FIXR(1.0 * (v)), FIXR(0.7937005259 * (v)), FIXR(0.6299605249 * (v)) } |
| 300 |
|
| |
| 301 |
|
| static int32_t scale_factor_mult2[3][3] = { |
| 302 |
|
| SCALE_GEN(4.0 / 3.0), /* 3 steps */ |
| 303 |
|
| SCALE_GEN(4.0 / 5.0), /* 5 steps */ |
| 304 |
|
| SCALE_GEN(4.0 / 9.0), /* 9 steps */ |
| 305 |
|
| }; |
| 306 |
|
| |
| 307 |
|
| void ff_mpa_synth_init(MPA_INT *window); |
| 308 |
|
| static MPA_INT window[512];// __attribute__((aligned(16))); |
| 309 |
|
| |
| 310 |
|
| /* layer 1 unscaling */ |
| 311 |
|
| /* n = number of bits of the mantissa minus 1 */ |
| 312 |
0 |
| static inline int l1_unscale (int n, int mant, int scale_factor) |
| 313 |
|
| { |
| 314 |
|
| int shift, mod; |
| 315 |
|
| int64_t val; |
| 316 |
|
| |
| 317 |
0 |
| shift = scale_factor_modshift[scale_factor]; |
| 318 |
0 |
| mod = shift & 3; |
| 319 |
0 |
| shift >>= 2; |
| 320 |
0 |
| val = MUL64(mant + (-1 << n) + 1, scale_factor_mult[n-1][mod]); |
| 321 |
0 |
| shift += n; |
| 322 |
|
| /* NOTE: at this point, 1 <= shift >= 21 + 15 */ |
| 323 |
0 |
| return (int)((val + ((int64_t)1 << (shift - 1))) >> shift); |
| 324 |
|
| } |
| 325 |
|
| |
| 326 |
0 |
| static inline int l2_unscale_group(int steps, int mant, int scale_factor) |
| 327 |
|
| { |
| 328 |
|
| int shift, mod, val; |
| 329 |
|
| |
| 330 |
0 |
| shift = scale_factor_modshift[scale_factor]; |
| 331 |
0 |
| mod = shift & 3; |
| 332 |
0 |
| shift >>= 2; |
| 333 |
|
| |
| 334 |
0 |
| val = (mant - (steps >> 1)) * scale_factor_mult2[steps >> 2][mod]; |
| 335 |
|
| /* NOTE: at this point, 0 <= shift <= 21 */ |
| 336 |
0 |
▶ | if (shift > 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if (shift > 0) |
0 |
0 |
0 |
|
| 337 |
0 |
| val = (val + (1 << (shift - 1))) >> shift; |
| 338 |
0 |
| return val; |
| 339 |
|
| } |
| 340 |
|
| |
| 341 |
|
| /* compute value^(4/3) * 2^(exponent/4). It normalized to FRAC_BITS */ |
| 342 |
0 |
| static inline int l3_unscale(int value, int exponent) |
| 343 |
|
| { |
| 344 |
|
| unsigned int m; |
| 345 |
|
| int e; |
| 346 |
|
| |
| 347 |
0 |
| e = table_4_3_exp [4*value + (exponent&3)]; |
| 348 |
0 |
| m = table_4_3_value[4*value + (exponent&3)]; |
| 349 |
0 |
| e -= (exponent >> 2); |
| 350 |
|
| assert(e>=1); |
| 351 |
0 |
▶ | if (e > 31) |
Branch: 1 branch
| Branch | True | False | Total |
| if (e > 31) |
0 |
0 |
0 |
|
| 352 |
0 |
| return 0; |
| 353 |
0 |
| m = (m + (1 << (e-1))) >> e; |
| 354 |
|
| |
| 355 |
0 |
| return m; |
| 356 |
|
| } |
| 357 |
|
| |
| 358 |
|
| /* all integer n^(4/3) computation code */ |
| 359 |
|
| #define DEV_ORDER 13 |
| 360 |
|
| |
| 361 |
|
| #define POW_FRAC_BITS 24 |
| 362 |
|
| #define POW_FRAC_ONE (1 << POW_FRAC_BITS) |
| 363 |
|
| #define POW_FIX(a) ((int)((a) * POW_FRAC_ONE)) |
| 364 |
|
| #define POW_MULL(a,b) (((int64_t)(a) * (int64_t)(b)) >> POW_FRAC_BITS) |
| 365 |
|
| |
| 366 |
|
| static int dev_4_3_coefs[DEV_ORDER]; |
| 367 |
|
| |
| 368 |
|
| |
| 369 |
0 |
| static void int_pow_init(void) |
| 370 |
|
| { |
| 371 |
|
| int i, a; |
| 372 |
|
| |
| 373 |
0 |
| a = POW_FIX(1.0); |
| 374 |
0 |
▶ | for(i=0;i<DEV_ORDER;i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(i=0;i<DEV_ORDER;i++) { |
0 |
0 |
0 |
|
| 375 |
0 |
| a = POW_MULL(a, POW_FIX(4.0 / 3.0) - i * POW_FIX(1.0)) / (i + 1); |
| 376 |
0 |
| dev_4_3_coefs[i] = a; |
| 377 |
|
| } |
| 378 |
0 |
| } |
| 379 |
|
| |
| 380 |
|
| |
| 381 |
0 |
| int decode_init() |
| 382 |
|
| { |
| 383 |
0 |
| MPADecodeContext *s = avctx->priv_data; |
| 384 |
|
| static int init=0; |
| 385 |
|
| int i, j, k; |
| 386 |
0 |
| avctx->priv_data = s = &MPAContext; |
| 387 |
|
| |
| 388 |
|
| #if defined(USE_HIGHPRECISION) && defined(CONFIG_AUDIO_NONSHORT) |
| 389 |
|
| avctx->sample_fmt= SAMPLE_FMT_S32; |
| 390 |
|
| #else |
| 391 |
0 |
| avctx->sample_fmt= SAMPLE_FMT_S16; |
| 392 |
|
| #endif |
| 393 |
|
| |
| 394 |
|
| // if(avctx->antialias_algo != FF_AA_FLOAT) |
| 395 |
|
| // s->compute_antialias= compute_antialias_integer; |
| 396 |
|
| // else |
| 397 |
|
| // s->compute_antialias= compute_antialias_float; |
| 398 |
|
| |
| 399 |
0 |
▶ | if (!init && !avctx->parse_only) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (!init && !avctx->parse_only) { |
0 |
0 |
0 |
| if (!init && !avctx->parse_only) { |
0 |
0 |
0 |
|
| 400 |
|
| /* scale factors table for layer 1/2 */ |
| 401 |
0 |
▶ | for(i=0;i<64;i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(i=0;i<64;i++) { |
0 |
0 |
0 |
|
| 402 |
|
| int shift, mod; |
| 403 |
|
| /* 1.0 (i = 3) is normalized to 2 ^ FRAC_BITS */ |
| 404 |
0 |
| shift = (i / 3); |
| 405 |
0 |
| mod = i % 3; |
| 406 |
0 |
| scale_factor_modshift[i] = mod | (shift << 2); |
| 407 |
|
| } |
| 408 |
|
| |
| 409 |
|
| /* scale factor multiply for layer 1 */ |
| 410 |
0 |
▶ | for(i=0;i<15;i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(i=0;i<15;i++) { |
0 |
0 |
0 |
|
| 411 |
|
| int n, norm; |
| 412 |
0 |
| n = i + 2; |
| 413 |
0 |
| norm = ((int64_t_C(1) << n) * FRAC_ONE) / ((1 << n) - 1); |
| 414 |
0 |
| scale_factor_mult[i][0] = MULL(FIXR(1.0 * 2.0), norm); |
| 415 |
0 |
| scale_factor_mult[i][1] = MULL(FIXR(0.7937005259 * 2.0), norm); |
| 416 |
0 |
| scale_factor_mult[i][2] = MULL(FIXR(0.6299605249 * 2.0), norm); |
| 417 |
0 |
| dbg_printf("%d: norm=%x s=%x %x %x\n", |
| 418 |
|
| i, norm, |
| 419 |
|
| scale_factor_mult[i][0], |
| 420 |
|
| scale_factor_mult[i][1], |
| 421 |
|
| scale_factor_mult[i][2]); |
| 422 |
|
| } |
| 423 |
|
| |
| 424 |
0 |
| ff_mpa_synth_init(window); |
| 425 |
|
| |
| 426 |
|
| |
| 427 |
|
| /* huffman decode tables */ |
| 428 |
0 |
| huff_code_table[0] = NULL; |
| 429 |
0 |
▶ | for(i=1;i<16;i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(i=1;i<16;i++) { |
0 |
0 |
0 |
|
| 430 |
0 |
| const HuffTable *h = &mpa_huff_tables[i]; |
| 431 |
|
| int xsize, x, y; |
| 432 |
|
| unsigned int n; |
| 433 |
|
| uint8_t *code_table; |
| 434 |
|
| |
| 435 |
0 |
| xsize = h->xsize; |
| 436 |
0 |
| n = xsize * xsize; |
| 437 |
|
| /* XXX: fail test */ |
| 438 |
|
| // init_vlc(&huff_vlc[i], 8, n, |
| 439 |
|
| // h->bits, 1, 1, h->codes, 2, 2, 1); |
| 440 |
|
| |
| 441 |
0 |
| code_table = av_mallocz(n); |
| 442 |
0 |
| j = 0; |
| 443 |
0 |
▶ | for(x=0;x<xsize;x++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(x=0;x<xsize;x++) { |
0 |
0 |
0 |
|
| 444 |
0 |
▶ | for(y=0;y<xsize;y++) |
Branch: 1 branch
| Branch | True | False | Total |
| for(y=0;y<xsize;y++) |
0 |
0 |
0 |
|
| 445 |
0 |
| code_table[j++] = (x << 4) | y; |
| 446 |
|
| } |
| 447 |
0 |
| huff_code_table[i] = code_table; |
| 448 |
|
| } |
| 449 |
0 |
▶ | for(i=0;i<2;i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(i=0;i<2;i++) { |
0 |
0 |
0 |
|
| 450 |
|
| // init_vlc(&huff_quad_vlc[i], i == 0 ? 7 : 4, 16, |
| 451 |
|
| // mpa_quad_bits[i], 1, 1, mpa_quad_codes[i], 1, 1, 1); |
| 452 |
|
| } |
| 453 |
|
| |
| 454 |
0 |
▶ | for(i=0;i<9;i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(i=0;i<9;i++) { |
0 |
0 |
0 |
|
| 455 |
0 |
| k = 0; |
| 456 |
0 |
▶ | for(j=0;j<22;j++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(j=0;j<22;j++) { |
0 |
0 |
0 |
|
| 457 |
0 |
| band_index_long[i][j] = k; |
| 458 |
0 |
| k += band_size_long[i][j]; |
| 459 |
|
| } |
| 460 |
0 |
| band_index_long[i][22] = k; |
| 461 |
|
| } |
| 462 |
|
| |
| 463 |
|
| /* compute n ^ (4/3) and store it in mantissa/exp format */ |
| 464 |
0 |
| table_4_3_exp= av_mallocz_static(&table_4_3_exp, TABLE_4_3_SIZE * sizeof(table_4_3_exp[0])); |
| 465 |
0 |
▶ | if(!table_4_3_exp) |
Branch: 1 branch
| Branch | True | False | Total |
| if(!table_4_3_exp) |
0 |
0 |
0 |
|
| 466 |
0 |
| return -1; |
| 467 |
0 |
| table_4_3_value= av_mallocz_static(&table_4_3_value, TABLE_4_3_SIZE * sizeof(table_4_3_value[0])); |
| 468 |
0 |
▶ | if(!table_4_3_value) |
Branch: 1 branch
| Branch | True | False | Total |
| if(!table_4_3_value) |
0 |
0 |
0 |
|
| 469 |
0 |
| return -1; |
| 470 |
|
| |
| 471 |
0 |
| int_pow_init(); |
| 472 |
0 |
▶ | for(i=1;i<TABLE_4_3_SIZE;i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(i=1;i<TABLE_4_3_SIZE;i++) { |
0 |
0 |
0 |
|
| 473 |
|
| double f, fm; |
| 474 |
|
| int e, m; |
| 475 |
0 |
| f = pow((double)(i/4), 4.0 / 3.0) * pow(2, (i&3)*0.25); |
| 476 |
0 |
| fm = frexp(f, &e); |
| 477 |
0 |
| m = (uint32_t)(fm*((int64_t)1<<31) + 0.5); |
| 478 |
0 |
| e+= FRAC_BITS - 31 + 5; |
| 479 |
|
| |
| 480 |
|
| /* normalized to FRAC_BITS */ |
| 481 |
0 |
| table_4_3_value[i] = m; |
| 482 |
|
| // av_log(NULL, AV_LOG_DEBUG, "%d %d %f\n", i, m, pow((double)i, 4.0 / 3.0)); |
| 483 |
0 |
| table_4_3_exp[i] = -e; |
| 484 |
|
| } |
| 485 |
|
| |
| 486 |
0 |
▶ | for(i=0;i<7;i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(i=0;i<7;i++) { |
0 |
0 |
0 |
|
| 487 |
|
| float f; |
| 488 |
|
| int v; |
| 489 |
0 |
▶ | if (i != 6) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (i != 6) { |
0 |
0 |
0 |
|
| 490 |
0 |
| f = tan((double)i * M_PI / 12.0); |
| 491 |
0 |
| v = FIXR(f / (1.0 + f)); |
| 492 |
|
| } else { |
| 493 |
0 |
| v = FIXR(1.0); |
| 494 |
|
| } |
| 495 |
0 |
| is_table[0][i] = v; |
| 496 |
0 |
| is_table[1][6 - i] = v; |
| 497 |
|
| } |
| 498 |
|
| /* invalid values */ |
| 499 |
0 |
▶ | for(i=7;i<16;i++) |
Branch: 1 branch
| Branch | True | False | Total |
| for(i=7;i<16;i++) |
0 |
0 |
0 |
|
| 500 |
0 |
| is_table[0][i] = is_table[1][i] = 0.0; |
| 501 |
|
| |
| 502 |
0 |
▶ | for(i=0;i<16;i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(i=0;i<16;i++) { |
0 |
0 |
0 |
|
| 503 |
|
| double f; |
| 504 |
|
| int e, k; |
| 505 |
|
| |
| 506 |
0 |
▶ | for(j=0;j<2;j++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(j=0;j<2;j++) { |
0 |
0 |
0 |
|
| 507 |
0 |
| e = -(j + 1) * ((i + 1) >> 1); |
| 508 |
0 |
| f = pow(2.0, e / 4.0); |
| 509 |
0 |
| k = i & 1; |
| 510 |
0 |
| is_table_lsf[j][k ^ 1][i] = FIXR(f); |
| 511 |
0 |
| is_table_lsf[j][k][i] = FIXR(1.0); |
| 512 |
0 |
| dbg_printf("is_table_lsf %d %d: %x %x\n", |
| 513 |
|
| i, j, is_table_lsf[j][0][i], is_table_lsf[j][1][i]); |
| 514 |
|
| } |
| 515 |
|
| } |
| 516 |
|
| |
| 517 |
0 |
▶ | for(i=0;i<8;i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(i=0;i<8;i++) { |
0 |
0 |
0 |
|
| 518 |
|
| float ci, cs, ca; |
| 519 |
0 |
| ci = ci_table[i]; |
| 520 |
0 |
| cs = 1.0 / sqrt(1.0 + ci * ci); |
| 521 |
0 |
| ca = cs * ci; |
| 522 |
0 |
| csa_table[i][0] = FIXHR(cs/4); |
| 523 |
0 |
| csa_table[i][1] = FIXHR(ca/4); |
| 524 |
0 |
| csa_table[i][2] = FIXHR(ca/4) + FIXHR(cs/4); |
| 525 |
0 |
| csa_table[i][3] = FIXHR(ca/4) - FIXHR(cs/4); |
| 526 |
0 |
| csa_table_float[i][0] = cs; |
| 527 |
0 |
| csa_table_float[i][1] = ca; |
| 528 |
0 |
| csa_table_float[i][2] = ca + cs; |
| 529 |
0 |
| csa_table_float[i][3] = ca - cs; |
| 530 |
|
| // printf("%d %d %d %d\n", FIX(cs), FIX(cs-1), FIX(ca), FIX(cs)-FIX(ca)); |
| 531 |
|
| // av_log(NULL, AV_LOG_DEBUG,"%f %f %f %f\n", cs, ca, ca+cs, ca-cs); |
| 532 |
|
| } |
| 533 |
|
| |
| 534 |
|
| /* compute mdct windows */ |
| 535 |
0 |
▶ | for(i=0;i<36;i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(i=0;i<36;i++) { |
0 |
0 |
0 |
|
| 536 |
0 |
▶ | for(j=0; j<4; j++){ |
Branch: 1 branch
| Branch | True | False | Total |
| for(j=0; j<4; j++){ |
0 |
0 |
0 |
|
| 537 |
|
| double d; |
| 538 |
|
| |
| 539 |
0 |
▶ | if(j==2 && i%3 != 1) |
Branch: 2 branches
| Branch | True | False | Total |
| if(j==2 && i%3 != 1) |
0 |
0 |
0 |
| if(j==2 && i%3 != 1) |
0 |
0 |
0 |
|
| 540 |
0 |
| continue; |
| 541 |
|
| |
| 542 |
0 |
| d= sin(M_PI * (i + 0.5) / 36.0); |
| 543 |
0 |
▶ | if(j==1){ |
Branch: 1 branch
| Branch | True | False | Total |
| if(j==1){ |
0 |
0 |
0 |
|
| 544 |
0 |
▶ | if (i>=30) d= 0; |
Branch: 1 branch
| Branch | True | False | Total |
| if (i>=30) d= 0; |
0 |
0 |
0 |
|
| 545 |
0 |
▶ | else if(i>=24) d= sin(M_PI * (i - 18 + 0.5) / 12.0); |
Branch: 1 branch
| Branch | True | False | Total |
| else if(i>=24) d= sin(M_PI * (i - 18 + 0.5) / 12.0); |
0 |
0 |
0 |
|
| 546 |
0 |
▶ | else if(i>=18) d= 1; |
Branch: 1 branch
| Branch | True | False | Total |
| else if(i>=18) d= 1; |
0 |
0 |
0 |
|
| 547 |
0 |
▶ | }else if(j==3){ |
Branch: 1 branch
| Branch | True | False | Total |
| }else if(j==3){ |
0 |
0 |
0 |
|
| 548 |
0 |
▶ | if (i< 6) d= 0; |
Branch: 1 branch
| Branch | True | False | Total |
| if (i< 6) d= 0; |
0 |
0 |
0 |
|
| 549 |
0 |
▶ | else if(i< 12) d= sin(M_PI * (i - 6 + 0.5) / 12.0); |
Branch: 1 branch
| Branch | True | False | Total |
| else if(i< 12) d= sin(M_PI * (i - 6 + 0.5) / 12.0); |
0 |
0 |
0 |
|
| 550 |
0 |
▶ | else if(i< 18) d= 1; |
Branch: 1 branch
| Branch | True | False | Total |
| else if(i< 18) d= 1; |
0 |
0 |
0 |
|
| 551 |
|
| } |
| 552 |
|
| //merge last stage of imdct into the window coefficients |
| 553 |
0 |
| d*= 0.5 / cos(M_PI*(2*i + 19)/72); |
| 554 |
|
| |
| 555 |
0 |
▶ | if(j==2) |
Branch: 1 branch
| Branch | True | False | Total |
| if(j==2) |
0 |
0 |
0 |
|
| 556 |
0 |
| mdct_win[j][i/3] = FIXHR((d / (1<<5))); |
| 557 |
|
| else |
| 558 |
0 |
| mdct_win[j][i ] = FIXHR((d / (1<<5))); |
| 559 |
|
| // av_log(NULL, AV_LOG_DEBUG, "%2d %d %f\n", i,j,d / (1<<5)); |
| 560 |
|
| } |
| 561 |
|
| } |
| 562 |
|
| |
| 563 |
|
| /* NOTE: we do frequency inversion adter the MDCT by changing |
| 564 |
|
| the sign of the right window coefs */ |
| 565 |
0 |
▶ | for(j=0;j<4;j++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(j=0;j<4;j++) { |
0 |
0 |
0 |
|
| 566 |
0 |
▶ | for(i=0;i<36;i+=2) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(i=0;i<36;i+=2) { |
0 |
0 |
0 |
|
| 567 |
0 |
| mdct_win[j + 4][i] = mdct_win[j][i]; |
| 568 |
0 |
| mdct_win[j + 4][i + 1] = -mdct_win[j][i + 1]; |
| 569 |
|
| } |
| 570 |
|
| } |
| 571 |
|
| |
| 572 |
|
| #if defined(ADEBUG) |
| 573 |
|
| for(j=0;j<8;j++) { |
| 574 |
|
| printf("win%d=\n", j); |
| 575 |
|
| for(i=0;i<36;i++) |
| 576 |
|
| printf("%f, ", (double)mdct_win[j][i] / FRAC_ONE); |
| 577 |
|
| printf("\n"); |
| 578 |
|
| } |
| 579 |
|
| #endif |
| 580 |
0 |
| init = 1; |
| 581 |
|
| } |
| 582 |
|
| |
| 583 |
0 |
| s->inbuf_index = 0; |
| 584 |
0 |
| s->inbuf = &s->inbuf1[s->inbuf_index][BACKSTEP_SIZE]; |
| 585 |
0 |
| s->inbuf_ptr = s->inbuf; |
| 586 |
|
| //#ifdef ADEBUG |
| 587 |
0 |
| s->frame_count = 0; |
| 588 |
|
| //#endif |
| 589 |
|
| // if (avctx->codec_id == CODEC_ID_MP3ADU) |
| 590 |
|
| // s->adu_mode = 1; |
| 591 |
0 |
| return 0; |
| 592 |
|
| } |
| 593 |
|
| |
| 594 |
|
| /* tab[i][j] = 1.0 / (2.0 * cos(pi*(2*k+1) / 2^(6 - j))) */ |
| 595 |
|
| |
| 596 |
|
| /* cos(i*pi/64) */ |
| 597 |
|
| |
| 598 |
|
| #define COS0_0 FIXR(0.50060299823519630134) |
| 599 |
|
| #define COS0_1 FIXR(0.50547095989754365998) |
| 600 |
|
| #define COS0_2 FIXR(0.51544730992262454697) |
| 601 |
|
| #define COS0_3 FIXR(0.53104259108978417447) |
| 602 |
|
| #define COS0_4 FIXR(0.55310389603444452782) |
| 603 |
|
| #define COS0_5 FIXR(0.58293496820613387367) |
| 604 |
|
| #define COS0_6 FIXR(0.62250412303566481615) |
| 605 |
|
| #define COS0_7 FIXR(0.67480834145500574602) |
| 606 |
|
| #define COS0_8 FIXR(0.74453627100229844977) |
| 607 |
|
| #define COS0_9 FIXR(0.83934964541552703873) |
| 608 |
|
| #define COS0_10 FIXR(0.97256823786196069369) |
| 609 |
|
| #define COS0_11 FIXR(1.16943993343288495515) |
| 610 |
|
| #define COS0_12 FIXR(1.48416461631416627724) |
| 611 |
|
| #define COS0_13 FIXR(2.05778100995341155085) |
| 612 |
|
| #define COS0_14 FIXR(3.40760841846871878570) |
| 613 |
|
| #define COS0_15 FIXR(10.19000812354805681150) |
| 614 |
|
| |
| 615 |
|
| #define COS1_0 FIXR(0.50241928618815570551) |
| 616 |
|
| #define COS1_1 FIXR(0.52249861493968888062) |
| 617 |
|
| #define COS1_2 FIXR(0.56694403481635770368) |
| 618 |
|
| #define COS1_3 FIXR(0.64682178335999012954) |
| 619 |
|
| #define COS1_4 FIXR(0.78815462345125022473) |
| 620 |
|
| #define COS1_5 FIXR(1.06067768599034747134) |
| 621 |
|
| #define COS1_6 FIXR(1.72244709823833392782) |
| 622 |
|
| #define COS1_7 FIXR(5.10114861868916385802) |
| 623 |
|
| |
| 624 |
|
| #define COS2_0 FIXR(0.50979557910415916894) |
| 625 |
|
| #define COS2_1 FIXR(0.60134488693504528054) |
| 626 |
|
| #define COS2_2 FIXR(0.89997622313641570463) |
| 627 |
|
| #define COS2_3 FIXR(2.56291544774150617881) |
| 628 |
|
| |
| 629 |
|
| #define COS3_0 FIXR(0.54119610014619698439) |
| 630 |
|
| #define COS3_1 FIXR(1.30656296487637652785) |
| 631 |
|
| |
| 632 |
|
| #define COS4_0 FIXR(0.70710678118654752439) |
| 633 |
|
| |
| 634 |
|
| /* butterfly operator */ |
| 635 |
|
| #define BF(a, b, c)\ |
| 636 |
|
| {\ |
| 637 |
|
| tmp0 = tab[a] + tab[b];\ |
| 638 |
|
| tmp1 = tab[a] - tab[b];\ |
| 639 |
|
| tab[a] = tmp0;\ |
| 640 |
|
| tab[b] = MULL(tmp1, c);\ |
| 641 |
|
| } |
| 642 |
|
| |
| 643 |
|
| #define BF1(a, b, c, d)\ |
| 644 |
|
| {\ |
| 645 |
|
| BF(a, b, COS4_0);\ |
| 646 |
|
| BF(c, d, -COS4_0);\ |
| 647 |
|
| tab[c] += tab[d];\ |
| 648 |
|
| } |
| 649 |
|
| |
| 650 |
|
| #define BF2(a, b, c, d)\ |
| 651 |
|
| {\ |
| 652 |
|
| BF(a, b, COS4_0);\ |
| 653 |
|
| BF(c, d, -COS4_0);\ |
| 654 |
|
| tab[c] += tab[d];\ |
| 655 |
|
| tab[a] += tab[c];\ |
| 656 |
|
| tab[c] += tab[b];\ |
| 657 |
|
| tab[b] += tab[d];\ |
| 658 |
|
| } |
| 659 |
|
| |
| 660 |
|
| #define ADD(a, b) tab[a] += tab[b] |
| 661 |
|
| |
| 662 |
|
| /* DCT32 without 1/sqrt(2) coef zero scaling. */ |
| 663 |
0 |
| static void dct32(int32_t *out, int32_t *tab) |
| 664 |
|
| { |
| 665 |
|
| int tmp0, tmp1; |
| 666 |
|
| |
| 667 |
|
| /* pass 1 */ |
| 668 |
0 |
| BF(0, 31, COS0_0); |
| 669 |
0 |
| BF(1, 30, COS0_1); |
| 670 |
0 |
| BF(2, 29, COS0_2); |
| 671 |
0 |
| BF(3, 28, COS0_3); |
| 672 |
0 |
| BF(4, 27, COS0_4); |
| 673 |
0 |
| BF(5, 26, COS0_5); |
| 674 |
0 |
| BF(6, 25, COS0_6); |
| 675 |
0 |
| BF(7, 24, COS0_7); |
| 676 |
0 |
| BF(8, 23, COS0_8); |
| 677 |
0 |
| BF(9, 22, COS0_9); |
| 678 |
0 |
| BF(10, 21, COS0_10); |
| 679 |
0 |
| BF(11, 20, COS0_11); |
| 680 |
0 |
| BF(12, 19, COS0_12); |
| 681 |
0 |
| BF(13, 18, COS0_13); |
| 682 |
0 |
| BF(14, 17, COS0_14); |
| 683 |
0 |
| BF(15, 16, COS0_15); |
| 684 |
|
| |
| 685 |
|
| /* pass 2 */ |
| 686 |
0 |
| BF(0, 15, COS1_0); |
| 687 |
0 |
| BF(1, 14, COS1_1); |
| 688 |
0 |
| BF(2, 13, COS1_2); |
| 689 |
0 |
| BF(3, 12, COS1_3); |
| 690 |
0 |
| BF(4, 11, COS1_4); |
| 691 |
0 |
| BF(5, 10, COS1_5); |
| 692 |
0 |
| BF(6, 9, COS1_6); |
| 693 |
0 |
| BF(7, 8, COS1_7); |
| 694 |
|
| |
| 695 |
0 |
| BF(16, 31, -COS1_0); |
| 696 |
0 |
| BF(17, 30, -COS1_1); |
| 697 |
0 |
| BF(18, 29, -COS1_2); |
| 698 |
0 |
| BF(19, 28, -COS1_3); |
| 699 |
0 |
| BF(20, 27, -COS1_4); |
| 700 |
0 |
| BF(21, 26, -COS1_5); |
| 701 |
0 |
| BF(22, 25, -COS1_6); |
| 702 |
0 |
| BF(23, 24, -COS1_7); |
| 703 |
|
| |
| 704 |
|
| /* pass 3 */ |
| 705 |
0 |
| BF(0, 7, COS2_0); |
| 706 |
0 |
| BF(1, 6, COS2_1); |
| 707 |
0 |
| BF(2, 5, COS2_2); |
| 708 |
0 |
| BF(3, 4, COS2_3); |
| 709 |
|
| |
| 710 |
0 |
| BF(8, 15, -COS2_0); |
| 711 |
0 |
| BF(9, 14, -COS2_1); |
| 712 |
0 |
| BF(10, 13, -COS2_2); |
| 713 |
0 |
| BF(11, 12, -COS2_3); |
| 714 |
|
| |
| 715 |
0 |
| BF(16, 23, COS2_0); |
| 716 |
0 |
| BF(17, 22, COS2_1); |
| 717 |
0 |
| BF(18, 21, COS2_2); |
| 718 |
0 |
| BF(19, 20, COS2_3); |
| 719 |
|
| |
| 720 |
0 |
| BF(24, 31, -COS2_0); |
| 721 |
0 |
| BF(25, 30, -COS2_1); |
| 722 |
0 |
| BF(26, 29, -COS2_2); |
| 723 |
0 |
| BF(27, 28, -COS2_3); |
| 724 |
|
| |
| 725 |
|
| /* pass 4 */ |
| 726 |
0 |
| BF(0, 3, COS3_0); |
| 727 |
0 |
| BF(1, 2, COS3_1); |
| 728 |
|
| |
| 729 |
0 |
| BF(4, 7, -COS3_0); |
| 730 |
0 |
| BF(5, 6, -COS3_1); |
| 731 |
|
| |
| 732 |
0 |
| BF(8, 11, COS3_0); |
| 733 |
0 |
| BF(9, 10, COS3_1); |
| 734 |
|
| |
| 735 |
0 |
| BF(12, 15, -COS3_0); |
| 736 |
0 |
| BF(13, 14, -COS3_1); |
| 737 |
|
| |
| 738 |
0 |
| BF(16, 19, COS3_0); |
| 739 |
0 |
| BF(17, 18, COS3_1); |
| 740 |
|
| |
| 741 |
0 |
| BF(20, 23, -COS3_0); |
| 742 |
0 |
| BF(21, 22, -COS3_1); |
| 743 |
|
| |
| 744 |
0 |
| BF(24, 27, COS3_0); |
| 745 |
0 |
| BF(25, 26, COS3_1); |
| 746 |
|
| |
| 747 |
0 |
| BF(28, 31, -COS3_0); |
| 748 |
0 |
| BF(29, 30, -COS3_1); |
| 749 |
|
| |
| 750 |
|
| /* pass 5 */ |
| 751 |
0 |
| BF1(0, 1, 2, 3); |
| 752 |
0 |
| BF2(4, 5, 6, 7); |
| 753 |
0 |
| BF1(8, 9, 10, 11); |
| 754 |
0 |
| BF2(12, 13, 14, 15); |
| 755 |
0 |
| BF1(16, 17, 18, 19); |
| 756 |
0 |
| BF2(20, 21, 22, 23); |
| 757 |
0 |
| BF1(24, 25, 26, 27); |
| 758 |
0 |
| BF2(28, 29, 30, 31); |
| 759 |
|
| |
| 760 |
|
| /* pass 6 */ |
| 761 |
|
| |
| 762 |
0 |
| ADD( 8, 12); |
| 763 |
0 |
| ADD(12, 10); |
| 764 |
0 |
| ADD(10, 14); |
| 765 |
0 |
| ADD(14, 9); |
| 766 |
0 |
| ADD( 9, 13); |
| 767 |
0 |
| ADD(13, 11); |
| 768 |
0 |
| ADD(11, 15); |
| 769 |
|
| |
| 770 |
0 |
| out[ 0] = tab[0]; |
| 771 |
0 |
| out[16] = tab[1]; |
| 772 |
0 |
| out[ 8] = tab[2]; |
| 773 |
0 |
| out[24] = tab[3]; |
| 774 |
0 |
| out[ 4] = tab[4]; |
| 775 |
0 |
| out[20] = tab[5]; |
| 776 |
0 |
| out[12] = tab[6]; |
| 777 |
0 |
| out[28] = tab[7]; |
| 778 |
0 |
| out[ 2] = tab[8]; |
| 779 |
0 |
| out[18] = tab[9]; |
| 780 |
0 |
| out[10] = tab[10]; |
| 781 |
0 |
| out[26] = tab[11]; |
| 782 |
0 |
| out[ 6] = tab[12]; |
| 783 |
0 |
| out[22] = tab[13]; |
| 784 |
0 |
| out[14] = tab[14]; |
| 785 |
0 |
| out[30] = tab[15]; |
| 786 |
|
| |
| 787 |
0 |
| ADD(24, 28); |
| 788 |
0 |
| ADD(28, 26); |
| 789 |
0 |
| ADD(26, 30); |
| 790 |
0 |
| ADD(30, 25); |
| 791 |
0 |
| ADD(25, 29); |
| 792 |
0 |
| ADD(29, 27); |
| 793 |
0 |
| ADD(27, 31); |
| 794 |
|
| |
| 795 |
0 |
| out[ 1] = tab[16] + tab[24]; |
| 796 |
0 |
| out[17] = tab[17] + tab[25]; |
| 797 |
0 |
| out[ 9] = tab[18] + tab[26]; |
| 798 |
0 |
| out[25] = tab[19] + tab[27]; |
| 799 |
0 |
| out[ 5] = tab[20] + tab[28]; |
| 800 |
0 |
| out[21] = tab[21] + tab[29]; |
| 801 |
0 |
| out[13] = tab[22] + tab[30]; |
| 802 |
0 |
| out[29] = tab[23] + tab[31]; |
| 803 |
0 |
| out[ 3] = tab[24] + tab[20]; |
| 804 |
0 |
| out[19] = tab[25] + tab[21]; |
| 805 |
0 |
| out[11] = tab[26] + tab[22]; |
| 806 |
0 |
| out[27] = tab[27] + tab[23]; |
| 807 |
0 |
| out[ 7] = tab[28] + tab[18]; |
| 808 |
0 |
| out[23] = tab[29] + tab[19]; |
| 809 |
0 |
| out[15] = tab[30] + tab[17]; |
| 810 |
0 |
| out[31] = tab[31]; |
| 811 |
0 |
| } |
| 812 |
|
| |
| 813 |
|
| #if FRAC_BITS <= 15 |
| 814 |
|
| |
| 815 |
0 |
| static inline int round_sample(int *sum) |
| 816 |
|
| { |
| 817 |
|
| int sum1; |
| 818 |
0 |
| sum1 = (*sum) >> OUT_SHIFT; |
| 819 |
0 |
| *sum &= (1<<OUT_SHIFT)-1; |
| 820 |
0 |
▶ | if (sum1 < OUT_MIN) |
Branch: 1 branch
| Branch | True | False | Total |
| if (sum1 < OUT_MIN) |
0 |
0 |
0 |
|
| 821 |
0 |
| sum1 = OUT_MIN; |
| 822 |
0 |
▶ | else if (sum1 > OUT_MAX) |
Branch: 1 branch
| Branch | True | False | Total |
| else if (sum1 > OUT_MAX) |
0 |
0 |
0 |
|
| 823 |
0 |
| sum1 = OUT_MAX; |
| 824 |
0 |
| return sum1; |
| 825 |
|
| } |
| 826 |
|
| |
| 827 |
|
| #if defined(ARCH_POWERPC_405) |
| 828 |
|
| |
| 829 |
|
| /* signed 16x16 -> 32 multiply add accumulate */ |
| 830 |
|
| #define MACS(rt, ra, rb) \ |
| 831 |
|
| asm ("maclhw %0, %2, %3" : "=r" (rt) : "0" (rt), "r" (ra), "r" (rb)); |
| 832 |
|
| |
| 833 |
|
| /* signed 16x16 -> 32 multiply */ |
| 834 |
|
| #define MULS(ra, rb) \ |
| 835 |
|
| ({ int __rt; asm ("mullhw %0, %1, %2" : "=r" (__rt) : "r" (ra), "r" (rb)); __rt; }) |
| 836 |
|
| |
| 837 |
|
| #else |
| 838 |
|
| |
| 839 |
|
| /* signed 16x16 -> 32 multiply add accumulate */ |
| 840 |
|
| #define MACS(rt, ra, rb) rt += (ra) * (rb) |
| 841 |
|
| |
| 842 |
|
| /* signed 16x16 -> 32 multiply */ |
| 843 |
|
| #define MULS(ra, rb) ((ra) * (rb)) |
| 844 |
|
| |
| 845 |
|
| #endif |
| 846 |
|
| |
| 847 |
|
| #else |
| 848 |
|
| |
| 849 |
|
| static inline int round_sample(int64_t *sum) |
| 850 |
|
| { |
| 851 |
|
| int sum1; |
| 852 |
|
| sum1 = (int)((*sum) >> OUT_SHIFT); |
| 853 |
|
| *sum &= (1<<OUT_SHIFT)-1; |
| 854 |
|
| if (sum1 < OUT_MIN) |
| 855 |
|
| sum1 = OUT_MIN; |
| 856 |
|
| else if (sum1 > OUT_MAX) |
| 857 |
|
| sum1 = OUT_MAX; |
| 858 |
|
| return sum1; |
| 859 |
|
| } |
| 860 |
|
| |
| 861 |
|
| #define MULS(ra, rb) MUL64(ra, rb) |
| 862 |
|
| |
| 863 |
|
| #endif |
| 864 |
|
| |
| 865 |
|
| #define SUM8(sum, op, w, p) \ |
| 866 |
|
| { \ |
| 867 |
|
| sum op MULS((w)[0 * 64], p[0 * 64]);\ |
| 868 |
|
| sum op MULS((w)[1 * 64], p[1 * 64]);\ |
| 869 |
|
| sum op MULS((w)[2 * 64], p[2 * 64]);\ |
| 870 |
|
| sum op MULS((w)[3 * 64], p[3 * 64]);\ |
| 871 |
|
| sum op MULS((w)[4 * 64], p[4 * 64]);\ |
| 872 |
|
| sum op MULS((w)[5 * 64], p[5 * 64]);\ |
| 873 |
|
| sum op MULS((w)[6 * 64], p[6 * 64]);\ |
| 874 |
|
| sum op MULS((w)[7 * 64], p[7 * 64]);\ |
| 875 |
|
| } |
| 876 |
|
| |
| 877 |
|
| #define SUM8P2(sum1, op1, sum2, op2, w1, w2, p) \ |
| 878 |
|
| { \ |
| 879 |
|
| int tmp;\ |
| 880 |
|
| tmp = p[0 * 64];\ |
| 881 |
|
| sum1 op1 MULS((w1)[0 * 64], tmp);\ |
| 882 |
|
| sum2 op2 MULS((w2)[0 * 64], tmp);\ |
| 883 |
|
| tmp = p[1 * 64];\ |
| 884 |
|
| sum1 op1 MULS((w1)[1 * 64], tmp);\ |
| 885 |
|
| sum2 op2 MULS((w2)[1 * 64], tmp);\ |
| 886 |
|
| tmp = p[2 * 64];\ |
| 887 |
|
| sum1 op1 MULS((w1)[2 * 64], tmp);\ |
| 888 |
|
| sum2 op2 MULS((w2)[2 * 64], tmp);\ |
| 889 |
|
| tmp = p[3 * 64];\ |
| 890 |
|
| sum1 op1 MULS((w1)[3 * 64], tmp);\ |
| 891 |
|
| sum2 op2 MULS((w2)[3 * 64], tmp);\ |
| 892 |
|
| tmp = p[4 * 64];\ |
| 893 |
|
| sum1 op1 MULS((w1)[4 * 64], tmp);\ |
| 894 |
|
| sum2 op2 MULS((w2)[4 * 64], tmp);\ |
| 895 |
|
| tmp = p[5 * 64];\ |
| 896 |
|
| sum1 op1 MULS((w1)[5 * 64], tmp);\ |
| 897 |
|
| sum2 op2 MULS((w2)[5 * 64], tmp);\ |
| 898 |
|
| tmp = p[6 * 64];\ |
| 899 |
|
| sum1 op1 MULS((w1)[6 * 64], tmp);\ |
| 900 |
|
| sum2 op2 MULS((w2)[6 * 64], tmp);\ |
| 901 |
|
| tmp = p[7 * 64];\ |
| 902 |
|
| sum1 op1 MULS((w1)[7 * 64], tmp);\ |
| 903 |
|
| sum2 op2 MULS((w2)[7 * 64], tmp);\ |
| 904 |
|
| } |
| 905 |
|
| |
| 906 |
0 |
| void ff_mpa_synth_init(MPA_INT *window) |
| 907 |
|
| { |
| 908 |
|
| int i; |
| 909 |
|
| |
| 910 |
|
| /* max = 18760, max sum over all 16 coefs : 44736 */ |
| 911 |
0 |
▶ | for(i=0;i<257;i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(i=0;i<257;i++) { |
0 |
0 |
0 |
|
| 912 |
|
| int v; |
| 913 |
0 |
| v = mpa_enwindow[i]; |
| 914 |
|
| #if WFRAC_BITS < 16 |
| 915 |
0 |
| v = (v + (1 << (16 - WFRAC_BITS - 1))) >> (16 - WFRAC_BITS); |
| 916 |
|
| #endif |
| 917 |
0 |
| window[i] = v; |
| 918 |
0 |
▶ | if ((i & 63) != 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if ((i & 63) != 0) |
0 |
0 |
0 |
|
| 919 |
0 |
| v = -v; |
| 920 |
0 |
▶ | if (i != 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if (i != 0) |
0 |
0 |
0 |
|
| 921 |
0 |
| window[512 - i] = v; |
| 922 |
|
| } |
| 923 |
0 |
| } |
| 924 |
|
| |
| 925 |
|
| /* 32 sub band synthesis filter. Input: 32 sub band samples, Output: |
| 926 |
|
| 32 samples. */ |
| 927 |
|
| /* XXX: optimize by avoiding ring buffer usage */ |
| 928 |
0 |
| void ff_mpa_synth_filter(MPA_INT *synth_buf_ptr, int *synth_buf_offset, |
| 929 |
|
| MPA_INT *window, int *dither_state, |
| 930 |
|
| OUT_INT *samples, int incr, |
| 931 |
|
| int32_t sb_samples[SBLIMIT]) |
| 932 |
|
| { |
| 933 |
|
| int32_t tmp[32]; |
| 934 |
|
| register MPA_INT *synth_buf; |
| 935 |
|
| register const MPA_INT *w, *w2, *p; |
| 936 |
|
| int j, offset, v; |
| 937 |
|
| OUT_INT *samples2; |
| 938 |
|
| #if FRAC_BITS <= 15 |
| 939 |
|
| int sum, sum2; |
| 940 |
|
| #else |
| 941 |
|
| int64_t sum, sum2; |
| 942 |
|
| #endif |
| 943 |
|
| |
| 944 |
0 |
| dct32(tmp, sb_samples); |
| 945 |
|
| |
| 946 |
0 |
| offset = *synth_buf_offset; |
| 947 |
0 |
| synth_buf = synth_buf_ptr + offset; |
| 948 |
|
| |
| 949 |
0 |
▶ | for(j=0;j<32;j++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(j=0;j<32;j++) { |
0 |
0 |
0 |
|
| 950 |
0 |
| v = tmp[j]; |
| 951 |
|
| #if FRAC_BITS <= 15 |
| 952 |
|
| /* NOTE: can cause a loss in precision if very high amplitude |
| 953 |
|
| sound */ |
| 954 |
0 |
▶ | if (v > 32767) |
Branch: 1 branch
| Branch | True | False | Total |
| if (v > 32767) |
0 |
0 |
0 |
|
| 955 |
0 |
| v = 32767; |
| 956 |
0 |
▶ | else if (v < -32768) |
Branch: 1 branch
| Branch | True | False | Total |
| else if (v < -32768) |
0 |
0 |
0 |
|
| 957 |
0 |
| v = -32768; |
| 958 |
|
| #endif |
| 959 |
0 |
| synth_buf[j] = v; |
| 960 |
|
| } |
| 961 |
|
| /* copy to avoid wrap */ |
| 962 |
0 |
| memcpy(synth_buf + 512, synth_buf, 32 * sizeof(MPA_INT)); |
| 963 |
|
| |
| 964 |
0 |
| samples2 = samples + 31 * incr; |
| 965 |
0 |
| w = window; |
| 966 |
0 |
| w2 = window + 31; |
| 967 |
|
| |
| 968 |
0 |
| sum = *dither_state; |
| 969 |
0 |
| p = synth_buf + 16; |
| 970 |
0 |
| SUM8(sum, +=, w, p); |
| 971 |
0 |
| p = synth_buf + 48; |
| 972 |
0 |
| SUM8(sum, -=, w + 32, p); |
| 973 |
0 |
| *samples = round_sample(&sum); |
| 974 |
0 |
| samples += incr; |
| 975 |
0 |
| w++; |
| 976 |
|
| |
| 977 |
|
| /* we calculate two samples at the same time to avoid one memory |
| 978 |
|
| access per two sample */ |
| 979 |
0 |
▶ | for(j=1;j<16;j++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(j=1;j<16;j++) { |
0 |
0 |
0 |
|
| 980 |
0 |
| sum2 = 0; |
| 981 |
0 |
| p = synth_buf + 16 + j; |
| 982 |
0 |
| SUM8P2(sum, +=, sum2, -=, w, w2, p); |
| 983 |
0 |
| p = synth_buf + 48 - j; |
| 984 |
0 |
| SUM8P2(sum, -=, sum2, -=, w + 32, w2 + 32, p); |
| 985 |
|
| |
| 986 |
0 |
| *samples = round_sample(&sum); |
| 987 |
0 |
| samples += incr; |
| 988 |
0 |
| sum += sum2; |
| 989 |
0 |
| *samples2 = round_sample(&sum); |
| 990 |
0 |
| samples2 -= incr; |
| 991 |
0 |
| w++; |
| 992 |
0 |
| w2--; |
| 993 |
|
| } |
| 994 |
|
| |
| 995 |
0 |
| p = synth_buf + 32; |
| 996 |
0 |
| SUM8(sum, -=, w + 32, p); |
| 997 |
0 |
| *samples = round_sample(&sum); |
| 998 |
0 |
| *dither_state= sum; |
| 999 |
|
| |
| 1000 |
0 |
| offset = (offset - 32) & 511; |
| 1001 |
0 |
| *synth_buf_offset = offset; |
| 1002 |
0 |
| } |
| 1003 |
|
| |
| 1004 |
|
| #define C3 FIXHR(0.86602540378443864676/2) |
| 1005 |
|
| |
| 1006 |
|
| /* 0.5 / cos(pi*(2*i+1)/36) */ |
| 1007 |
|
| static const int icos36[9] = { |
| 1008 |
|
| FIXR(0.50190991877167369479), |
| 1009 |
|
| FIXR(0.51763809020504152469), //0 |
| 1010 |
|
| FIXR(0.55168895948124587824), |
| 1011 |
|
| FIXR(0.61038729438072803416), |
| 1012 |
|
| FIXR(0.70710678118654752439), //1 |
| 1013 |
|
| FIXR(0.87172339781054900991), |
| 1014 |
|
| FIXR(1.18310079157624925896), |
| 1015 |
|
| FIXR(1.93185165257813657349), //2 |
| 1016 |
|
| FIXR(5.73685662283492756461), |
| 1017 |
|
| }; |
| 1018 |
|
| |
| 1019 |
|
| /* 12 points IMDCT. We compute it "by hand" by factorizing obvious |
| 1020 |
|
| cases. */ |
| 1021 |
0 |
| static void imdct12(int *out, int *in) |
| 1022 |
|
| { |
| 1023 |
|
| int in0, in1, in2, in3, in4, in5, t1, t2; |
| 1024 |
|
| |
| 1025 |
0 |
| in0= in[0*3]; |
| 1026 |
0 |
| in1= in[1*3] + in[0*3]; |
| 1027 |
0 |
| in2= in[2*3] + in[1*3]; |
| 1028 |
0 |
| in3= in[3*3] + in[2*3]; |
| 1029 |
0 |
| in4= in[4*3] + in[3*3]; |
| 1030 |
0 |
| in5= in[5*3] + in[4*3]; |
| 1031 |
0 |
| in5 += in3; |
| 1032 |
0 |
| in3 += in1; |
| 1033 |
|
| |
| 1034 |
0 |
| in2= MULH(2*in2, C3); |
| 1035 |
0 |
| in3= MULH(2*in3, C3); |
| 1036 |
|
| |
| 1037 |
0 |
| t1 = in0 - in4; |
| 1038 |
0 |
| t2 = MULL(in1 - in5, icos36[4]); |
| 1039 |
|
| |
| 1040 |
0 |
| out[ 7]= |
| 1041 |
0 |
| out[10]= t1 + t2; |
| 1042 |
0 |
| out[ 1]= |
| 1043 |
0 |
| out[ 4]= t1 - t2; |
| 1044 |
|
| |
| 1045 |
0 |
| in0 += in4>>1; |
| 1046 |
0 |
| in4 = in0 + in2; |
| 1047 |
0 |
| in1 += in5>>1; |
| 1048 |
0 |
| in5 = MULL(in1 + in3, icos36[1]); |
| 1049 |
0 |
| out[ 8]= |
| 1050 |
0 |
| out[ 9]= in4 + in5; |
| 1051 |
0 |
| out[ 2]= |
| 1052 |
0 |
| out[ 3]= in4 - in5; |
| 1053 |
|
| |
| 1054 |
0 |
| in0 -= in2; |
| 1055 |
0 |
| in1 = MULL(in1 - in3, icos36[7]); |
| 1056 |
0 |
| out[ 0]= |
| 1057 |
0 |
| out[ 5]= in0 - in1; |
| 1058 |
0 |
| out[ 6]= |
| 1059 |
0 |
| out[11]= in0 + in1; |
| 1060 |
0 |
| } |
| 1061 |
|
| |
| 1062 |
|
| /* cos(pi*i/18) */ |
| 1063 |
|
| #define C1 FIXHR(0.98480775301220805936/2) |
| 1064 |
|
| #define C2 FIXHR(0.93969262078590838405/2) |
| 1065 |
|
| #define C3 FIXHR(0.86602540378443864676/2) |
| 1066 |
|
| #define C4 FIXHR(0.76604444311897803520/2) |
| 1067 |
|
| #define C5 FIXHR(0.64278760968653932632/2) |
| 1068 |
|
| #define C6 FIXHR(0.5/2) |
| 1069 |
|
| #define C7 FIXHR(0.34202014332566873304/2) |
| 1070 |
|
| #define C8 FIXHR(0.17364817766693034885/2) |
| 1071 |
|
| |
| 1072 |
|
| |
| 1073 |
|
| /* using Lee like decomposition followed by hand coded 9 points DCT */ |
| 1074 |
0 |
| static void imdct36(int *out, int *buf, int *in, int *win) |
| 1075 |
|
| { |
| 1076 |
|
| int i, j, t0, t1, t2, t3, s0, s1, s2, s3; |
| 1077 |
|
| int tmp[18], *tmp1, *in1; |
| 1078 |
|
| |
| 1079 |
0 |
▶ | for(i=17;i>=1;i--) |
Branch: 1 branch
| Branch | True | False | Total |
| for(i=17;i>=1;i--) |
0 |
0 |
0 |
|
| 1080 |
0 |
| in[i] += in[i-1]; |
| 1081 |
0 |
▶ | for(i=17;i>=3;i-=2) |
Branch: 1 branch
| Branch | True | False | Total |
| for(i=17;i>=3;i-=2) |
0 |
0 |
0 |
|
| 1082 |
0 |
| in[i] += in[i-2]; |
| 1083 |
|
| |
| 1084 |
0 |
▶ | for(j=0;j<2;j++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(j=0;j<2;j++) { |
0 |
0 |
0 |
|
| 1085 |
0 |
| tmp1 = tmp + j; |
| 1086 |
0 |
| in1 = in + j; |
| 1087 |
0 |
| t2 = in1[2*4] + in1[2*8] - in1[2*2]; |
| 1088 |
|
| |
| 1089 |
0 |
| t3 = in1[2*0] + (in1[2*6]>>1); |
| 1090 |
0 |
| t1 = in1[2*0] - in1[2*6]; |
| 1091 |
0 |
| tmp1[ 6] = t1 - (t2>>1); |
| 1092 |
0 |
| tmp1[16] = t1 + t2; |
| 1093 |
|
| |
| 1094 |
0 |
| t0 = MULH(2*(in1[2*2] + in1[2*4]), C2); |
| 1095 |
0 |
| t1 = MULH( in1[2*4] - in1[2*8] , -2*C8); |
| 1096 |
0 |
| t2 = MULH(2*(in1[2*2] + in1[2*8]), -C4); |
| 1097 |
|
| |
| 1098 |
0 |
| tmp1[10] = t3 - t0 - t2; |
| 1099 |
0 |
| tmp1[ 2] = t3 + t0 + t1; |
| 1100 |
0 |
| tmp1[14] = t3 + t2 - t1; |
| 1101 |
|
| |
| 1102 |
0 |
| tmp1[ 4] = MULH(2*(in1[2*5] + in1[2*7] - in1[2*1]), -C3); |
| 1103 |
0 |
| t2 = MULH(2*(in1[2*1] + in1[2*5]), C1); |
| 1104 |
0 |
| t3 = MULH( in1[2*5] - in1[2*7] , -2*C7); |
| 1105 |
0 |
| t0 = MULH(2*in1[2*3], C3); |
| 1106 |
|
| |
| 1107 |
0 |
| t1 = MULH(2*(in1[2*1] + in1[2*7]), -C5); |
| 1108 |
|
| |
| 1109 |
0 |
| tmp1[ 0] = t2 + t3 + t0; |
| 1110 |
0 |
| tmp1[12] = t2 + t1 - t0; |
| 1111 |
0 |
| tmp1[ 8] = t3 - t1 - t0; |
| 1112 |
|
| } |
| 1113 |
|
| |
| 1114 |
0 |
| i = 0; |
| 1115 |
0 |
▶ | for(j=0;j<4;j++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(j=0;j<4;j++) { |
0 |
0 |
0 |
|
| 1116 |
0 |
| t0 = tmp[i]; |
| 1117 |
0 |
| t1 = tmp[i + 2]; |
| 1118 |
0 |
| s0 = t1 + t0; |
| 1119 |
0 |
| s2 = t1 - t0; |
| 1120 |
|
| |
| 1121 |
0 |
| t2 = tmp[i + 1]; |
| 1122 |
0 |
| t3 = tmp[i + 3]; |
| 1123 |
0 |
| s1 = MULL(t3 + t2, icos36[j]); |
| 1124 |
0 |
| s3 = MULL(t3 - t2, icos36[8 - j]); |
| 1125 |
|
| |
| 1126 |
0 |
| t0 = s0 + s1; |
| 1127 |
0 |
| t1 = s0 - s1; |
| 1128 |
0 |
| out[(9 + j)*SBLIMIT] = MULH(t1, win[9 + j]) + buf[9 + j]; |
| 1129 |
0 |
| out[(8 - j)*SBLIMIT] = MULH(t1, win[8 - j]) + buf[8 - j]; |
| 1130 |
0 |
| buf[9 + j] = MULH(t0, win[18 + 9 + j]); |
| 1131 |
0 |
| buf[8 - j] = MULH(t0, win[18 + 8 - j]); |
| 1132 |
|
| |
| 1133 |
0 |
| t0 = s2 + s3; |
| 1134 |
0 |
| t1 = s2 - s3; |
| 1135 |
0 |
| out[(9 + 8 - j)*SBLIMIT] = MULH(t1, win[9 + 8 - j]) + buf[9 + 8 - j]; |
| 1136 |
0 |
| out[( j)*SBLIMIT] = MULH(t1, win[ j]) + buf[ j]; |
| 1137 |
0 |
| buf[9 + 8 - j] = MULH(t0, win[18 + 9 + 8 - j]); |
| 1138 |
0 |
| buf[ + j] = MULH(t0, win[18 + j]); |
| 1139 |
0 |
| i += 4; |
| 1140 |
|
| } |
| 1141 |
|
| |
| 1142 |
0 |
| s0 = tmp[16]; |
| 1143 |
0 |
| s1 = MULL(tmp[17], icos36[4]); |
| 1144 |
0 |
| t0 = s0 + s1; |
| 1145 |
0 |
| t1 = s0 - s1; |
| 1146 |
0 |
| out[(9 + 4)*SBLIMIT] = MULH(t1, win[9 + 4]) + buf[9 + 4]; |
| 1147 |
0 |
| out[(8 - 4)*SBLIMIT] = MULH(t1, win[8 - 4]) + buf[8 - 4]; |
| 1148 |
0 |
| buf[9 + 4] = MULH(t0, win[18 + 9 + 4]); |
| 1149 |
0 |
| buf[8 - 4] = MULH(t0, win[18 + 8 - 4]); |
| 1150 |
0 |
| } |
| 1151 |
|
| |
| 1152 |
|
| /* header decoding. MUST check the header before because no |
| 1153 |
|
| consistency check is done there. Return 1 if free format found and |
| 1154 |
|
| that the frame size must be computed externally */ |
| 1155 |
0 |
| static int decode_header(MPADecodeContext *s, uint32_t header) |
| 1156 |
|
| { |
| 1157 |
|
| int sample_rate, frame_size, mpeg25, padding; |
| 1158 |
|
| int sample_rate_index, bitrate_index; |
| 1159 |
0 |
▶ | if (header & (1<<20)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (header & (1<<20)) { |
0 |
0 |
0 |
|
| 1160 |
0 |
| s->lsf = (header & (1<<19)) ? 0 : 1; |
| 1161 |
0 |
| mpeg25 = 0; |
| 1162 |
|
| } else { |
| 1163 |
0 |
| s->lsf = 1; |
| 1164 |
0 |
| mpeg25 = 1; |
| 1165 |
|
| } |
| 1166 |
|
| |
| 1167 |
0 |
| s->layer = 4 - ((header >> 17) & 3); |
| 1168 |
|
| /* extract frequency */ |
| 1169 |
0 |
| sample_rate_index = (header >> 10) & 3; |
| 1170 |
0 |
| sample_rate = mpa_freq_tab[sample_rate_index] >> (s->lsf + mpeg25); |
| 1171 |
0 |
| sample_rate_index += 3 * (s->lsf + mpeg25); |
| 1172 |
0 |
| s->sample_rate_index = sample_rate_index; |
| 1173 |
0 |
| s->error_protection = ((header >> 16) & 1) ^ 1; |
| 1174 |
0 |
| s->sample_rate = sample_rate; |
| 1175 |
|
| |
| 1176 |
0 |
| bitrate_index = (header >> 12) & 0xf; |
| 1177 |
0 |
| padding = (header >> 9) & 1; |
| 1178 |
|
| //extension = (header >> 8) & 1; |
| 1179 |
0 |
| s->mode = (header >> 6) & 3; |
| 1180 |
0 |
| s->mode_ext = (header >> 4) & 3; |
| 1181 |
|
| //copyright = (header >> 3) & 1; |
| 1182 |
|
| //original = (header >> 2) & 1; |
| 1183 |
|
| //emphasis = header & 3; |
| 1184 |
|
| |
| 1185 |
0 |
▶ | if (s->mode == MPA_MONO) |
Branch: 1 branch
| Branch | True | False | Total |
| if (s->mode == MPA_MONO) |
0 |
0 |
0 |
|
| 1186 |
0 |
| s->nb_channels = 1; |
| 1187 |
|
| else |
| 1188 |
0 |
| s->nb_channels = 2; |
| 1189 |
|
| |
| 1190 |
0 |
▶ | if (bitrate_index != 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (bitrate_index != 0) { |
0 |
0 |
0 |
|
| 1191 |
0 |
| frame_size = mpa_bitrate_tab[s->lsf][s->layer - 1][bitrate_index]; |
| 1192 |
0 |
| s->bit_rate = frame_size * 1000; |
| 1193 |
0 |
| switch(s->layer) { |
| 1194 |
0 |
| case 1: |
| 1195 |
0 |
| frame_size = (frame_size * 12000) / sample_rate; |
| 1196 |
0 |
| frame_size = (frame_size + padding) * 4; |
| 1197 |
0 |
| break; |
| 1198 |
0 |
| case 2: |
| 1199 |
0 |
| frame_size = (frame_size * 144000) / sample_rate; |
| 1200 |
0 |
| frame_size += padding; |
| 1201 |
0 |
| break; |
| 1202 |
0 |
| default: |
| 1203 |
|
| case 3: |
| 1204 |
0 |
| frame_size = (frame_size * 144000) / (sample_rate << s->lsf); |
| 1205 |
0 |
| frame_size += padding; |
| 1206 |
0 |
| break; |
| 1207 |
|
| } |
| 1208 |
0 |
| s->frame_size = frame_size; |
| 1209 |
|
| } else { |
| 1210 |
|
| /* if no frame size computed, signal it */ |
| 1211 |
0 |
▶ | if (!s->free_format_frame_size) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!s->free_format_frame_size) |
0 |
0 |
0 |
|
| 1212 |
0 |
| return 1; |
| 1213 |
|
| /* free format: compute bitrate and real frame size from the |
| 1214 |
|
| frame size we extracted by reading the bitstream */ |
| 1215 |
0 |
| s->frame_size = s->free_format_frame_size; |
| 1216 |
0 |
| switch(s->layer) { |
| 1217 |
0 |
| case 1: |
| 1218 |
0 |
| s->frame_size += padding * 4; |
| 1219 |
0 |
| s->bit_rate = (s->frame_size * sample_rate) / 48000; |
| 1220 |
0 |
| break; |
| 1221 |
0 |
| case 2: |
| 1222 |
0 |
| s->frame_size += padding; |
| 1223 |
0 |
| s->bit_rate = (s->frame_size * sample_rate) / 144000; |
| 1224 |
0 |
| break; |
| 1225 |
0 |
| default: |
| 1226 |
|
| case 3: |
| 1227 |
0 |
| s->frame_size += padding; |
| 1228 |
0 |
| s->bit_rate = (s->frame_size * (sample_rate << s->lsf)) / 144000; |
| 1229 |
0 |
| break; |
| 1230 |
|
| } |
| 1231 |
|
| } |
| 1232 |
|
| |
| 1233 |
|
| #if defined(ADEBUG) |
| 1234 |
|
| printf("layer%d, %d Hz, %d kbits/s, ", |
| 1235 |
|
| s->layer, s->sample_rate, s->bit_rate); |
| 1236 |
|
| if (s->nb_channels == 2) { |
| 1237 |
|
| if (s->layer == 3) { |
| 1238 |
|
| if (s->mode_ext & MODE_EXT_MS_STEREO) |
| 1239 |
|
| printf("ms-"); |
| 1240 |
|
| if (s->mode_ext & MODE_EXT_I_STEREO) |
| 1241 |
|
| printf("i-"); |
| 1242 |
|
| } |
| 1243 |
|
| printf("stereo"); |
| 1244 |
|
| } else { |
| 1245 |
|
| printf("mono"); |
| 1246 |
|
| } |
| 1247 |
|
| printf("\n"); |
| 1248 |
|
| #endif |
| 1249 |
0 |
| return 0; |
| 1250 |
|
| } |
| 1251 |
|
| |
| 1252 |
|
| /* useful helper to get mpeg audio stream infos. Return -1 if error in |
| 1253 |
|
| header, otherwise the coded frame size in bytes */ |
| 1254 |
0 |
| int mpa_decode_header(AVCodecContext *avctx, uint32_t head) |
| 1255 |
|
| { |
| 1256 |
0 |
| MPADecodeContext s1, *s = &s1; |
| 1257 |
0 |
| memset( s, 0, sizeof(MPADecodeContext) ); |
| 1258 |
|
| |
| 1259 |
0 |
▶ | if (ff_mpa_check_header(head) != 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if (ff_mpa_check_header(head) != 0) |
0 |
0 |
0 |
|
| 1260 |
0 |
| return -1; |
| 1261 |
|
| |
| 1262 |
0 |
▶ | if (decode_header(s, head) != 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (decode_header(s, head) != 0) { |
0 |
0 |
0 |
|
| 1263 |
0 |
| return -1; |
| 1264 |
|
| } |
| 1265 |
|
| |
| 1266 |
0 |
| switch(s->layer) { |
| 1267 |
0 |
| case 1: |
| 1268 |
0 |
| avctx->frame_size = 384; |
| 1269 |
0 |
| break; |
| 1270 |
0 |
| case 2: |
| 1271 |
0 |
| avctx->frame_size = 1152; |
| 1272 |
0 |
| break; |
| 1273 |
0 |
| default: |
| 1274 |
|
| case 3: |
| 1275 |
0 |
▶ | if (s->lsf) |
Branch: 1 branch
| Branch | True | False | Total |
| if (s->lsf) |
0 |
0 |
0 |
|
| 1276 |
0 |
| avctx->frame_size = 576; |
| 1277 |
|
| else |
| 1278 |
0 |
| avctx->frame_size = 1152; |
| 1279 |
0 |
| break; |
| 1280 |
|
| } |
| 1281 |
|
| |
| 1282 |
0 |
| avctx->sample_rate = s->sample_rate; |
| 1283 |
0 |
| avctx->channels = s->nb_channels; |
| 1284 |
0 |
| avctx->bit_rate = s->bit_rate; |
| 1285 |
0 |
| avctx->sub_id = s->layer; |
| 1286 |
0 |
| return s->frame_size; |
| 1287 |
|
| } |
| 1288 |
|
| |
| 1289 |
|
| /* return the number of decoded frames */ |
| 1290 |
0 |
| static int mp_decode_layer1(MPADecodeContext *s) |
| 1291 |
|
| { |
| 1292 |
|
| int bound, i, v, n, ch, j, mant; |
| 1293 |
|
| uint8_t allocation[MPA_MAX_CHANNELS][SBLIMIT]; |
| 1294 |
|
| uint8_t scale_factors[MPA_MAX_CHANNELS][SBLIMIT]; |
| 1295 |
|
| |
| 1296 |
0 |
▶ | if (s->mode == MPA_JSTEREO) |
Branch: 1 branch
| Branch | True | False | Total |
| if (s->mode == MPA_JSTEREO) |
0 |
0 |
0 |
|
| 1297 |
0 |
| bound = (s->mode_ext + 1) * 4; |
| 1298 |
|
| else |
| 1299 |
0 |
| bound = SBLIMIT; |
| 1300 |
|
| |
| 1301 |
|
| /* allocation bits */ |
| 1302 |
0 |
▶ | for(i=0;i<bound;i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(i=0;i<bound;i++) { |
0 |
0 |
0 |
|
| 1303 |
0 |
▶ | for(ch=0;ch<s->nb_channels;ch++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(ch=0;ch<s->nb_channels;ch++) { |
0 |
0 |
0 |
|
| 1304 |
0 |
| allocation[ch][i] = get_bits(&s->gb, 4); |
| 1305 |
|
| } |
| 1306 |
|
| } |
| 1307 |
0 |
▶ | for(i=bound;i<SBLIMIT;i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(i=bound;i<SBLIMIT;i++) { |
0 |
0 |
0 |
|
| 1308 |
0 |
| allocation[0][i] = get_bits(&s->gb, 4); |
| 1309 |
|
| } |
| 1310 |
|
| |
| 1311 |
|
| /* scale factors */ |
| 1312 |
0 |
▶ | for(i=0;i<bound;i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(i=0;i<bound;i++) { |
0 |
0 |
0 |
|
| 1313 |
0 |
▶ | for(ch=0;ch<s->nb_channels;ch++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(ch=0;ch<s->nb_channels;ch++) { |
0 |
0 |
0 |
|
| 1314 |
0 |
▶ | if (allocation[ch][i]) |
Branch: 1 branch
| Branch | True | False | Total |
| if (allocation[ch][i]) |
0 |
0 |
0 |
|
| 1315 |
0 |
| scale_factors[ch][i] = get_bits(&s->gb, 6); |
| 1316 |
|
| } |
| 1317 |
|
| } |
| 1318 |
0 |
▶ | for(i=bound;i<SBLIMIT;i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(i=bound;i<SBLIMIT;i++) { |
0 |
0 |
0 |
|
| 1319 |
0 |
▶ | if (allocation[0][i]) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (allocation[0][i]) { |
0 |
0 |
0 |
|
| 1320 |
0 |
| scale_factors[0][i] = get_bits(&s->gb, 6); |
| 1321 |
0 |
| scale_factors[1][i] = get_bits(&s->gb, 6); |
| 1322 |
|
| } |
| 1323 |
|
| } |
| 1324 |
|
| |
| 1325 |
|
| /* compute samples */ |
| 1326 |
0 |
▶ | for(j=0;j<12;j++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(j=0;j<12;j++) { |
0 |
0 |
0 |
|
| 1327 |
0 |
▶ | for(i=0;i<bound;i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(i=0;i<bound;i++) { |
0 |
0 |
0 |
|
| 1328 |
0 |
▶ | for(ch=0;ch<s->nb_channels;ch++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(ch=0;ch<s->nb_channels;ch++) { |
0 |
0 |
0 |
|
| 1329 |
0 |
| n = allocation[ch][i]; |
| 1330 |
0 |
▶ | if (n) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (n) { |
0 |
0 |
0 |
|
| 1331 |
0 |
| mant = get_bits(&s->gb, n + 1); |
| 1332 |
0 |
| v = l1_unscale(n, mant, scale_factors[ch][i]); |
| 1333 |
|
| } else { |
| 1334 |
0 |
| v = 0; |
| 1335 |
|
| } |
| 1336 |
0 |
| s->sb_samples[ch][j][i] = v; |
| 1337 |
|
| } |
| 1338 |
|
| } |
| 1339 |
0 |
▶ | for(i=bound;i<SBLIMIT;i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(i=bound;i<SBLIMIT;i++) { |
0 |
0 |
0 |
|
| 1340 |
0 |
| n = allocation[0][i]; |
| 1341 |
0 |
▶ | if (n) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (n) { |
0 |
0 |
0 |
|
| 1342 |
0 |
| mant = get_bits(&s->gb, n + 1); |
| 1343 |
0 |
| v = l1_unscale(n, mant, scale_factors[0][i]); |
| 1344 |
0 |
| s->sb_samples[0][j][i] = v; |
| 1345 |
0 |
| v = l1_unscale(n, mant, scale_factors[1][i]); |
| 1346 |
0 |
| s->sb_samples[1][j][i] = v; |
| 1347 |
|
| } else { |
| 1348 |
0 |
| s->sb_samples[0][j][i] = 0; |
| 1349 |
0 |
| s->sb_samples[1][j][i] = 0; |
| 1350 |
|
| } |
| 1351 |
|
| } |
| 1352 |
|
| } |
| 1353 |
0 |
| return 12; |
| 1354 |
|
| } |
| 1355 |
|
| |
| 1356 |
|
| /* bitrate is in kb/s */ |
| 1357 |
0 |
| int l2_select_table(int bitrate, int nb_channels, int freq, int lsf) |
| 1358 |
|
| { |
| 1359 |
|
| int ch_bitrate, table; |
| 1360 |
|
| |
| 1361 |
0 |
| ch_bitrate = bitrate / nb_channels; |
| 1362 |
0 |
▶ | if (!lsf) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!lsf) { |
0 |
0 |
0 |
|
| 1363 |
0 |
▶ | if ((freq == 48000 && ch_bitrate >= 56) || |
Branch: 3 branches
| Branch | True | False | Total |
| if ((freq == 48000 && ch_bitrate >= 56) || |
0 |
0 |
0 |
| if ((freq == 48000 && ch_bitrate >= 56) || |
0 |
0 |
0 |
| if ((freq == 48000 && ch_bitrate >= 56) || |
0 |
0 |
0 |
|
| 1364 |
0 |
▶ | (ch_bitrate >= 56 && ch_bitrate <= 80)) |
Branch: 1 branch
| Branch | True | False | Total |
| (ch_bitrate >= 56 && ch_bitrate <= 80)) |
0 |
0 |
0 |
|
| 1365 |
0 |
| table = 0; |
| 1366 |
0 |
▶ | else if (freq != 48000 && ch_bitrate >= 96) |
Branch: 2 branches
| Branch | True | False | Total |
| else if (freq != 48000 && ch_bitrate >= 96) |
0 |
0 |
0 |
| else if (freq != 48000 && ch_bitrate >= 96) |
0 |
0 |
0 |
|
| 1367 |
0 |
| table = 1; |
| 1368 |
0 |
▶ | else if (freq != 32000 && ch_bitrate <= 48) |
Branch: 2 branches
| Branch | True | False | Total |
| else if (freq != 32000 && ch_bitrate <= 48) |
0 |
0 |
0 |
| else if (freq != 32000 && ch_bitrate <= 48) |
0 |
0 |
0 |
|
| 1369 |
0 |
| table = 2; |
| 1370 |
|
| else |
| 1371 |
0 |
| table = 3; |
| 1372 |
|
| } else { |
| 1373 |
0 |
| table = 4; |
| 1374 |
|
| } |
| 1375 |
0 |
| return table; |
| 1376 |
|
| } |
| 1377 |
|
| |
| 1378 |
0 |
| static int mp_decode_layer2(MPADecodeContext *s) |
| 1379 |
|
| { |
| 1380 |
|
| int sblimit; /* number of used subbands */ |
| 1381 |
|
| const unsigned char *alloc_table; |
| 1382 |
|
| int table, bit_alloc_bits, i, j, ch, bound, v; |
| 1383 |
|
| unsigned char bit_alloc[MPA_MAX_CHANNELS][SBLIMIT]; |
| 1384 |
|
| unsigned char scale_code[MPA_MAX_CHANNELS][SBLIMIT]; |
| 1385 |
|
| unsigned char scale_factors[MPA_MAX_CHANNELS][SBLIMIT][3], *sf; |
| 1386 |
|
| int scale, qindex, bits, steps, k, l, m, b; |
| 1387 |
|
| |
| 1388 |
|
| /* select decoding table */ |
| 1389 |
0 |
| table = l2_select_table(s->bit_rate / 1000, s->nb_channels, |
| 1390 |
|
| s->sample_rate, s->lsf); |
| 1391 |
0 |
| sblimit = sblimit_table[table]; |
| 1392 |
0 |
| alloc_table = alloc_tables[table]; |
| 1393 |
|
| |
| 1394 |
0 |
▶ | if (s->mode == MPA_JSTEREO) |
Branch: 1 branch
| Branch | True | False | Total |
| if (s->mode == MPA_JSTEREO) |
0 |
0 |
0 |
|
| 1395 |
0 |
| bound = (s->mode_ext + 1) * 4; |
| 1396 |
|
| else |
| 1397 |
0 |
| bound = sblimit; |
| 1398 |
|
| |
| 1399 |
0 |
| dbg_printf("bound=%d sblimit=%d\n", bound, sblimit); |
| 1400 |
|
| |
| 1401 |
|
| /* sanity check */ |
| 1402 |
0 |
▶ | if( bound > sblimit ) bound = sblimit; |
Branch: 1 branch
| Branch | True | False | Total |
| if( bound > sblimit ) bound = sblimit; |
0 |
0 |
0 |
|
| 1403 |
|
| |
| 1404 |
|
| /* parse bit allocation */ |
| 1405 |
0 |
| j = 0; |
| 1406 |
0 |
▶ | for(i=0;i<bound;i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(i=0;i<bound;i++) { |
0 |
0 |
0 |
|
| 1407 |
0 |
| bit_alloc_bits = alloc_table[j]; |
| 1408 |
0 |
▶ | for(ch=0;ch<s->nb_channels;ch++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(ch=0;ch<s->nb_channels;ch++) { |
0 |
0 |
0 |
|
| 1409 |
0 |
| bit_alloc[ch][i] = get_bits(&s->gb, bit_alloc_bits); |
| 1410 |
|
| } |
| 1411 |
0 |
| j += 1 << bit_alloc_bits; |
| 1412 |
|
| } |
| 1413 |
0 |
▶ | for(i=bound;i<sblimit;i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(i=bound;i<sblimit;i++) { |
0 |
0 |
0 |
|
| 1414 |
0 |
| bit_alloc_bits = alloc_table[j]; |
| 1415 |
0 |
| v = get_bits(&s->gb, bit_alloc_bits); |
| 1416 |
0 |
| bit_alloc[0][i] = v; |
| 1417 |
0 |
| bit_alloc[1][i] = v; |
| 1418 |
0 |
| j += 1 << bit_alloc_bits; |
| 1419 |
|
| } |
| 1420 |
|
| |
| 1421 |
|
| #ifdef ADEBUG |
| 1422 |
|
| { |
| 1423 |
|
| for(ch=0;ch<s->nb_channels;ch++) { |
| 1424 |
|
| for(i=0;i<sblimit;i++) |
| 1425 |
|
| printf(" %d", bit_alloc[ch][i]); |
| 1426 |
|
| printf("\n"); |
| 1427 |
|
| } |
| 1428 |
|
| } |
| 1429 |
|
| #endif |
| 1430 |
|
| |
| 1431 |
|
| /* scale codes */ |
| 1432 |
0 |
▶ | for(i=0;i<sblimit;i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(i=0;i<sblimit;i++) { |
0 |
0 |
0 |
|
| 1433 |
0 |
▶ | for(ch=0;ch<s->nb_channels;ch++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(ch=0;ch<s->nb_channels;ch++) { |
0 |
0 |
0 |
|
| 1434 |
0 |
▶ | if (bit_alloc[ch][i]) |
Branch: 1 branch
| Branch | True | False | Total |
| if (bit_alloc[ch][i]) |
0 |
0 |
0 |
|
| 1435 |
0 |
| scale_code[ch][i] = get_bits(&s->gb, 2); |
| 1436 |
|
| } |
| 1437 |
|
| } |
| 1438 |
|
| |
| 1439 |
|
| /* scale factors */ |
| 1440 |
0 |
▶ | for(i=0;i<sblimit;i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(i=0;i<sblimit;i++) { |
0 |
0 |
0 |
|
| 1441 |
0 |
▶ | for(ch=0;ch<s->nb_channels;ch++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(ch=0;ch<s->nb_channels;ch++) { |
0 |
0 |
0 |
|
| 1442 |
0 |
▶ | if (bit_alloc[ch][i]) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (bit_alloc[ch][i]) { |
0 |
0 |
0 |
|
| 1443 |
0 |
| sf = scale_factors[ch][i]; |
| 1444 |
0 |
| switch(scale_code[ch][i]) { |
| 1445 |
0 |
| default: |
| 1446 |
|
| case 0: |
| 1447 |
0 |
| sf[0] = get_bits(&s->gb, 6); |
| 1448 |
0 |
| sf[1] = get_bits(&s->gb, 6); |
| 1449 |
0 |
| sf[2] = get_bits(&s->gb, 6); |
| 1450 |
0 |
| break; |
| 1451 |
0 |
| case 2: |
| 1452 |
0 |
| sf[0] = get_bits(&s->gb, 6); |
| 1453 |
0 |
| sf[1] = sf[0]; |
| 1454 |
0 |
| sf[2] = sf[0]; |
| 1455 |
0 |
| break; |
| 1456 |
0 |
| case 1: |
| 1457 |
0 |
| sf[0] = get_bits(&s->gb, 6); |
| 1458 |
0 |
| sf[2] = get_bits(&s->gb, 6); |
| 1459 |
0 |
| sf[1] = sf[0]; |
| 1460 |
0 |
| break; |
| 1461 |
0 |
| case 3: |
| 1462 |
0 |
| sf[0] = get_bits(&s->gb, 6); |
| 1463 |
0 |
| sf[2] = get_bits(&s->gb, 6); |
| 1464 |
0 |
| sf[1] = sf[2]; |
| 1465 |
0 |
| break; |
| 1466 |
|
| } |
| 1467 |
|
| } |
| 1468 |
|
| } |
| 1469 |
|
| } |
| 1470 |
|
| |
| 1471 |
|
| #ifdef ADEBUG |
| 1472 |
|
| for(ch=0;ch<s->nb_channels;ch++) { |
| 1473 |
|
| for(i=0;i<sblimit;i++) { |
| 1474 |
|
| if (bit_alloc[ch][i]) { |
| 1475 |
|
| sf = scale_factors[ch][i]; |
| 1476 |
|
| printf(" %d %d %d", sf[0], sf[1], sf[2]); |
| 1477 |
|
| } else { |
| 1478 |
|
| printf(" -"); |
| 1479 |
|
| } |
| 1480 |
|
| } |
| 1481 |
|
| printf("\n"); |
| 1482 |
|
| } |
| 1483 |
|
| #endif |
| 1484 |
|
| |
| 1485 |
|
| /* samples */ |
| 1486 |
0 |
▶ | for(k=0;k<3;k++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(k=0;k<3;k++) { |
0 |
0 |
0 |
|
| 1487 |
0 |
▶ | for(l=0;l<12;l+=3) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(l=0;l<12;l+=3) { |
0 |
0 |
0 |
|
| 1488 |
0 |
| j = 0; |
| 1489 |
0 |
▶ | for(i=0;i<bound;i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(i=0;i<bound;i++) { |
0 |
0 |
0 |
|
| 1490 |
0 |
| bit_alloc_bits = alloc_table[j]; |
| 1491 |
0 |
▶ | for(ch=0;ch<s->nb_channels;ch++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(ch=0;ch<s->nb_channels;ch++) { |
0 |
0 |
0 |
|
| 1492 |
0 |
| b = bit_alloc[ch][i]; |
| 1493 |
0 |
▶ | if (b) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (b) { |
0 |
0 |
0 |
|
| 1494 |
0 |
| scale = scale_factors[ch][i][k]; |
| 1495 |
0 |
| qindex = alloc_table[j+b]; |
| 1496 |
0 |
| bits = quant_bits[qindex]; |
| 1497 |
0 |
▶ | if (bits < 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (bits < 0) { |
0 |
0 |
0 |
|
| 1498 |
|
| /* 3 values at the same time */ |
| 1499 |
0 |
| v = get_bits(&s->gb, -bits); |
| 1500 |
0 |
| steps = quant_steps[qindex]; |
| 1501 |
0 |
| s->sb_samples[ch][k * 12 + l + 0][i] = |
| 1502 |
0 |
| l2_unscale_group(steps, v % steps, scale); |
| 1503 |
0 |
| v = v / steps; |
| 1504 |
0 |
| s->sb_samples[ch][k * 12 + l + 1][i] = |
| 1505 |
0 |
| l2_unscale_group(steps, v % steps, scale); |
| 1506 |
0 |
| v = v / steps; |
| 1507 |
0 |
| s->sb_samples[ch][k * 12 + l + 2][i] = |
| 1508 |
0 |
| l2_unscale_group(steps, v, scale); |
| 1509 |
|
| } else { |
| 1510 |
0 |
▶ | for(m=0;m<3;m++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(m=0;m<3;m++) { |
0 |
0 |
0 |
|
| 1511 |
0 |
| v = get_bits(&s->gb, bits); |
| 1512 |
0 |
| v = l1_unscale(bits - 1, v, scale); |
| 1513 |
0 |
| s->sb_samples[ch][k * 12 + l + m][i] = v; |
| 1514 |
|
| } |
| 1515 |
|
| } |
| 1516 |
|
| } else { |
| 1517 |
0 |
| s->sb_samples[ch][k * 12 + l + 0][i] = 0; |
| 1518 |
0 |
| s->sb_samples[ch][k * 12 + l + 1][i] = 0; |
| 1519 |
0 |
| s->sb_samples[ch][k * 12 + l + 2][i] = 0; |
| 1520 |
|
| } |
| 1521 |
|
| } |
| 1522 |
|
| /* next subband in alloc table */ |
| 1523 |
0 |
| j += 1 << bit_alloc_bits; |
| 1524 |
|
| } |
| 1525 |
|
| /* XXX: find a way to avoid this duplication of code */ |
| 1526 |
0 |
▶ | for(i=bound;i<sblimit;i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(i=bound;i<sblimit;i++) { |
0 |
0 |
0 |
|
| 1527 |
0 |
| bit_alloc_bits = alloc_table[j]; |
| 1528 |
0 |
| b = bit_alloc[0][i]; |
| 1529 |
0 |
▶ | if (b) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (b) { |
0 |
0 |
0 |
|
| 1530 |
|
| int mant, scale0, scale1; |
| 1531 |
0 |
| scale0 = scale_factors[0][i][k]; |
| 1532 |
0 |
| scale1 = scale_factors[1][i][k]; |
| 1533 |
0 |
| qindex = alloc_table[j+b]; |
| 1534 |
0 |
| bits = quant_bits[qindex]; |
| 1535 |
0 |
▶ | if (bits < 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (bits < 0) { |
0 |
0 |
0 |
|
| 1536 |
|
| /* 3 values at the same time */ |
| 1537 |
0 |
| v = get_bits(&s->gb, -bits); |
| 1538 |
0 |
| steps = quant_steps[qindex]; |
| 1539 |
0 |
| mant = v % steps; |
| 1540 |
0 |
| v = v / steps; |
| 1541 |
0 |
| s->sb_samples[0][k * 12 + l + 0][i] = |
| 1542 |
0 |
| l2_unscale_group(steps, mant, scale0); |
| 1543 |
0 |
| s->sb_samples[1][k * 12 + l + 0][i] = |
| 1544 |
0 |
| l2_unscale_group(steps, mant, scale1); |
| 1545 |
0 |
| mant = v % steps; |
| 1546 |
0 |
| v = v / steps; |
| 1547 |
0 |
| s->sb_samples[0][k * 12 + l + 1][i] = |
| 1548 |
0 |
| l2_unscale_group(steps, mant, scale0); |
| 1549 |
0 |
| s->sb_samples[1][k * 12 + l + 1][i] = |
| 1550 |
0 |
| l2_unscale_group(steps, mant, scale1); |
| 1551 |
0 |
| s->sb_samples[0][k * 12 + l + 2][i] = |
| 1552 |
0 |
| l2_unscale_group(steps, v, scale0); |
| 1553 |
0 |
| s->sb_samples[1][k * 12 + l + 2][i] = |
| 1554 |
0 |
| l2_unscale_group(steps, v, scale1); |
| 1555 |
|
| } else { |
| 1556 |
0 |
▶ | for(m=0;m<3;m++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(m=0;m<3;m++) { |
0 |
0 |
0 |
|
| 1557 |
0 |
| mant = get_bits(&s->gb, bits); |
| 1558 |
0 |
| s->sb_samples[0][k * 12 + l + m][i] = |
| 1559 |
0 |
| l1_unscale(bits - 1, mant, scale0); |
| 1560 |
0 |
| s->sb_samples[1][k * 12 + l + m][i] = |
| 1561 |
0 |
| l1_unscale(bits - 1, mant, scale1); |
| 1562 |
|
| } |
| 1563 |
|
| } |
| 1564 |
|
| } else { |
| 1565 |
0 |
| s->sb_samples[0][k * 12 + l + 0][i] = 0; |
| 1566 |
0 |
| s->sb_samples[0][k * 12 + l + 1][i] = 0; |
| 1567 |
0 |
| s->sb_samples[0][k * 12 + l + 2][i] = 0; |
| 1568 |
0 |
| s->sb_samples[1][k * 12 + l + 0][i] = 0; |
| 1569 |
0 |
| s->sb_samples[1][k * 12 + l + 1][i] = 0; |
| 1570 |
0 |
| s->sb_samples[1][k * 12 + l + 2][i] = 0; |
| 1571 |
|
| } |
| 1572 |
|
| /* next subband in alloc table */ |
| 1573 |
0 |
| j += 1 << bit_alloc_bits; |
| 1574 |
|
| } |
| 1575 |
|
| /* fill remaining samples to zero */ |
| 1576 |
0 |
▶ | for(i=sblimit;i<SBLIMIT;i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(i=sblimit;i<SBLIMIT;i++) { |
0 |
0 |
0 |
|
| 1577 |
0 |
▶ | for(ch=0;ch<s->nb_channels;ch++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(ch=0;ch<s->nb_channels;ch++) { |
0 |
0 |
0 |
|
| 1578 |
0 |
| s->sb_samples[ch][k * 12 + l + 0][i] = 0; |
| 1579 |
0 |
| s->sb_samples[ch][k * 12 + l + 1][i] = 0; |
| 1580 |
0 |
| s->sb_samples[ch][k * 12 + l + 2][i] = 0; |
| 1581 |
|
| } |
| 1582 |
|
| } |
| 1583 |
|
| } |
| 1584 |
|
| } |
| 1585 |
0 |
| return 3 * 12; |
| 1586 |
|
| } |
| 1587 |
|
| |
| 1588 |
0 |
| static int mp_decode_frame(MPADecodeContext *s, |
| 1589 |
|
| OUT_INT *samples) |
| 1590 |
|
| { |
| 1591 |
|
| int i, nb_frames, ch; |
| 1592 |
|
| OUT_INT *samples_ptr; |
| 1593 |
|
| |
| 1594 |
0 |
| init_get_bits(&s->gb, s->inbuf + HEADER_SIZE, |
| 1595 |
0 |
| (s->inbuf_ptr - s->inbuf - HEADER_SIZE)*8); |
| 1596 |
|
| |
| 1597 |
|
| /* skip error protection field */ |
| 1598 |
0 |
▶ | if (s->error_protection) |
Branch: 1 branch
| Branch | True | False | Total |
| if (s->error_protection) |
0 |
0 |
0 |
|
| 1599 |
0 |
| get_bits(&s->gb, 16); |
| 1600 |
|
| |
| 1601 |
0 |
| dbg_printf("frame %d:\n", s->frame_count); |
| 1602 |
0 |
| switch(s->layer) { |
| 1603 |
0 |
| case 1: |
| 1604 |
0 |
| nb_frames = mp_decode_layer1(s); |
| 1605 |
0 |
| break; |
| 1606 |
0 |
| case 3: |
| 1607 |
|
| // default: |
| 1608 |
0 |
| fprintf(stderr, "\nMP3 Audio or other unknown input, cannot decode\n"); |
| 1609 |
|
| |
| 1610 |
|
| // nb_frames = mp_decode_layer3(s); |
| 1611 |
|
| // break; |
| 1612 |
|
| |
| 1613 |
0 |
| default: |
| 1614 |
|
| case 2: |
| 1615 |
0 |
| nb_frames = mp_decode_layer2(s); |
| 1616 |
0 |
| break; |
| 1617 |
|
| } |
| 1618 |
|
| #if defined(ADEBUG) |
| 1619 |
|
| for(i=0;i<nb_frames;i++) { |
| 1620 |
|
| for(ch=0;ch<s->nb_channels;ch++) { |
| 1621 |
|
| int j; |
| 1622 |
|
| printf("%d-%d:", i, ch); |
| 1623 |
|
| for(j=0;j<SBLIMIT;j++) |
| 1624 |
|
| printf(" %0.6f", (double)s->sb_samples[ch][i][j] / FRAC_ONE); |
| 1625 |
|
| printf("\n"); |
| 1626 |
|
| } |
| 1627 |
|
| } |
| 1628 |
|
| #endif |
| 1629 |
|
| /* apply the synthesis filter */ |
| 1630 |
0 |
▶ | for(ch=0;ch<s->nb_channels;ch++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(ch=0;ch<s->nb_channels;ch++) { |
0 |
0 |
0 |
|
| 1631 |
0 |
| samples_ptr = samples + ch; |
| 1632 |
0 |
▶ | for(i=0;i<nb_frames;i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(i=0;i<nb_frames;i++) { |
0 |
0 |
0 |
|
| 1633 |
0 |
| ff_mpa_synth_filter(s->synth_buf[ch], &(s->synth_buf_offset[ch]), |
| 1634 |
0 |
| window, &s->dither_state, |
| 1635 |
|
| samples_ptr, s->nb_channels, |
| 1636 |
0 |
| s->sb_samples[ch][i]); |
| 1637 |
0 |
| samples_ptr += 32 * s->nb_channels; |
| 1638 |
|
| } |
| 1639 |
|
| } |
| 1640 |
|
| //#ifdef ADEBUG |
| 1641 |
0 |
| s->frame_count++; |
| 1642 |
|
| // s->frame_count += nb_frames; |
| 1643 |
|
| //#endif |
| 1644 |
0 |
| return nb_frames * 32 * sizeof(OUT_INT) * s->nb_channels; |
| 1645 |
|
| } |
| 1646 |
|
| |
| 1647 |
0 |
| int decode_frame(void *data, int *data_size, |
| 1648 |
|
| uint8_t * buf, int buf_size) |
| 1649 |
|
| { |
| 1650 |
0 |
| MPADecodeContext *s = avctx->priv_data; |
| 1651 |
|
| uint32_t header; |
| 1652 |
|
| uint8_t *buf_ptr; |
| 1653 |
|
| int len, out_size; |
| 1654 |
0 |
| OUT_INT *out_samples = data; |
| 1655 |
|
| |
| 1656 |
0 |
| buf_ptr = buf; |
| 1657 |
0 |
▶ | while (buf_size > 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (buf_size > 0) { |
0 |
0 |
0 |
|
| 1658 |
0 |
| len = s->inbuf_ptr - s->inbuf; |
| 1659 |
0 |
▶ | if (s->frame_size == 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (s->frame_size == 0) { |
0 |
0 |
0 |
|
| 1660 |
|
| /* special case for next header for first frame in free |
| 1661 |
|
| format case (XXX: find a simpler method) */ |
| 1662 |
0 |
▶ | if (s->free_format_next_header != 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (s->free_format_next_header != 0) { |
0 |
0 |
0 |
|
| 1663 |
0 |
| s->inbuf[0] = s->free_format_next_header >> 24; |
| 1664 |
0 |
| s->inbuf[1] = s->free_format_next_header >> 16; |
| 1665 |
0 |
| s->inbuf[2] = s->free_format_next_header >> 8; |
| 1666 |
0 |
| s->inbuf[3] = s->free_format_next_header; |
| 1667 |
0 |
| s->inbuf_ptr = s->inbuf + 4; |
| 1668 |
0 |
| s->free_format_next_header = 0; |
| 1669 |
0 |
| goto got_header; |
| 1670 |
|
| } |
| 1671 |
|
| /* no header seen : find one. We need at least HEADER_SIZE |
| 1672 |
|
| bytes to parse it */ |
| 1673 |
0 |
| len = HEADER_SIZE - len; |
| 1674 |
0 |
▶ | if (len > buf_size) |
Branch: 1 branch
| Branch | True | False | Total |
| if (len > buf_size) |
0 |
0 |
0 |
|
| 1675 |
0 |
| len = buf_size; |
| 1676 |
0 |
▶ | if (len > 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (len > 0) { |
0 |
0 |
0 |
|
| 1677 |
0 |
| memcpy(s->inbuf_ptr, buf_ptr, len); |
| 1678 |
0 |
| buf_ptr += len; |
| 1679 |
0 |
| buf_size -= len; |
| 1680 |
0 |
| s->inbuf_ptr += len; |
| 1681 |
|
| } |
| 1682 |
0 |
▶ | if ((s->inbuf_ptr - s->inbuf) >= HEADER_SIZE) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ((s->inbuf_ptr - s->inbuf) >= HEADER_SIZE) { |
0 |
0 |
0 |
|
| 1683 |
0 |
| got_header: |
| 1684 |
0 |
| header = (s->inbuf[0] << 24) | (s->inbuf[1] << 16) | |
| 1685 |
0 |
| (s->inbuf[2] << 8) | s->inbuf[3]; |
| 1686 |
|
| |
| 1687 |
0 |
▶ | if (ff_mpa_check_header(header) < 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (ff_mpa_check_header(header) < 0) { |
0 |
0 |
0 |
|
| 1688 |
|
| /* no sync found : move by one byte (inefficient, but simple!) */ |
| 1689 |
0 |
| memmove(s->inbuf, s->inbuf + 1, s->inbuf_ptr - s->inbuf - 1); |
| 1690 |
0 |
| s->inbuf_ptr--; |
| 1691 |
0 |
| dbg_printf("skip %x\n", header); |
| 1692 |
|
| /* reset free format frame size to give a chance |
| 1693 |
|
| to get a new bitrate */ |
| 1694 |
0 |
| s->free_format_frame_size = 0; |
| 1695 |
|
| } else { |
| 1696 |
0 |
▶ | if (decode_header(s, header) == 1) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (decode_header(s, header) == 1) { |
0 |
0 |
0 |
|
| 1697 |
|
| /* free format: prepare to compute frame size */ |
| 1698 |
0 |
| s->frame_size = -1; |
| 1699 |
|
| } |
| 1700 |
|
| /* update codec info */ |
| 1701 |
0 |
| avctx->sample_rate = s->sample_rate; |
| 1702 |
0 |
| avctx->channels = s->nb_channels; |
| 1703 |
0 |
| avctx->bit_rate = s->bit_rate; |
| 1704 |
0 |
| avctx->sub_id = s->layer; |
| 1705 |
0 |
| switch(s->layer) { |
| 1706 |
0 |
| case 1: |
| 1707 |
0 |
| avctx->frame_size = 384; |
| 1708 |
0 |
| break; |
| 1709 |
0 |
| case 2: |
| 1710 |
0 |
| avctx->frame_size = 1152; |
| 1711 |
0 |
| break; |
| 1712 |
0 |
| case 3: |
| 1713 |
0 |
▶ | if (s->lsf) |
Branch: 1 branch
| Branch | True | False | Total |
| if (s->lsf) |
0 |
0 |
0 |
|
| 1714 |
0 |
| avctx->frame_size = 576; |
| 1715 |
|
| else |
| 1716 |
0 |
| avctx->frame_size = 1152; |
| 1717 |
0 |
| break; |
| 1718 |
|
| } |
| 1719 |
|
| } |
| 1720 |
|
| } |
| 1721 |
0 |
▶ | } else if (s->frame_size == -1) { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (s->frame_size == -1) { |
0 |
0 |
0 |
|
| 1722 |
|
| /* free format : find next sync to compute frame size */ |
| 1723 |
0 |
| len = MPA_MAX_CODED_FRAME_SIZE - len; |
| 1724 |
0 |
▶ | if (len > buf_size) |
Branch: 1 branch
| Branch | True | False | Total |
| if (len > buf_size) |
0 |
0 |
0 |
|
| 1725 |
0 |
| len = buf_size; |
| 1726 |
0 |
▶ | if (len == 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (len == 0) { |
0 |
0 |
0 |
|
| 1727 |
|
| /* frame too long: resync */ |
| 1728 |
0 |
| s->frame_size = 0; |
| 1729 |
0 |
| memmove(s->inbuf, s->inbuf + 1, s->inbuf_ptr - s->inbuf - 1); |
| 1730 |
0 |
| s->inbuf_ptr--; |
| 1731 |
|
| } else { |
| 1732 |
|
| uint8_t *p, *pend; |
| 1733 |
|
| uint32_t header1; |
| 1734 |
|
| int padding; |
| 1735 |
|
| |
| 1736 |
0 |
| memcpy(s->inbuf_ptr, buf_ptr, len); |
| 1737 |
|
| /* check for header */ |
| 1738 |
0 |
| p = s->inbuf_ptr - 3; |
| 1739 |
0 |
| pend = s->inbuf_ptr + len - 4; |
| 1740 |
0 |
▶ | while (p <= pend) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (p <= pend) { |
0 |
0 |
0 |
|
| 1741 |
0 |
| header = (p[0] << 24) | (p[1] << 16) | |
| 1742 |
0 |
| (p[2] << 8) | p[3]; |
| 1743 |
0 |
| header1 = (s->inbuf[0] << 24) | (s->inbuf[1] << 16) | |
| 1744 |
0 |
| (s->inbuf[2] << 8) | s->inbuf[3]; |
| 1745 |
|
| /* check with high probability that we have a |
| 1746 |
|
| valid header */ |
| 1747 |
0 |
▶ | if ((header & SAME_HEADER_MASK) == |
Branch: 1 branch
| Branch | True | False | Total |
| if ((header & SAME_HEADER_MASK) == |
0 |
0 |
0 |
|
| 1748 |
|
| (header1 & SAME_HEADER_MASK)) { |
| 1749 |
|
| /* header found: update pointers */ |
| 1750 |
0 |
| len = (p + 4) - s->inbuf_ptr; |
| 1751 |
0 |
| buf_ptr += len; |
| 1752 |
0 |
| buf_size -= len; |
| 1753 |
0 |
| s->inbuf_ptr = p; |
| 1754 |
|
| /* compute frame size */ |
| 1755 |
0 |
| s->free_format_next_header = header; |
| 1756 |
0 |
| s->free_format_frame_size = s->inbuf_ptr - s->inbuf; |
| 1757 |
0 |
| padding = (header1 >> 9) & 1; |
| 1758 |
0 |
▶ | if (s->layer == 1) |
Branch: 1 branch
| Branch | True | False | Total |
| if (s->layer == 1) |
0 |
0 |
0 |
|
| 1759 |
0 |
| s->free_format_frame_size -= padding * 4; |
| 1760 |
|
| else |
| 1761 |
0 |
| s->free_format_frame_size -= padding; |
| 1762 |
0 |
| dbg_printf("free frame size=%d padding=%d\n", |
| 1763 |
|
| s->free_format_frame_size, padding); |
| 1764 |
0 |
| decode_header(s, header1); |
| 1765 |
0 |
| goto next_data; |
| 1766 |
|
| } |
| 1767 |
0 |
| p++; |
| 1768 |
|
| } |
| 1769 |
|
| /* not found: simply increase pointers */ |
| 1770 |
0 |
| buf_ptr += len; |
| 1771 |
0 |
| s->inbuf_ptr += len; |
| 1772 |
0 |
| buf_size -= len; |
| 1773 |
|
| } |
| 1774 |
0 |
▶ | } else if (len < s->frame_size) { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (len < s->frame_size) { |
0 |
0 |
0 |
|
| 1775 |
0 |
▶ | if (s->frame_size > MPA_MAX_CODED_FRAME_SIZE) |
Branch: 1 branch
| Branch | True | False | Total |
| if (s->frame_size > MPA_MAX_CODED_FRAME_SIZE) |
0 |
0 |
0 |
|
| 1776 |
0 |
| s->frame_size = MPA_MAX_CODED_FRAME_SIZE; |
| 1777 |
0 |
| len = s->frame_size - len; |
| 1778 |
0 |
▶ | if (len > buf_size) |
Branch: 1 branch
| Branch | True | False | Total |
| if (len > buf_size) |
0 |
0 |
0 |
|
| 1779 |
0 |
| len = buf_size; |
| 1780 |
0 |
| memcpy(s->inbuf_ptr, buf_ptr, len); |
| 1781 |
0 |
| buf_ptr += len; |
| 1782 |
0 |
| s->inbuf_ptr += len; |
| 1783 |
0 |
| buf_size -= len; |
| 1784 |
|
| } |
| 1785 |
0 |
| next_data: |
| 1786 |
0 |
▶ | if (s->frame_size > 0 && |
Branch: 1 branch
| Branch | True | False | Total |
| if (s->frame_size > 0 && |
0 |
0 |
0 |
|
| 1787 |
0 |
▶ | (s->inbuf_ptr - s->inbuf) >= s->frame_size) { |
Branch: 1 branch
| Branch | True | False | Total |
| (s->inbuf_ptr - s->inbuf) >= s->frame_size) { |
0 |
0 |
0 |
|
| 1788 |
0 |
▶ | if (avctx->parse_only) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (avctx->parse_only) { |
0 |
0 |
0 |
|
| 1789 |
|
| /* simply return the frame data */ |
| 1790 |
0 |
| *(uint8_t **)data = s->inbuf; |
| 1791 |
0 |
| out_size = s->inbuf_ptr - s->inbuf; |
| 1792 |
|
| } else { |
| 1793 |
0 |
| out_size = mp_decode_frame(s, out_samples); |
| 1794 |
|
| } |
| 1795 |
0 |
| s->inbuf_ptr = s->inbuf; |
| 1796 |
0 |
| s->frame_size = 0; |
| 1797 |
0 |
| *data_size = out_size; |
| 1798 |
0 |
| break; |
| 1799 |
|
| } |
| 1800 |
|
| } |
| 1801 |
0 |
| return buf_ptr - buf; |
| 1802 |
|
| } |
| 1803 |
|
| |
| 1804 |
0 |
| int get_samplerate() |
| 1805 |
|
| { |
| 1806 |
0 |
| return CodecContext.sample_rate; |
| 1807 |
|
| } |
| 1808 |
|
| |
| 1809 |
0 |
| int get_channels() |
| 1810 |
|
| { |
| 1811 |
0 |
| return CodecContext.channels; |
| 1812 |
|
| } |
| 1813 |
|
| |
| 1814 |
0 |
| int get_framesize() |
| 1815 |
|
| { |
| 1816 |
0 |
| return CodecContext.frame_size; |
| 1817 |
|
| } |
| 1818 |
0 |
| int get_framenum() |
| 1819 |
|
| { |
| 1820 |
0 |
| MPADecodeContext *s = CodecContext.priv_data; |
| 1821 |
|
| |
| 1822 |
0 |
| return s->frame_count; |
| 1823 |
|
| } |
| 1824 |
|
| |
| 1825 |
|
| /* |
| 1826 |
|
| AVCodec mp2_decoder = |
| 1827 |
|
| { |
| 1828 |
|
| "mp2", |
| 1829 |
|
| CODEC_TYPE_AUDIO, |
| 1830 |
|
| CODEC_ID_MP2, |
| 1831 |
|
| sizeof(MPADecodeContext), |
| 1832 |
|
| decode_init, |
| 1833 |
|
| NULL, |
| 1834 |
|
| NULL, |
| 1835 |
|
| decode_frame, |
| 1836 |
|
| CODEC_CAP_PARSE_ONLY, |
| 1837 |
|
| }; |
| 1838 |
|
| */ |