Ticket #10079: aacfix-0.24.diff
File aacfix-0.24.diff, 67.9 KB (added by , 12 years ago) |
---|
-
mythtv/configure
diff --git a/mythtv/configure b/mythtv/configure index e17edb0..659e8d0 100755
a b rdft_select="fft" 1473 1473 # decoders / encoders / hardware accelerators 1474 1474 aac_decoder_select="mdct rdft" 1475 1475 aac_encoder_select="mdct" 1476 aac_latm_decoder_select="aac_decoder "1476 aac_latm_decoder_select="aac_decoder aac_latm_parser" 1477 1477 ac3_decoder_select="mdct ac3_parser" 1478 1478 alac_encoder_select="lpc" 1479 1479 amrnb_decoder_select="lsp" -
mythtv/external/FFmpeg/libavcodec/Makefile
diff --git a/mythtv/external/FFmpeg/libavcodec/Makefile b/mythtv/external/FFmpeg/libavcodec/Makefile index 0d6ab83..15a9493 100644
a b OBJS-$(CONFIG_AAC_ENCODER) += aacenc.o aaccoder.o \ 61 61 aacpsy.o aactab.o \ 62 62 psymodel.o iirfilter.o \ 63 63 mpeg4audio.o 64 OBJS-$(CONFIG_AAC_LATM_DECODER) += aaclatmdec.o65 64 OBJS-$(CONFIG_AASC_DECODER) += aasc.o msrledec.o 66 65 OBJS-$(CONFIG_AC3_DECODER) += ac3dec.o ac3dec_data.o ac3.o 67 66 OBJS-$(CONFIG_AC3_ENCODER) += ac3enc.o ac3tab.o ac3.o -
mythtv/external/FFmpeg/libavcodec/aac.h
diff --git a/mythtv/external/FFmpeg/libavcodec/aac.h b/mythtv/external/FFmpeg/libavcodec/aac.h index 94f578f..da6603a 100644
a b 42 42 #define MAX_ELEM_ID 16 43 43 44 44 #define TNS_MAX_ORDER 20 45 #define MAX_LTP_LONG_SFB 40 45 46 46 47 enum RawDataBlockType { 47 48 TYPE_SCE, … … typedef struct { 128 129 #define SCALE_MAX_POS 255 ///< scalefactor index maximum value 129 130 #define SCALE_MAX_DIFF 60 ///< maximum scalefactor difference allowed by standard 130 131 #define SCALE_DIFF_ZERO 60 ///< codebook index corresponding to zero scalefactor indices difference 132 #define POW_SF2_ZERO 200 ///< ff_aac_pow2sf_tab index corresponding to pow(2, 0); 133 134 /** 135 * Long Term Prediction 136 */ 137 typedef struct { 138 int8_t present; 139 int16_t lag; 140 float coef; 141 int8_t used[MAX_LTP_LONG_SFB]; 142 } LongTermPrediction; 131 143 132 144 /** 133 145 * Individual Channel Stream … … typedef struct { 138 150 uint8_t use_kb_window[2]; ///< If set, use Kaiser-Bessel window, otherwise use a sinus window. 139 151 int num_window_groups; 140 152 uint8_t group_len[8]; 153 LongTermPrediction ltp; 141 154 const uint16_t *swb_offset; ///< table of offsets to the lowest spectral coefficient of a scalefactor band, sfb, for a particular window 142 155 const uint8_t *swb_sizes; ///< table of scalefactor band sizes for a particular window 143 156 int num_swb; ///< number of scalefactor window bands … … typedef struct { 205 218 IndividualChannelStream ics; 206 219 TemporalNoiseShaping tns; 207 220 Pulse pulse; 208 enum BandType band_type[128]; ///< band types 209 int band_type_run_end[120]; ///< band type run end points 210 float sf[120]; ///< scalefactors 211 int sf_idx[128]; ///< scalefactor indices (used by encoder) 212 uint8_t zeroes[128]; ///< band is not coded (used by encoder) 213 DECLARE_ALIGNED(16, float, coeffs)[1024]; ///< coefficients for IMDCT 214 DECLARE_ALIGNED(16, float, saved)[1024]; ///< overlap 215 DECLARE_ALIGNED(16, float, ret)[2048]; ///< PCM output 221 enum BandType band_type[128]; ///< band types 222 int band_type_run_end[120]; ///< band type run end points 223 float sf[120]; ///< scalefactors 224 int sf_idx[128]; ///< scalefactor indices (used by encoder) 225 uint8_t zeroes[128]; ///< band is not coded (used by encoder) 226 DECLARE_ALIGNED(16, float, coeffs)[1024]; ///< coefficients for IMDCT 227 DECLARE_ALIGNED(16, float, saved)[1024]; ///< overlap 228 DECLARE_ALIGNED(16, float, ret)[2048]; ///< PCM output 229 DECLARE_ALIGNED(16, int16_t, ltp_state)[3072]; ///< time signal for LTP 216 230 PredictorState predictor_state[MAX_PREDICTORS]; 217 231 } SingleChannelElement; 218 232 … … typedef struct { 251 265 */ 252 266 ChannelElement *che[4][MAX_ELEM_ID]; 253 267 ChannelElement *tag_che_map[4][MAX_ELEM_ID]; 254 uint8_t tags_seen_this_frame[4][MAX_ELEM_ID];255 268 int tags_mapped; 256 269 /** @} */ 257 270 … … typedef struct { 259 272 * @defgroup temporary aligned temporary buffers (We do not want to have these on the stack.) 260 273 * @{ 261 274 */ 262 DECLARE_ALIGNED(16, float, buf_mdct)[ 1024];275 DECLARE_ALIGNED(16, float, buf_mdct)[2048]; 263 276 /** @} */ 264 277 265 278 /** … … typedef struct { 268 281 */ 269 282 FFTContext mdct; 270 283 FFTContext mdct_small; 284 FFTContext mdct_ltp; 271 285 DSPContext dsp; 286 // FmtConvertContext fmt_conv; 272 287 int random_state; 273 288 /** @} */ 274 289 … … typedef struct { 277 292 * @{ 278 293 */ 279 294 float *output_data[MAX_CHANNELS]; ///< Points to each element's 'ret' buffer (PCM output). 280 float add_bias; ///< offset for dsp.float_to_int16281 295 float sf_scale; ///< Pre-scale for correct IMDCT and dsp.float_to_int16. 282 296 int sf_offset; ///< offset into pow2sf_tab as appropriate for dsp.float_to_int16 283 297 /** @} */ -
mythtv/external/FFmpeg/libavcodec/aacdec.c
diff --git a/mythtv/external/FFmpeg/libavcodec/aacdec.c b/mythtv/external/FFmpeg/libavcodec/aacdec.c index 62aab34..c983141 100644
a b 3 3 * Copyright (c) 2005-2006 Oded Shimon ( ods15 ods15 dyndns org ) 4 4 * Copyright (c) 2006-2007 Maxim Gavrilov ( maxim.gavrilov gmail com ) 5 5 * 6 * AAC LATM decoder 7 * Copyright (c) 2008-2010 Paul Kendall <paul@kcbbs.gen.nz> 8 * Copyright (c) 2010 Janne Grunau <janne-ffmpeg@jannau.net> 9 * 6 10 * This file is part of FFmpeg. 7 11 * 8 12 * FFmpeg is free software; you can redistribute it and/or … … 38 42 * Y filterbank - standard 39 43 * N (code in SoC repo) filterbank - Scalable Sample Rate 40 44 * Y Temporal Noise Shaping 41 * N (code in SoC repo)Long Term Prediction45 * Y Long Term Prediction 42 46 * Y intensity stereo 43 47 * Y channel coupling 44 48 * Y frequency domain prediction … … static const char overread_err[] = "Input buffer exhausted before END element fo 113 117 114 118 static ChannelElement *get_che(AACContext *ac, int type, int elem_id) 115 119 { 116 /* Some buggy encoders appear to set all elem_ids to zero and rely on 117 channels always occurring in the same order. This is expressly forbidden 118 by the spec but we will try to work around it. 119 */ 120 int err_printed = 0; 121 while (ac->tags_seen_this_frame[type][elem_id] && elem_id < MAX_ELEM_ID) { 122 if (ac->output_configured < OC_LOCKED && !err_printed) { 123 av_log(ac->avctx, AV_LOG_WARNING, "Duplicate channel tag found, attempting to remap.\n"); 124 err_printed = 1; 125 } 126 elem_id++; 127 } 128 if (elem_id == MAX_ELEM_ID) 129 return NULL; 130 ac->tags_seen_this_frame[type][elem_id] = 1; 131 132 if (ac->tag_che_map[type][elem_id]) { 120 // For PCE based channel configurations map the channels solely based on tags. 121 if (!ac->m4ac.chan_config) { 133 122 return ac->tag_che_map[type][elem_id]; 134 123 } 135 if (ac->tags_mapped >= tags_per_config[ac->m4ac.chan_config]) { 136 return NULL; 137 } 124 // For indexed channel configurations map the channels solely based on position. 138 125 switch (ac->m4ac.chan_config) { 139 126 case 7: 140 127 if (ac->tags_mapped == 3 && type == TYPE_CPE) { … … static ChannelElement *get_che(AACContext *ac, int type, int elem_id) 190 177 * @return Returns error status. 0 - OK, !0 - error 191 178 */ 192 179 static av_cold int che_configure(AACContext *ac, 193 enum ChannelPosition che_pos[4][MAX_ELEM_ID], 194 int type, int id, 195 int *channels) 180 enum ChannelPosition che_pos[4][MAX_ELEM_ID], 181 int type, int id, int *channels) 196 182 { 197 183 if (che_pos[type][id]) { 198 184 if (!ac->che[type][id] && !(ac->che[type][id] = av_mallocz(sizeof(ChannelElement)))) … … static av_cold int che_configure(AACContext *ac, 222 208 * @return Returns error status. 0 - OK, !0 - error 223 209 */ 224 210 static av_cold int output_configure(AACContext *ac, 225 enum ChannelPosition che_pos[4][MAX_ELEM_ID],226 enum ChannelPosition new_che_pos[4][MAX_ELEM_ID],227 int channel_config, enum OCStatus oc_type)211 enum ChannelPosition che_pos[4][MAX_ELEM_ID], 212 enum ChannelPosition new_che_pos[4][MAX_ELEM_ID], 213 int channel_config, enum OCStatus oc_type) 228 214 { 229 215 AVCodecContext *avctx = ac->avctx; 230 216 int i, type, channels = 0, ret; … … static av_cold int output_configure(AACContext *ac, 241 227 return ret; 242 228 } 243 229 244 memset(ac->tag_che_map, 0, 4 * MAX_ELEM_ID * sizeof(ac->che[0][0])); 245 ac->tags_mapped = 0; 230 memset(ac->tag_che_map, 0, 4 * MAX_ELEM_ID * sizeof(ac->che[0][0])); 246 231 247 232 avctx->channel_layout = aac_channel_layout[channel_config - 1]; 248 233 } else { … … static av_cold int output_configure(AACContext *ac, 263 248 } 264 249 265 250 memcpy(ac->tag_che_map, ac->che, 4 * MAX_ELEM_ID * sizeof(ac->che[0][0])); 266 ac->tags_mapped = 4 * MAX_ELEM_ID;267 268 avctx->channel_layout = 0;269 251 } 270 252 271 253 avctx->channels = channels; … … static void decode_channel_map(enum ChannelPosition *cpe_map, 300 282 * 301 283 * @return Returns error status. 0 - OK, !0 - error 302 284 */ 303 static int decode_pce(AACContext *ac, enum ChannelPosition new_che_pos[4][MAX_ELEM_ID], 285 static int decode_pce(AVCodecContext *avctx, MPEG4AudioConfig *m4ac, 286 enum ChannelPosition new_che_pos[4][MAX_ELEM_ID], 304 287 GetBitContext *gb) 305 288 { 306 289 int num_front, num_side, num_back, num_lfe, num_assoc_data, num_cc, sampling_index; … … static int decode_pce(AACContext *ac, enum ChannelPosition new_che_pos[4][MAX_EL 309 292 skip_bits(gb, 2); // object_type 310 293 311 294 sampling_index = get_bits(gb, 4); 312 if ( ac->m4ac.sampling_index != sampling_index)313 av_log(a c->avctx, AV_LOG_WARNING, "Sample rate index in program config element does not match the sample rate index configured by the container.\n");295 if (m4ac->sampling_index != sampling_index) 296 av_log(avctx, AV_LOG_WARNING, "Sample rate index in program config element does not match the sample rate index configured by the container.\n"); 314 297 315 298 num_front = get_bits(gb, 4); 316 299 num_side = get_bits(gb, 4); … … static int decode_pce(AACContext *ac, enum ChannelPosition new_che_pos[4][MAX_EL 327 310 if (get_bits1(gb)) 328 311 skip_bits(gb, 3); // mixdown_coeff_index and pseudo_surround 329 312 313 if (get_bits_left(gb) < 4 * (num_front + num_side + num_back + num_lfe + num_assoc_data + num_cc)) { 314 av_log(avctx, AV_LOG_ERROR, overread_err); 315 return -1; 316 } 330 317 decode_channel_map(new_che_pos[TYPE_CPE], new_che_pos[TYPE_SCE], AAC_CHANNEL_FRONT, gb, num_front); 331 318 decode_channel_map(new_che_pos[TYPE_CPE], new_che_pos[TYPE_SCE], AAC_CHANNEL_SIDE, gb, num_side ); 332 319 decode_channel_map(new_che_pos[TYPE_CPE], new_che_pos[TYPE_SCE], AAC_CHANNEL_BACK, gb, num_back ); … … static int decode_pce(AACContext *ac, enum ChannelPosition new_che_pos[4][MAX_EL 341 328 /* comment field, first byte is length */ 342 329 comment_len = get_bits(gb, 8) * 8; 343 330 if (get_bits_left(gb) < comment_len) { 344 av_log(a c->avctx, AV_LOG_ERROR, overread_err);331 av_log(avctx, AV_LOG_ERROR, overread_err); 345 332 return -1; 346 333 } 347 334 skip_bits_long(gb, comment_len); … … static int decode_pce(AACContext *ac, enum ChannelPosition new_che_pos[4][MAX_EL 356 343 * 357 344 * @return Returns error status. 0 - OK, !0 - error 358 345 */ 359 static av_cold int set_default_channel_config(A ACContext *ac,360 enum ChannelPosition new_che_pos[4][MAX_ELEM_ID],361 int channel_config)346 static av_cold int set_default_channel_config(AVCodecContext *avctx, 347 enum ChannelPosition new_che_pos[4][MAX_ELEM_ID], 348 int channel_config) 362 349 { 363 350 if (channel_config < 1 || channel_config > 7) { 364 av_log(a c->avctx, AV_LOG_ERROR, "invalid default channel configuration (%d)\n",351 av_log(avctx, AV_LOG_ERROR, "invalid default channel configuration (%d)\n", 365 352 channel_config); 366 353 return -1; 367 354 } … … static av_cold int set_default_channel_config(AACContext *ac, 397 384 /** 398 385 * Decode GA "General Audio" specific configuration; reference: table 4.1. 399 386 * 387 * @param ac pointer to AACContext, may be null 388 * @param avctx pointer to AVCCodecContext, used for logging 389 * 400 390 * @return Returns error status. 0 - OK, !0 - error 401 391 */ 402 static int decode_ga_specific_config(AACContext *ac, GetBitContext *gb, 392 static int decode_ga_specific_config(AACContext *ac, AVCodecContext *avctx, 393 GetBitContext *gb, 394 MPEG4AudioConfig *m4ac, 403 395 int channel_config) 404 396 { 405 397 enum ChannelPosition new_che_pos[4][MAX_ELEM_ID]; 406 398 int extension_flag, ret; 407 399 408 400 if (get_bits1(gb)) { // frameLengthFlag 409 av_log_missing_feature(a c->avctx, "960/120 MDCT window is", 1);401 av_log_missing_feature(avctx, "960/120 MDCT window is", 1); 410 402 return -1; 411 403 } 412 404 … … static int decode_ga_specific_config(AACContext *ac, GetBitContext *gb, 414 406 skip_bits(gb, 14); // coreCoderDelay 415 407 extension_flag = get_bits1(gb); 416 408 417 if ( ac->m4ac.object_type == AOT_AAC_SCALABLE ||418 ac->m4ac.object_type == AOT_ER_AAC_SCALABLE)409 if (m4ac->object_type == AOT_AAC_SCALABLE || 410 m4ac->object_type == AOT_ER_AAC_SCALABLE) 419 411 skip_bits(gb, 3); // layerNr 420 412 421 413 memset(new_che_pos, 0, 4 * MAX_ELEM_ID * sizeof(new_che_pos[0][0])); 422 414 if (channel_config == 0) { 423 415 skip_bits(gb, 4); // element_instance_tag 424 if ((ret = decode_pce(a c, new_che_pos, gb)))416 if ((ret = decode_pce(avctx, m4ac, new_che_pos, gb))) 425 417 return ret; 426 418 } else { 427 if ((ret = set_default_channel_config(a c, new_che_pos, channel_config)))419 if ((ret = set_default_channel_config(avctx, new_che_pos, channel_config))) 428 420 return ret; 429 421 } 430 if ( (ret = output_configure(ac, ac->che_pos, new_che_pos, channel_config, OC_GLOBAL_HDR)))422 if (ac && (ret = output_configure(ac, ac->che_pos, new_che_pos, channel_config, OC_GLOBAL_HDR))) 431 423 return ret; 432 424 433 425 if (extension_flag) { 434 switch ( ac->m4ac.object_type) {426 switch (m4ac->object_type) { 435 427 case AOT_ER_BSAC: 436 428 skip_bits(gb, 5); // numOfSubFrame 437 429 skip_bits(gb, 11); // layer_length … … static int decode_ga_specific_config(AACContext *ac, GetBitContext *gb, 454 446 /** 455 447 * Decode audio specific configuration; reference: table 1.13. 456 448 * 449 * @param ac pointer to AACContext, may be null 450 * @param avctx pointer to AVCCodecContext, used for logging 451 * @param m4ac pointer to MPEG4AudioConfig, used for parsing 457 452 * @param data pointer to AVCodecContext extradata 458 453 * @param data_size size of AVCCodecContext extradata 459 454 * 460 * @return Returns error status . 0 - OK, !0 - error455 * @return Returns error status or number of consumed bits. <0 - error 461 456 */ 462 static int decode_audio_specific_config(AACContext *ac, void *data, 463 int data_size) 457 static int decode_audio_specific_config(AACContext *ac, 458 AVCodecContext *avctx, 459 MPEG4AudioConfig *m4ac, 460 const uint8_t *data, int data_size, int asclen) 464 461 { 465 462 GetBitContext gb; 466 463 int i; 467 464 465 av_log(avctx, AV_LOG_DEBUG, "extradata size %d\n", avctx->extradata_size); 466 for (i = 0; i < avctx->extradata_size; i++) 467 av_log(avctx, AV_LOG_DEBUG, "%02x ", avctx->extradata[i]); 468 av_log(avctx, AV_LOG_DEBUG, "\n"); 469 468 470 init_get_bits(&gb, data, data_size * 8); 469 471 470 if ((i = ff_mpeg4audio_get_config( &ac->m4ac, data, data_size)) < 0)472 if ((i = ff_mpeg4audio_get_config(m4ac, data, asclen/8)) < 0) 471 473 return -1; 472 if ( ac->m4ac.sampling_index > 12) {473 av_log(a c->avctx, AV_LOG_ERROR, "invalid sampling rate index %d\n", ac->m4ac.sampling_index);474 if (m4ac->sampling_index > 12) { 475 av_log(avctx, AV_LOG_ERROR, "invalid sampling rate index %d\n", m4ac->sampling_index); 474 476 return -1; 475 477 } 476 if ( ac->m4ac.sbr == 1 && ac->m4ac.ps == -1)477 ac->m4ac.ps = 1;478 if (m4ac->sbr == 1 && m4ac->ps == -1) 479 m4ac->ps = 1; 478 480 479 481 skip_bits_long(&gb, i); 480 482 481 switch ( ac->m4ac.object_type) {483 switch (m4ac->object_type) { 482 484 case AOT_AAC_MAIN: 483 485 case AOT_AAC_LC: 484 if (decode_ga_specific_config(ac, &gb, ac->m4ac.chan_config)) 486 case AOT_AAC_LTP: 487 if (decode_ga_specific_config(ac, avctx, &gb, m4ac, m4ac->chan_config)) 485 488 return -1; 486 489 break; 487 490 default: 488 av_log(a c->avctx, AV_LOG_ERROR, "Audio object type %s%d is not supported.\n",489 ac->m4ac.sbr == 1? "SBR+" : "", ac->m4ac.object_type);491 av_log(avctx, AV_LOG_ERROR, "Audio object type %s%d is not supported.\n", 492 m4ac->sbr == 1? "SBR+" : "", m4ac->object_type); 490 493 return -1; 491 494 } 492 return 0; 495 496 av_log(avctx, AV_LOG_DEBUG, "AOT %d chan config %d sampling index %d (%d) SBR %d PS %d\n", 497 m4ac->object_type, m4ac->chan_config, m4ac->sampling_index, 498 m4ac->sample_rate, m4ac->sbr, m4ac->ps); 499 500 return get_bits_count(&gb); 493 501 } 494 502 495 503 /** … … static void reset_all_predictors(PredictorState *ps) 521 529 reset_predict_state(&ps[i]); 522 530 } 523 531 532 static int sample_rate_idx (int rate) 533 { 534 if (92017 <= rate) return 0; 535 else if (75132 <= rate) return 1; 536 else if (55426 <= rate) return 2; 537 else if (46009 <= rate) return 3; 538 else if (37566 <= rate) return 4; 539 else if (27713 <= rate) return 5; 540 else if (23004 <= rate) return 6; 541 else if (18783 <= rate) return 7; 542 else if (13856 <= rate) return 8; 543 else if (11502 <= rate) return 9; 544 else if (9391 <= rate) return 10; 545 else return 11; 546 } 547 524 548 static void reset_predictor_group(PredictorState *ps, int group_num) 525 549 { 526 550 int i; … … static av_cold int aac_decode_init(AVCodecContext *avctx) 542 566 ac->m4ac.sample_rate = avctx->sample_rate; 543 567 544 568 if (avctx->extradata_size > 0) { 545 if (decode_audio_specific_config(ac, avctx->extradata, avctx->extradata_size)) 569 if (decode_audio_specific_config(ac, ac->avctx, &ac->m4ac, 570 avctx->extradata, 571 avctx->extradata_size, 8*avctx->extradata_size) < 0) 546 572 return -1; 573 } else { 574 int sr, i; 575 enum ChannelPosition new_che_pos[4][MAX_ELEM_ID]; 576 577 sr = sample_rate_idx(avctx->sample_rate); 578 ac->m4ac.sampling_index = sr; 579 ac->m4ac.channels = avctx->channels; 580 ac->m4ac.sbr = -1; 581 ac->m4ac.ps = -1; 582 583 for (i = 0; i < FF_ARRAY_ELEMS(ff_mpeg4audio_channels); i++) 584 if (ff_mpeg4audio_channels[i] == avctx->channels) 585 break; 586 if (i == FF_ARRAY_ELEMS(ff_mpeg4audio_channels)) { 587 i = 0; 588 } 589 ac->m4ac.chan_config = i; 590 591 if (ac->m4ac.chan_config) { 592 set_default_channel_config(avctx, new_che_pos, ac->m4ac.chan_config); 593 } 547 594 } 548 595 549 596 avctx->sample_fmt = SAMPLE_FMT_S16; … … static av_cold int aac_decode_init(AVCodecContext *avctx) 563 610 ff_aac_sbr_init(); 564 611 565 612 dsputil_init(&ac->dsp, avctx); 613 // ff_fmt_convert_init(&ac->fmt_conv, avctx); 566 614 567 615 ac->random_state = 0x1f2e3d4c; 568 616 569 // -1024 - Compensate wrong IMDCT method.570 // 32768 - Required to scale values to the correct range for the bias method571 // for float to int16 conversion.572 573 if (ac->dsp.float_to_int16_interleave == ff_float_to_int16_interleave_c) {574 ac->add_bias = 385.0f;575 ac->sf_scale = 1. / (-1024. * 32768.);576 ac->sf_offset = 0;577 } else {578 ac->add_bias = 0.0f;579 ac->sf_scale = 1. / -1024.;580 ac->sf_offset = 60;581 }582 583 617 ff_aac_tableinit(); 584 618 585 619 INIT_VLC_STATIC(&vlc_scalefactors,7,FF_ARRAY_ELEMS(ff_aac_scalefactor_code), … … static av_cold int aac_decode_init(AVCodecContext *avctx) 587 621 ff_aac_scalefactor_code, sizeof(ff_aac_scalefactor_code[0]), sizeof(ff_aac_scalefactor_code[0]), 588 622 352); 589 623 590 ff_mdct_init(&ac->mdct, 11, 1, 1.0); 591 ff_mdct_init(&ac->mdct_small, 8, 1, 1.0); 624 ff_mdct_init(&ac->mdct, 11, 1, 1.0/1024.0); 625 ff_mdct_init(&ac->mdct_small, 8, 1, 1.0/128.0); 626 ff_mdct_init(&ac->mdct_ltp, 11, 0, -2.0); 592 627 // window initialization 593 628 ff_kbd_window_init(ff_aac_kbd_long_1024, 4.0, 1024); 594 629 ff_kbd_window_init(ff_aac_kbd_short_128, 6.0, 128); … … static int decode_prediction(AACContext *ac, IndividualChannelStream *ics, 638 673 } 639 674 640 675 /** 676 * Decode Long Term Prediction data; reference: table 4.xx. 677 */ 678 static void decode_ltp(AACContext *ac, LongTermPrediction *ltp, 679 GetBitContext *gb, uint8_t max_sfb) 680 { 681 int sfb; 682 683 ltp->lag = get_bits(gb, 11); 684 ltp->coef = ltp_coef[get_bits(gb, 3)]; 685 for (sfb = 0; sfb < FFMIN(max_sfb, MAX_LTP_LONG_SFB); sfb++) 686 ltp->used[sfb] = get_bits1(gb); 687 } 688 689 /** 641 690 * Decode Individual Channel Stream info; reference: table 4.6. 642 691 * 643 692 * @param common_window Channels have independent [0], or shared [1], Individual Channel Stream information. … … static int decode_ics_info(AACContext *ac, IndividualChannelStream *ics, 691 740 memset(ics, 0, sizeof(IndividualChannelStream)); 692 741 return -1; 693 742 } else { 694 av_log_missing_feature(ac->avctx, "Predictor bit set but LTP is", 1); 695 memset(ics, 0, sizeof(IndividualChannelStream)); 696 return -1; 743 if ((ics->ltp.present = get_bits(gb, 1))) 744 decode_ltp(ac, &ics->ltp, gb, ics->max_sfb); 697 745 } 698 746 } 699 747 } … … static int decode_scalefactors(AACContext *ac, float sf[120], GetBitContext *gb, 771 819 enum BandType band_type[120], 772 820 int band_type_run_end[120]) 773 821 { 774 const int sf_offset = ac->sf_offset + (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE ? 12 : 0);775 822 int g, i, idx = 0; 776 int offset[3] = { global_gain, global_gain - 90, 100 }; 823 int offset[3] = { global_gain, global_gain - 90, 0 }; 824 int clipped_offset; 777 825 int noise_flag = 1; 778 826 static const char *sf_str[3] = { "Global gain", "Noise gain", "Intensity stereo position" }; 779 827 for (g = 0; g < ics->num_window_groups; g++) { … … static int decode_scalefactors(AACContext *ac, float sf[120], GetBitContext *gb, 785 833 } else if ((band_type[idx] == INTENSITY_BT) || (band_type[idx] == INTENSITY_BT2)) { 786 834 for (; i < run_end; i++, idx++) { 787 835 offset[2] += get_vlc2(gb, vlc_scalefactors.table, 7, 3) - 60; 788 if (offset[2] > 255U) { 789 av_log(ac->avctx, AV_LOG_ERROR, 790 "%s (%d) out of range.\n", sf_str[2], offset[2]); 791 return -1; 836 clipped_offset = av_clip(offset[2], -155, 100); 837 if (offset[2] != clipped_offset) { 838 /* av_log_ask_for_sample(ac->avctx, "Intensity stereo " 839 "position clipped (%d -> %d).\nIf you heard an " 840 "audible artifact, there may be a bug in the " 841 "decoder. ", offset[2], clipped_offset); 842 */ 792 843 } 793 sf[idx] = ff_aac_pow2sf_tab[- offset[2] + 300];844 sf[idx] = ff_aac_pow2sf_tab[-clipped_offset + POW_SF2_ZERO]; 794 845 } 795 846 } else if (band_type[idx] == NOISE_BT) { 796 847 for (; i < run_end; i++, idx++) { … … static int decode_scalefactors(AACContext *ac, float sf[120], GetBitContext *gb, 798 849 offset[1] += get_bits(gb, 9) - 256; 799 850 else 800 851 offset[1] += get_vlc2(gb, vlc_scalefactors.table, 7, 3) - 60; 801 if (offset[1] > 255U) { 802 av_log(ac->avctx, AV_LOG_ERROR, 803 "%s (%d) out of range.\n", sf_str[1], offset[1]); 804 return -1; 852 clipped_offset = av_clip(offset[1], -100, 155); 853 if (offset[1] != clipped_offset) { 854 /* av_log_ask_for_sample(ac->avctx, "Noise gain clipped " 855 "(%d -> %d).\nIf you heard an audible " 856 "artifact, there may be a bug in the decoder. ", 857 offset[1], clipped_offset); 858 */ 805 859 } 806 sf[idx] = -ff_aac_pow2sf_tab[ offset[1] + sf_offset + 100];860 sf[idx] = -ff_aac_pow2sf_tab[clipped_offset + POW_SF2_ZERO]; 807 861 } 808 862 } else { 809 863 for (; i < run_end; i++, idx++) { … … static int decode_scalefactors(AACContext *ac, float sf[120], GetBitContext *gb, 813 867 "%s (%d) out of range.\n", sf_str[0], offset[0]); 814 868 return -1; 815 869 } 816 sf[idx] = -ff_aac_pow2sf_tab[ offset[0] + sf_offset];870 sf[idx] = -ff_aac_pow2sf_tab[offset[0] - 100 + POW_SF2_ZERO]; 817 871 } 818 872 } 819 873 } … … static inline float *VMUL4S(float *dst, const float *v, unsigned idx, 954 1008 union float754 s = { .f = *scale }; 955 1009 union float754 t; 956 1010 957 t.i = s.i ^ (sign & 1 <<31);1011 t.i = s.i ^ (sign & 1U<<31); 958 1012 *dst++ = v[idx & 3] * t.f; 959 1013 960 1014 sign <<= nz & 1; nz >>= 1; 961 t.i = s.i ^ (sign & 1 <<31);1015 t.i = s.i ^ (sign & 1U<<31); 962 1016 *dst++ = v[idx>>2 & 3] * t.f; 963 1017 964 1018 sign <<= nz & 1; nz >>= 1; 965 t.i = s.i ^ (sign & 1 <<31);1019 t.i = s.i ^ (sign & 1U<<31); 966 1020 *dst++ = v[idx>>4 & 3] * t.f; 967 1021 968 1022 sign <<= nz & 1; nz >>= 1; 969 t.i = s.i ^ (sign & 1 <<31);1023 t.i = s.i ^ (sign & 1U<<31); 970 1024 *dst++ = v[idx>>6 & 3] * t.f; 971 1025 972 1026 return dst; … … static int decode_spectrum_and_dequant(AACContext *ac, float coef[1024], 1063 1117 1064 1118 UPDATE_CACHE(re, gb); 1065 1119 GET_VLC(code, re, gb, vlc_tab, 8, 2); 1066 #if MIN_CACHE_BITS < 201067 UPDATE_CACHE(re, gb);1068 #endif1069 1120 cb_idx = cb_vector_idx[code]; 1070 1121 nnz = cb_idx >> 8 & 15; 1071 1122 bits = SHOW_UBITS(re, gb, nnz) << (32-nnz); … … static int decode_spectrum_and_dequant(AACContext *ac, float coef[1024], 1158 1209 return -1; 1159 1210 } 1160 1211 1161 #if MIN_CACHE_BITS < 211162 LAST_SKIP_BITS(re, gb, b + 1);1163 UPDATE_CACHE(re, gb);1164 #else1165 1212 SKIP_BITS(re, gb, b + 1); 1166 #endif1167 1213 b += 4; 1168 1214 n = (1 << b) + SHOW_UBITS(re, gb, b); 1169 1215 LAST_SKIP_BITS(re, gb, b); 1170 *icf++ = cbrt_tab[n] | (bits & 1 <<31);1216 *icf++ = cbrt_tab[n] | (bits & 1U<<31); 1171 1217 bits <<= 1; 1172 1218 } else { 1173 1219 unsigned v = ((const uint32_t*)vq)[cb_idx & 15]; 1174 *icf++ = (bits & 1 <<31) | v;1220 *icf++ = (bits & 1U<<31) | v; 1175 1221 bits <<= !!v; 1176 1222 } 1177 1223 cb_idx >>= 4; … … static av_always_inline float flt16_trunc(float pf) 1232 1278 } 1233 1279 1234 1280 static av_always_inline void predict(PredictorState *ps, float *coef, 1235 float sf_scale, float inv_sf_scale, 1236 int output_enable) 1281 int output_enable) 1237 1282 { 1238 1283 const float a = 0.953125; // 61.0 / 64 1239 1284 const float alpha = 0.90625; // 29.0 / 32 … … static av_always_inline void predict(PredictorState *ps, float *coef, 1249 1294 1250 1295 pv = flt16_round(k1 * r0 + k2 * r1); 1251 1296 if (output_enable) 1252 *coef += pv * sf_scale;1297 *coef += pv; 1253 1298 1254 e0 = *coef * inv_sf_scale;1299 e0 = *coef; 1255 1300 e1 = e0 - k1 * r0; 1256 1301 1257 1302 ps->cor1 = flt16_trunc(alpha * cor1 + r1 * e1); … … static av_always_inline void predict(PredictorState *ps, float *coef, 1269 1314 static void apply_prediction(AACContext *ac, SingleChannelElement *sce) 1270 1315 { 1271 1316 int sfb, k; 1272 float sf_scale = ac->sf_scale, inv_sf_scale = 1 / ac->sf_scale;1273 1317 1274 1318 if (!sce->ics.predictor_initialized) { 1275 1319 reset_all_predictors(sce->predictor_state); … … static void apply_prediction(AACContext *ac, SingleChannelElement *sce) 1280 1324 for (sfb = 0; sfb < ff_aac_pred_sfb_max[ac->m4ac.sampling_index]; sfb++) { 1281 1325 for (k = sce->ics.swb_offset[sfb]; k < sce->ics.swb_offset[sfb + 1]; k++) { 1282 1326 predict(&sce->predictor_state[k], &sce->coeffs[k], 1283 sf_scale, inv_sf_scale,1284 1327 sce->ics.predictor_present && sce->ics.prediction_used[sfb]); 1285 1328 } 1286 1329 } … … static void apply_mid_side_stereo(AACContext *ac, ChannelElement *cpe) 1386 1429 * [1] mask is decoded from bitstream; [2] mask is all 1s; 1387 1430 * [3] reserved for scalable AAC 1388 1431 */ 1389 static void apply_intensity_stereo( ChannelElement *cpe, int ms_present)1432 static void apply_intensity_stereo(AACContext *ac, ChannelElement *cpe, int ms_present) 1390 1433 { 1391 1434 const IndividualChannelStream *ics = &cpe->ch[1].ics; 1392 1435 SingleChannelElement *sce1 = &cpe->ch[1]; 1393 1436 float *coef0 = cpe->ch[0].coeffs, *coef1 = cpe->ch[1].coeffs; 1394 1437 const uint16_t *offsets = ics->swb_offset; 1395 int g, group, i, k,idx = 0;1438 int g, group, i, idx = 0; 1396 1439 int c; 1397 1440 float scale; 1398 1441 for (g = 0; g < ics->num_window_groups; g++) { … … static void apply_intensity_stereo(ChannelElement *cpe, int ms_present) 1405 1448 c *= 1 - 2 * cpe->ms_mask[idx]; 1406 1449 scale = c * sce1->sf[idx]; 1407 1450 for (group = 0; group < ics->group_len[g]; group++) 1408 for (k = offsets[i]; k < offsets[i + 1]; k++) 1409 coef1[group * 128 + k] = scale * coef0[group * 128 + k]; 1451 ac->dsp.vector_fmul_scalar(coef1 + group * 128 + offsets[i], 1452 coef0 + group * 128 + offsets[i], 1453 scale, 1454 offsets[i + 1] - offsets[i]); 1410 1455 } 1411 1456 } else { 1412 1457 int bt_run_end = sce1->band_type_run_end[idx]; … … static int decode_cpe(AACContext *ac, GetBitContext *gb, ChannelElement *cpe) 1435 1480 i = cpe->ch[1].ics.use_kb_window[0]; 1436 1481 cpe->ch[1].ics = cpe->ch[0].ics; 1437 1482 cpe->ch[1].ics.use_kb_window[1] = i; 1483 if (cpe->ch[1].ics.predictor_present && (ac->m4ac.object_type != AOT_AAC_MAIN)) 1484 if ((cpe->ch[1].ics.ltp.present = get_bits(gb, 1))) 1485 decode_ltp(ac, &cpe->ch[1].ics.ltp, gb, cpe->ch[1].ics.max_sfb); 1438 1486 ms_present = get_bits(gb, 2); 1439 1487 if (ms_present == 3) { 1440 1488 av_log(ac->avctx, AV_LOG_ERROR, "ms_present = 3 is reserved.\n"); … … static int decode_cpe(AACContext *ac, GetBitContext *gb, ChannelElement *cpe) 1456 1504 } 1457 1505 } 1458 1506 1459 apply_intensity_stereo( cpe, ms_present);1507 apply_intensity_stereo(ac, cpe, ms_present); 1460 1508 return 0; 1461 1509 } 1462 1510 … … static void apply_tns(float coef[1024], TemporalNoiseShaping *tns, 1674 1722 int w, filt, m, i; 1675 1723 int bottom, top, order, start, end, size, inc; 1676 1724 float lpc[TNS_MAX_ORDER]; 1725 float tmp[TNS_MAX_ORDER]; 1677 1726 1678 1727 for (w = 0; w < ics->num_windows; w++) { 1679 1728 bottom = ics->num_swb; … … static void apply_tns(float coef[1024], TemporalNoiseShaping *tns, 1699 1748 } 1700 1749 start += w * 128; 1701 1750 1702 // ar filter 1703 for (m = 0; m < size; m++, start += inc) 1704 for (i = 1; i <= FFMIN(m, order); i++) 1705 coef[start] -= coef[start - i * inc] * lpc[i - 1]; 1751 if (decode) { 1752 // ar filter 1753 for (m = 0; m < size; m++, start += inc) 1754 for (i = 1; i <= FFMIN(m, order); i++) 1755 coef[start] -= coef[start - i * inc] * lpc[i - 1]; 1756 } else { 1757 // ma filter 1758 for (m = 0; m < size; m++, start += inc) { 1759 tmp[0] = coef[start]; 1760 for (i = 1; i <= FFMIN(m, order); i++) 1761 coef[start] += tmp[i] * lpc[i - 1]; 1762 for (i = order; i > 0; i--) 1763 tmp[i] = tmp[i - 1]; 1764 } 1765 } 1706 1766 } 1707 1767 } 1708 1768 } 1709 1769 1770 static void vector_fmul(float *dst, const float *src0, const float *src1, int len){ 1771 int i; 1772 for(i=0; i<len; i++) 1773 dst[i] = src0[i] * src1[i]; 1774 } 1775 1776 /** 1777 * Apply windowing and MDCT to obtain the spectral 1778 * coefficient from the predicted sample by LTP. 1779 */ 1780 static void windowing_and_mdct_ltp(AACContext *ac, float *out, 1781 float *in, IndividualChannelStream *ics) 1782 { 1783 const float *lwindow = ics->use_kb_window[0] ? ff_aac_kbd_long_1024 : ff_sine_1024; 1784 const float *swindow = ics->use_kb_window[0] ? ff_aac_kbd_short_128 : ff_sine_128; 1785 const float *lwindow_prev = ics->use_kb_window[1] ? ff_aac_kbd_long_1024 : ff_sine_1024; 1786 const float *swindow_prev = ics->use_kb_window[1] ? ff_aac_kbd_short_128 : ff_sine_128; 1787 1788 if (ics->window_sequence[0] != LONG_STOP_SEQUENCE) { 1789 vector_fmul(in, in, lwindow_prev, 1024); 1790 } else { 1791 memset(in, 0, 448 * sizeof(float)); 1792 vector_fmul(in + 448, in + 448, swindow_prev, 128); 1793 } 1794 if (ics->window_sequence[0] != LONG_START_SEQUENCE) { 1795 ac->dsp.vector_fmul_reverse(in + 1024, in + 1024, lwindow, 1024); 1796 } else { 1797 ac->dsp.vector_fmul_reverse(in + 1024 + 448, in + 1024 + 448, swindow, 128); 1798 memset(in + 1024 + 576, 0, 448 * sizeof(float)); 1799 } 1800 ac->mdct_ltp.mdct_calc(&ac->mdct_ltp, out, in); 1801 } 1802 1803 /** 1804 * Apply the long term prediction 1805 */ 1806 static void apply_ltp(AACContext *ac, SingleChannelElement *sce) 1807 { 1808 const LongTermPrediction *ltp = &sce->ics.ltp; 1809 const uint16_t *offsets = sce->ics.swb_offset; 1810 int i, sfb; 1811 1812 if (sce->ics.window_sequence[0] != EIGHT_SHORT_SEQUENCE) { 1813 float *predTime = sce->ret; 1814 float *predFreq = ac->buf_mdct; 1815 int16_t num_samples = 2048; 1816 1817 if (ltp->lag < 1024) 1818 num_samples = ltp->lag + 1024; 1819 for (i = 0; i < num_samples; i++) 1820 predTime[i] = sce->ltp_state[i + 2048 - ltp->lag] * ltp->coef; 1821 memset(&predTime[i], 0, (2048 - i) * sizeof(float)); 1822 1823 windowing_and_mdct_ltp(ac, predFreq, predTime, &sce->ics); 1824 1825 if (sce->tns.present) 1826 apply_tns(predFreq, &sce->tns, &sce->ics, 0); 1827 1828 for (sfb = 0; sfb < FFMIN(sce->ics.max_sfb, MAX_LTP_LONG_SFB); sfb++) 1829 if (ltp->used[sfb]) 1830 for (i = offsets[sfb]; i < offsets[sfb + 1]; i++) 1831 sce->coeffs[i] += predFreq[i]; 1832 } 1833 } 1834 1835 /** 1836 * Update the LTP buffer for next frame 1837 */ 1838 static void update_ltp(AACContext *ac, SingleChannelElement *sce) 1839 { 1840 IndividualChannelStream *ics = &sce->ics; 1841 float *saved = sce->saved; 1842 float *saved_ltp = sce->coeffs; 1843 const float *lwindow = ics->use_kb_window[0] ? ff_aac_kbd_long_1024 : ff_sine_1024; 1844 const float *swindow = ics->use_kb_window[0] ? ff_aac_kbd_short_128 : ff_sine_128; 1845 int i; 1846 1847 if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) { 1848 memcpy(saved_ltp, saved, 512 * sizeof(float)); 1849 memset(saved_ltp + 576, 0, 448 * sizeof(float)); 1850 ac->dsp.vector_fmul_reverse(saved_ltp + 448, ac->buf_mdct + 960, &swindow[64], 64); 1851 for (i = 0; i < 64; i++) 1852 saved_ltp[i + 512] = ac->buf_mdct[1023 - i] * swindow[63 - i]; 1853 } else if (ics->window_sequence[0] == LONG_START_SEQUENCE) { 1854 memcpy(saved_ltp, ac->buf_mdct + 512, 448 * sizeof(float)); 1855 memset(saved_ltp + 576, 0, 448 * sizeof(float)); 1856 ac->dsp.vector_fmul_reverse(saved_ltp + 448, ac->buf_mdct + 960, &swindow[64], 64); 1857 for (i = 0; i < 64; i++) 1858 saved_ltp[i + 512] = ac->buf_mdct[1023 - i] * swindow[63 - i]; 1859 } else { // LONG_STOP or ONLY_LONG 1860 ac->dsp.vector_fmul_reverse(saved_ltp, ac->buf_mdct + 512, &lwindow[512], 512); 1861 for (i = 0; i < 512; i++) 1862 saved_ltp[i + 512] = ac->buf_mdct[1023 - i] * lwindow[511 - i]; 1863 } 1864 1865 memcpy(sce->ltp_state, sce->ltp_state+1024, 1024 * sizeof(*sce->ltp_state)); 1866 memcpy(sce->ltp_state+1024, sce->ret, 1024 * sizeof(*sce->ltp_state)); 1867 memcpy(sce->ltp_state+2048, saved_ltp, 1024 * sizeof(*sce->ltp_state)); 1868 } 1869 1710 1870 /** 1711 1871 * Conduct IMDCT and windowing. 1712 1872 */ 1713 static void imdct_and_windowing(AACContext *ac, SingleChannelElement *sce , float bias)1873 static void imdct_and_windowing(AACContext *ac, SingleChannelElement *sce) 1714 1874 { 1715 1875 IndividualChannelStream *ics = &sce->ics; 1716 1876 float *in = sce->coeffs; … … static void imdct_and_windowing(AACContext *ac, SingleChannelElement *sce, float 1726 1886 // imdct 1727 1887 if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) { 1728 1888 for (i = 0; i < 1024; i += 128) 1729 ff_imdct_half(&ac->mdct_small, buf + i, in + i);1889 ac->mdct_small.imdct_half(&ac->mdct_small, buf + i, in + i); 1730 1890 } else 1731 ff_imdct_half(&ac->mdct, buf, in);1891 ac->mdct.imdct_half(&ac->mdct, buf, in); 1732 1892 1733 1893 /* window overlapping 1734 1894 * NOTE: To simplify the overlapping code, all 'meaningless' short to long … … static void imdct_and_windowing(AACContext *ac, SingleChannelElement *sce, float 1738 1898 */ 1739 1899 if ((ics->window_sequence[1] == ONLY_LONG_SEQUENCE || ics->window_sequence[1] == LONG_STOP_SEQUENCE) && 1740 1900 (ics->window_sequence[0] == ONLY_LONG_SEQUENCE || ics->window_sequence[0] == LONG_START_SEQUENCE)) { 1741 ac->dsp.vector_fmul_window( out, saved, buf, lwindow_prev, bias, 512);1901 ac->dsp.vector_fmul_window( out, saved, buf, lwindow_prev, 0.0f, 512); 1742 1902 } else { 1743 for (i = 0; i < 448; i++) 1744 out[i] = saved[i] + bias; 1903 memcpy( out, saved, 448 * sizeof(float)); 1745 1904 1746 1905 if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) { 1747 ac->dsp.vector_fmul_window(out + 448 + 0*128, saved + 448, buf + 0*128, swindow_prev, bias, 64);1748 ac->dsp.vector_fmul_window(out + 448 + 1*128, buf + 0*128 + 64, buf + 1*128, swindow, bias, 64);1749 ac->dsp.vector_fmul_window(out + 448 + 2*128, buf + 1*128 + 64, buf + 2*128, swindow, bias, 64);1750 ac->dsp.vector_fmul_window(out + 448 + 3*128, buf + 2*128 + 64, buf + 3*128, swindow, bias, 64);1751 ac->dsp.vector_fmul_window(temp, buf + 3*128 + 64, buf + 4*128, swindow, bias, 64);1906 ac->dsp.vector_fmul_window(out + 448 + 0*128, saved + 448, buf + 0*128, swindow_prev, 0.0f, 64); 1907 ac->dsp.vector_fmul_window(out + 448 + 1*128, buf + 0*128 + 64, buf + 1*128, swindow, 0.0f, 64); 1908 ac->dsp.vector_fmul_window(out + 448 + 2*128, buf + 1*128 + 64, buf + 2*128, swindow, 0.0f, 64); 1909 ac->dsp.vector_fmul_window(out + 448 + 3*128, buf + 2*128 + 64, buf + 3*128, swindow, 0.0f, 64); 1910 ac->dsp.vector_fmul_window(temp, buf + 3*128 + 64, buf + 4*128, swindow, 0.0f, 64); 1752 1911 memcpy( out + 448 + 4*128, temp, 64 * sizeof(float)); 1753 1912 } else { 1754 ac->dsp.vector_fmul_window(out + 448, saved + 448, buf, swindow_prev, bias, 64); 1755 for (i = 576; i < 1024; i++) 1756 out[i] = buf[i-512] + bias; 1913 ac->dsp.vector_fmul_window(out + 448, saved + 448, buf, swindow_prev, 0.0f, 64); 1914 memcpy( out + 576, buf + 64, 448 * sizeof(float)); 1757 1915 } 1758 1916 } 1759 1917 1760 1918 // buffer update 1761 1919 if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) { 1762 for (i = 0; i < 64; i++) 1763 saved[i] = temp[64 + i] - bias; 1764 ac->dsp.vector_fmul_window(saved + 64, buf + 4*128 + 64, buf + 5*128, swindow, 0, 64); 1765 ac->dsp.vector_fmul_window(saved + 192, buf + 5*128 + 64, buf + 6*128, swindow, 0, 64); 1766 ac->dsp.vector_fmul_window(saved + 320, buf + 6*128 + 64, buf + 7*128, swindow, 0, 64); 1920 memcpy( saved, temp + 64, 64 * sizeof(float)); 1921 ac->dsp.vector_fmul_window(saved + 64, buf + 4*128 + 64, buf + 5*128, swindow, 0.0f, 64); 1922 ac->dsp.vector_fmul_window(saved + 192, buf + 5*128 + 64, buf + 6*128, swindow, 0.0f, 64); 1923 ac->dsp.vector_fmul_window(saved + 320, buf + 6*128 + 64, buf + 7*128, swindow, 0.0f, 64); 1767 1924 memcpy( saved + 448, buf + 7*128 + 64, 64 * sizeof(float)); 1768 1925 } else if (ics->window_sequence[0] == LONG_START_SEQUENCE) { 1769 1926 memcpy( saved, buf + 512, 448 * sizeof(float)); … … static void apply_independent_coupling(AACContext *ac, 1820 1977 { 1821 1978 int i; 1822 1979 const float gain = cce->coup.gain[index][0]; 1823 const float bias = ac->add_bias;1824 1980 const float *src = cce->ch[0].ret; 1825 1981 float *dest = target->ret; 1826 1982 const int len = 1024 << (ac->m4ac.sbr == 1); 1827 1983 1828 1984 for (i = 0; i < len; i++) 1829 dest[i] += gain * (src[i] - bias);1985 dest[i] += gain * src[i]; 1830 1986 } 1831 1987 1832 1988 /** … … static void apply_channel_coupling(AACContext *ac, ChannelElement *cc, 1870 2026 static void spectral_to_sample(AACContext *ac) 1871 2027 { 1872 2028 int i, type; 1873 float imdct_bias = (ac->m4ac.sbr <= 0) ? ac->add_bias : 0.0f;1874 2029 for (type = 3; type >= 0; type--) { 1875 2030 for (i = 0; i < MAX_ELEM_ID; i++) { 1876 2031 ChannelElement *che = ac->che[type][i]; 1877 2032 if (che) { 1878 2033 if (type <= TYPE_CPE) 1879 2034 apply_channel_coupling(ac, che, type, i, BEFORE_TNS, apply_dependent_coupling); 2035 if (ac->m4ac.object_type == AOT_AAC_LTP) { 2036 if (che->ch[0].ics.predictor_present) { 2037 if (che->ch[0].ics.ltp.present) 2038 apply_ltp(ac, &che->ch[0]); 2039 if (che->ch[1].ics.ltp.present && type == TYPE_CPE) 2040 apply_ltp(ac, &che->ch[1]); 2041 } 2042 } 1880 2043 if (che->ch[0].tns.present) 1881 2044 apply_tns(che->ch[0].coeffs, &che->ch[0].tns, &che->ch[0].ics, 1); 1882 2045 if (che->ch[1].tns.present) … … static void spectral_to_sample(AACContext *ac) 1884 2047 if (type <= TYPE_CPE) 1885 2048 apply_channel_coupling(ac, che, type, i, BETWEEN_TNS_AND_IMDCT, apply_dependent_coupling); 1886 2049 if (type != TYPE_CCE || che->coup.coupling_point == AFTER_IMDCT) { 1887 imdct_and_windowing(ac, &che->ch[0], imdct_bias); 2050 imdct_and_windowing(ac, &che->ch[0]); 2051 if (ac->m4ac.object_type == AOT_AAC_LTP) 2052 update_ltp(ac, &che->ch[0]); 1888 2053 if (type == TYPE_CPE) { 1889 imdct_and_windowing(ac, &che->ch[1], imdct_bias); 2054 imdct_and_windowing(ac, &che->ch[1]); 2055 if (ac->m4ac.object_type == AOT_AAC_LTP) 2056 update_ltp(ac, &che->ch[1]); 1890 2057 } 1891 2058 if (ac->m4ac.sbr > 0) { 1892 2059 ff_sbr_apply(ac, &che->sbr, type, che->ch[0].ret, che->ch[1].ret); … … static int parse_adts_frame_header(AACContext *ac, GetBitContext *gb) 1906 2073 1907 2074 size = ff_aac_parse_header(gb, &hdr_info); 1908 2075 if (size > 0) { 1909 if ( ac->output_configured != OC_LOCKED &&hdr_info.chan_config) {2076 if (hdr_info.chan_config) { 1910 2077 enum ChannelPosition new_che_pos[4][MAX_ELEM_ID]; 1911 2078 memset(new_che_pos, 0, 4 * MAX_ELEM_ID * sizeof(new_che_pos[0][0])); 1912 2079 ac->m4ac.chan_config = hdr_info.chan_config; 1913 if (set_default_channel_config(ac , new_che_pos, hdr_info.chan_config))2080 if (set_default_channel_config(ac->avctx, new_che_pos, hdr_info.chan_config)) 1914 2081 return -7; 1915 2082 if (output_configure(ac, ac->che_pos, new_che_pos, hdr_info.chan_config, OC_TRIAL_FRAME)) 1916 2083 return -7; 1917 2084 } else if (ac->output_configured != OC_LOCKED) { 2085 ac->m4ac.chan_config = 0; 1918 2086 ac->output_configured = OC_NONE; 1919 2087 } 1920 2088 if (ac->output_configured != OC_LOCKED) { 1921 2089 ac->m4ac.sbr = -1; 1922 2090 ac->m4ac.ps = -1; 2091 ac->m4ac.sample_rate = hdr_info.sample_rate; 2092 ac->m4ac.sampling_index = hdr_info.sampling_index; 2093 ac->m4ac.object_type = hdr_info.object_type; 1923 2094 } 1924 ac->m4ac.sample_rate = hdr_info.sample_rate;1925 ac->m4ac.sampling_index = hdr_info.sampling_index;1926 ac->m4ac.object_type = hdr_info.object_type;1927 2095 if (!ac->avctx->sample_rate) 1928 2096 ac->avctx->sample_rate = hdr_info.sample_rate; 1929 2097 if (hdr_info.num_aac_frames == 1) { … … static int parse_adts_frame_header(AACContext *ac, GetBitContext *gb) 1937 2105 return size; 1938 2106 } 1939 2107 1940 static int aac_decode_frame (AVCodecContext *avctx, void *data,1941 int *data_size, AVPacket *avpkt)2108 static int aac_decode_frame_int(AVCodecContext *avctx, void *data, 2109 int *data_size, GetBitContext *gb) 1942 2110 { 1943 const uint8_t *buf = avpkt->data;1944 int buf_size = avpkt->size;1945 2111 AACContext *ac = avctx->priv_data; 1946 2112 ChannelElement *che = NULL, *che_prev = NULL; 1947 GetBitContext gb;1948 2113 enum RawDataBlockType elem_type, elem_type_prev = TYPE_END; 1949 2114 int err, elem_id, data_size_tmp; 1950 int buf_consumed; 1951 int samples = 0, multiplier; 1952 int buf_offset; 2115 int samples = 0, multiplier, audio_found = 0; 1953 2116 1954 init_get_bits(&gb, buf, buf_size * 8); 1955 1956 if (show_bits(&gb, 12) == 0xfff) { 1957 if (parse_adts_frame_header(ac, &gb) < 0) { 2117 if (show_bits(gb, 12) == 0xfff) { 2118 if (parse_adts_frame_header(ac, gb) < 0) { 1958 2119 av_log(avctx, AV_LOG_ERROR, "Error decoding AAC frame header.\n"); 1959 2120 return -1; 1960 2121 } … … static int aac_decode_frame(AVCodecContext *avctx, void *data, 1964 2125 } 1965 2126 } 1966 2127 1967 memset(ac->tags_seen_this_frame, 0, sizeof(ac->tags_seen_this_frame));2128 ac->tags_mapped = 0; 1968 2129 // parse 1969 while ((elem_type = get_bits( &gb, 3)) != TYPE_END) {1970 elem_id = get_bits( &gb, 4);2130 while ((elem_type = get_bits(gb, 3)) != TYPE_END) { 2131 elem_id = get_bits(gb, 4); 1971 2132 1972 2133 if (elem_type < TYPE_DSE) { 1973 2134 if (!(che=get_che(ac, elem_type, elem_id))) { … … static int aac_decode_frame(AVCodecContext *avctx, void *data, 1981 2142 switch (elem_type) { 1982 2143 1983 2144 case TYPE_SCE: 1984 err = decode_ics(ac, &che->ch[0], &gb, 0, 0); 2145 err = decode_ics(ac, &che->ch[0], gb, 0, 0); 2146 audio_found = 1; 1985 2147 break; 1986 2148 1987 2149 case TYPE_CPE: 1988 err = decode_cpe(ac, &gb, che); 2150 err = decode_cpe(ac, gb, che); 2151 audio_found = 1; 1989 2152 break; 1990 2153 1991 2154 case TYPE_CCE: 1992 err = decode_cce(ac, &gb, che);2155 err = decode_cce(ac, gb, che); 1993 2156 break; 1994 2157 1995 2158 case TYPE_LFE: 1996 err = decode_ics(ac, &che->ch[0], &gb, 0, 0); 2159 err = decode_ics(ac, &che->ch[0], gb, 0, 0); 2160 audio_found = 1; 1997 2161 break; 1998 2162 1999 2163 case TYPE_DSE: 2000 err = skip_data_stream_element(ac, &gb);2164 err = skip_data_stream_element(ac, gb); 2001 2165 break; 2002 2166 2003 2167 case TYPE_PCE: { 2004 2168 enum ChannelPosition new_che_pos[4][MAX_ELEM_ID]; 2005 2169 memset(new_che_pos, 0, 4 * MAX_ELEM_ID * sizeof(new_che_pos[0][0])); 2006 if ((err = decode_pce(a c, new_che_pos, &gb)))2170 if ((err = decode_pce(avctx, &ac->m4ac, new_che_pos, gb))) 2007 2171 break; 2008 2172 if (ac->output_configured > OC_TRIAL_PCE) 2009 2173 av_log(avctx, AV_LOG_ERROR, … … static int aac_decode_frame(AVCodecContext *avctx, void *data, 2015 2179 2016 2180 case TYPE_FIL: 2017 2181 if (elem_id == 15) 2018 elem_id += get_bits( &gb, 8) - 1;2019 if (get_bits_left( &gb) < 8 * elem_id) {2182 elem_id += get_bits(gb, 8) - 1; 2183 if (get_bits_left(gb) < 8 * elem_id) { 2020 2184 av_log(avctx, AV_LOG_ERROR, overread_err); 2021 2185 return -1; 2022 2186 } 2023 2187 while (elem_id > 0) 2024 elem_id -= decode_extension_payload(ac, &gb, elem_id, che_prev, elem_type_prev);2188 elem_id -= decode_extension_payload(ac, gb, elem_id, che_prev, elem_type_prev); 2025 2189 err = 0; /* FIXME */ 2026 2190 break; 2027 2191 … … static int aac_decode_frame(AVCodecContext *avctx, void *data, 2036 2200 if (err) 2037 2201 return err; 2038 2202 2039 if (get_bits_left( &gb) < 3) {2203 if (get_bits_left(gb) < 3) { 2040 2204 av_log(avctx, AV_LOG_ERROR, overread_err); 2041 2205 return -1; 2042 2206 } … … static int aac_decode_frame(AVCodecContext *avctx, void *data, 2063 2227 if (samples) 2064 2228 ac->dsp.float_to_int16_interleave(data, (const float **)ac->output_data, samples, avctx->channels); 2065 2229 2066 if (ac->output_configured) 2230 // if (samples) 2231 // ac->fmt_conv.float_to_int16_interleave(data, (const float **)ac->output_data, samples, avctx->channels); 2232 2233 if (ac->output_configured && audio_found) 2067 2234 ac->output_configured = OC_LOCKED; 2068 2235 2236 return 0; 2237 } 2238 2239 static int aac_decode_frame(AVCodecContext *avctx, void *data, 2240 int *data_size, AVPacket *avpkt) 2241 { 2242 const uint8_t *buf = avpkt->data; 2243 int buf_size = avpkt->size; 2244 GetBitContext gb; 2245 int buf_consumed; 2246 int buf_offset; 2247 int err; 2248 2249 init_get_bits(&gb, buf, buf_size * 8); 2250 2251 if ((err = aac_decode_frame_int(avctx, data, data_size, &gb)) < 0) 2252 return err; 2253 2069 2254 buf_consumed = (get_bits_count(&gb) + 7) >> 3; 2070 2255 for (buf_offset = buf_consumed; buf_offset < buf_size; buf_offset++) 2071 2256 if (buf[buf_offset]) … … static av_cold int aac_decode_close(AVCodecContext *avctx) 2089 2274 2090 2275 ff_mdct_end(&ac->mdct); 2091 2276 ff_mdct_end(&ac->mdct_small); 2277 ff_mdct_end(&ac->mdct_ltp); 2092 2278 return 0; 2093 2279 } 2094 2280 2281 2282 #define LOAS_SYNC_WORD 0x2b7 ///< 11 bits LOAS sync word 2283 2284 struct LATMContext { 2285 AACContext aac_ctx; ///< containing AACContext 2286 int initialized; ///< initilized after a valid extradata was seen 2287 2288 // parser data 2289 int audio_mux_version_A; ///< LATM syntax version 2290 int frame_length_type; ///< 0/1 variable/fixed frame length 2291 int frame_length; ///< frame length for fixed frame length 2292 }; 2293 2294 static inline uint32_t latm_get_value(GetBitContext *b) 2295 { 2296 int length = get_bits(b, 2); 2297 2298 return get_bits_long(b, (length+1)*8); 2299 } 2300 2301 static int latm_decode_audio_specific_config(struct LATMContext *latmctx, 2302 GetBitContext *gb, int asclen) 2303 { 2304 AVCodecContext *avctx = latmctx->aac_ctx.avctx; 2305 MPEG4AudioConfig m4ac; 2306 AACContext *ac= &latmctx->aac_ctx; 2307 int config_start_bit = get_bits_count(gb); 2308 int bits_consumed, esize; 2309 2310 if (config_start_bit % 8) { 2311 av_log_missing_feature(latmctx->aac_ctx.avctx, "audio specific " 2312 "config not byte aligned.\n", 1); 2313 return AVERROR_INVALIDDATA; 2314 } else { 2315 bits_consumed = 2316 decode_audio_specific_config(ac, avctx, &m4ac, 2317 gb->buffer + (config_start_bit / 8), 2318 get_bits_left(gb) / 8, asclen); 2319 2320 if (bits_consumed < 0) 2321 return AVERROR_INVALIDDATA; 2322 ac->m4ac= m4ac; 2323 2324 esize = (bits_consumed+7) / 8; 2325 2326 if (avctx->extradata_size <= esize) { 2327 av_free(avctx->extradata); 2328 avctx->extradata = av_malloc(esize + FF_INPUT_BUFFER_PADDING_SIZE); 2329 if (!avctx->extradata) 2330 return AVERROR(ENOMEM); 2331 } 2332 2333 avctx->extradata_size = esize; 2334 memcpy(avctx->extradata, gb->buffer + (config_start_bit/8), esize); 2335 memset(avctx->extradata+esize, 0, FF_INPUT_BUFFER_PADDING_SIZE); 2336 2337 skip_bits_long(gb, bits_consumed); 2338 } 2339 2340 return bits_consumed; 2341 } 2342 2343 static int read_stream_mux_config(struct LATMContext *latmctx, 2344 GetBitContext *gb) 2345 { 2346 int ret, audio_mux_version = get_bits(gb, 1); 2347 2348 latmctx->audio_mux_version_A = 0; 2349 if (audio_mux_version) 2350 latmctx->audio_mux_version_A = get_bits(gb, 1); 2351 2352 if (!latmctx->audio_mux_version_A) { 2353 2354 if (audio_mux_version) 2355 latm_get_value(gb); // taraFullness 2356 2357 skip_bits(gb, 1); // allStreamSameTimeFraming 2358 skip_bits(gb, 6); // numSubFrames 2359 // numPrograms 2360 if (get_bits(gb, 4)) { // numPrograms 2361 av_log_missing_feature(latmctx->aac_ctx.avctx, 2362 "multiple programs are not supported\n", 1); 2363 return AVERROR_PATCHWELCOME; 2364 } 2365 2366 // for each program (which there is only on in DVB) 2367 2368 // for each layer (which there is only on in DVB) 2369 if (get_bits(gb, 3)) { // numLayer 2370 av_log_missing_feature(latmctx->aac_ctx.avctx, 2371 "multiple layers are not supported\n", 1); 2372 return AVERROR_PATCHWELCOME; 2373 } 2374 2375 // for all but first stream: use_same_config = get_bits(gb, 1); 2376 if (!audio_mux_version) { 2377 if ((ret = latm_decode_audio_specific_config(latmctx, gb, 0)) < 0) 2378 return ret; 2379 } else { 2380 int ascLen = latm_get_value(gb); 2381 if ((ret = latm_decode_audio_specific_config(latmctx, gb, ascLen)) < 0) 2382 return ret; 2383 ascLen -= ret; 2384 skip_bits_long(gb, ascLen); 2385 } 2386 2387 latmctx->frame_length_type = get_bits(gb, 3); 2388 switch (latmctx->frame_length_type) { 2389 case 0: 2390 skip_bits(gb, 8); // latmBufferFullness 2391 break; 2392 case 1: 2393 latmctx->frame_length = get_bits(gb, 9); 2394 break; 2395 case 3: 2396 case 4: 2397 case 5: 2398 skip_bits(gb, 6); // CELP frame length table index 2399 break; 2400 case 6: 2401 case 7: 2402 skip_bits(gb, 1); // HVXC frame length table index 2403 break; 2404 } 2405 2406 if (get_bits(gb, 1)) { // other data 2407 if (audio_mux_version) { 2408 latm_get_value(gb); // other_data_bits 2409 } else { 2410 int esc; 2411 do { 2412 esc = get_bits(gb, 1); 2413 skip_bits(gb, 8); 2414 } while (esc); 2415 } 2416 } 2417 2418 if (get_bits(gb, 1)) // crc present 2419 skip_bits(gb, 8); // config_crc 2420 } 2421 2422 return 0; 2423 } 2424 2425 static int read_payload_length_info(struct LATMContext *ctx, GetBitContext *gb) 2426 { 2427 uint8_t tmp; 2428 2429 if (ctx->frame_length_type == 0) { 2430 int mux_slot_length = 0; 2431 do { 2432 tmp = get_bits(gb, 8); 2433 mux_slot_length += tmp; 2434 } while (tmp == 255); 2435 return mux_slot_length; 2436 } else if (ctx->frame_length_type == 1) { 2437 return ctx->frame_length; 2438 } else if (ctx->frame_length_type == 3 || 2439 ctx->frame_length_type == 5 || 2440 ctx->frame_length_type == 7) { 2441 skip_bits(gb, 2); // mux_slot_length_coded 2442 } 2443 return 0; 2444 } 2445 2446 static int read_audio_mux_element(struct LATMContext *latmctx, 2447 GetBitContext *gb) 2448 { 2449 int err; 2450 uint8_t use_same_mux = get_bits(gb, 1); 2451 if (!use_same_mux) { 2452 if ((err = read_stream_mux_config(latmctx, gb)) < 0) 2453 return err; 2454 } else if (!latmctx->aac_ctx.avctx->extradata) { 2455 av_log(latmctx->aac_ctx.avctx, AV_LOG_DEBUG, 2456 "no decoder config found\n"); 2457 return AVERROR(EAGAIN); 2458 } 2459 if (latmctx->audio_mux_version_A == 0) { 2460 int mux_slot_length_bytes = read_payload_length_info(latmctx, gb); 2461 if (mux_slot_length_bytes * 8 > get_bits_left(gb)) { 2462 av_log(latmctx->aac_ctx.avctx, AV_LOG_ERROR, "incomplete frame\n"); 2463 return AVERROR_INVALIDDATA; 2464 } else if (mux_slot_length_bytes * 8 + 256 < get_bits_left(gb)) { 2465 av_log(latmctx->aac_ctx.avctx, AV_LOG_ERROR, 2466 "frame length mismatch %d << %d\n", 2467 mux_slot_length_bytes * 8, get_bits_left(gb)); 2468 return AVERROR_INVALIDDATA; 2469 } 2470 } 2471 return 0; 2472 } 2473 2474 2475 static int latm_decode_frame(AVCodecContext *avctx, void *out, int *out_size, 2476 AVPacket *avpkt) 2477 { 2478 struct LATMContext *latmctx = avctx->priv_data; 2479 int muxlength, err; 2480 GetBitContext gb; 2481 2482 if (avpkt->size == 0) 2483 return 0; 2484 2485 init_get_bits(&gb, avpkt->data, avpkt->size * 8); 2486 2487 // check for LOAS sync word 2488 if (get_bits(&gb, 11) != LOAS_SYNC_WORD) 2489 return AVERROR_INVALIDDATA; 2490 2491 muxlength = get_bits(&gb, 13) + 3; 2492 // not enough data, the parser should have sorted this 2493 if (muxlength > avpkt->size) 2494 return AVERROR_INVALIDDATA; 2495 2496 if ((err = read_audio_mux_element(latmctx, &gb)) < 0) 2497 return err; 2498 2499 if (!latmctx->initialized) { 2500 if (!avctx->extradata) { 2501 *out_size = 0; 2502 return avpkt->size; 2503 } else { 2504 aac_decode_close(avctx); 2505 if ((err = aac_decode_init(avctx)) < 0) 2506 return err; 2507 latmctx->initialized = 1; 2508 } 2509 } 2510 2511 if (show_bits(&gb, 12) == 0xfff) { 2512 av_log(latmctx->aac_ctx.avctx, AV_LOG_ERROR, 2513 "ADTS header detected, probably as result of configuration " 2514 "misparsing\n"); 2515 return AVERROR_INVALIDDATA; 2516 } 2517 2518 if ((err = aac_decode_frame_int(avctx, out, out_size, &gb)) < 0) 2519 return err; 2520 2521 return muxlength; 2522 } 2523 2524 av_cold static int latm_decode_init(AVCodecContext *avctx) 2525 { 2526 struct LATMContext *latmctx = avctx->priv_data; 2527 int ret; 2528 2529 ret = aac_decode_init(avctx); 2530 2531 if (avctx->extradata_size > 0) { 2532 latmctx->initialized = !ret; 2533 } else { 2534 latmctx->initialized = 0; 2535 } 2536 2537 return ret; 2538 } 2539 2540 2095 2541 AVCodec aac_decoder = { 2096 2542 "aac", 2097 2543 AVMEDIA_TYPE_AUDIO, … … AVCodec aac_decoder = { 2107 2553 }, 2108 2554 .channel_layouts = aac_channel_layout, 2109 2555 }; 2556 2557 /* 2558 Note: This decoder filter is intended to decode LATM streams transferred 2559 in MPEG transport streams which only contain one program. 2560 To do a more complex LATM demuxing a separate LATM demuxer should be used. 2561 */ 2562 AVCodec aac_latm_decoder = { 2563 .name = "aac_latm", 2564 .type = AVMEDIA_TYPE_AUDIO, 2565 .id = CODEC_ID_AAC_LATM, 2566 .priv_data_size = sizeof(struct LATMContext), 2567 .init = latm_decode_init, 2568 .close = aac_decode_close, 2569 .decode = latm_decode_frame, 2570 .long_name = NULL_IF_CONFIG_SMALL("AAC LATM (Advanced Audio Codec LATM syntax)"), 2571 .sample_fmts = (const enum SampleFormat[]) { 2572 SAMPLE_FMT_S16,SAMPLE_FMT_NONE 2573 }, 2574 .channel_layouts = aac_channel_layout, 2575 }; -
mythtv/external/FFmpeg/libavcodec/aacdectab.h
diff --git a/mythtv/external/FFmpeg/libavcodec/aacdectab.h b/mythtv/external/FFmpeg/libavcodec/aacdectab.h index b74f100..2759c29 100644
a b 34 34 35 35 #include <stdint.h> 36 36 37 /* @name ltp_coef 38 * Table of the LTP coefficient (multiplied by 2) 39 */ 40 static const float ltp_coef[8] = { 41 1.141658, 1.393232, 1.626008, 1.822608, 42 1.969800, 2.135788, 2.2389202, 2.739066, 43 }; 44 37 45 /* @name tns_tmp2_map 38 46 * Tables of the tmp2[] arrays of LPC coefficients used for TNS. 39 47 * The suffix _M_N[] indicate the values of coef_compress and coef_res -
mythtv/external/FFmpeg/libavcodec/aacsbr.c
diff --git a/mythtv/external/FFmpeg/libavcodec/aacsbr.c b/mythtv/external/FFmpeg/libavcodec/aacsbr.c index 050305a..ec7ad3c 100644
a b 32 32 #include "aacsbrdata.h" 33 33 #include "fft.h" 34 34 #include "aacps.h" 35 #include "libavutil/libm.h" 35 36 36 37 #include <stdint.h> 37 38 #include <float.h> 39 #include <math.h> 38 40 39 41 #define ENVELOPE_ADJUSTMENT_OFFSET 2 40 42 #define NOISE_FLOOR_OFFSET 6.0f … … av_cold void ff_aac_sbr_init(void) 127 129 128 130 av_cold void ff_aac_sbr_ctx_init(SpectralBandReplication *sbr) 129 131 { 132 if(sbr->mdct.mdct_bits) 133 return; 130 134 sbr->kx[0] = sbr->kx[1] = 32; //Typo in spec, kx' inits to 32 131 135 sbr->data[0].e_a[1] = sbr->data[1].e_a[1] = -1; 132 136 sbr->data[0].synthesis_filterbank_samples_offset = SBR_SYNTHESIS_BUF_SIZE - (1280 - 128); 133 137 sbr->data[1].synthesis_filterbank_samples_offset = SBR_SYNTHESIS_BUF_SIZE - (1280 - 128); 134 ff_mdct_init(&sbr->mdct, 7, 1, 1.0/64);138 ff_mdct_init(&sbr->mdct, 7, 1, 1.0 / 64.0); 135 139 ff_mdct_init(&sbr->mdct_ana, 7, 1, -2.0); 136 140 ff_ps_ctx_init(&sbr->ps); 137 141 } … … static void sbr_dequant(SpectralBandReplication *sbr, int id_aac) 1134 1138 * @param W array of complex-valued samples split into subbands 1135 1139 */ 1136 1140 static void sbr_qmf_analysis(DSPContext *dsp, FFTContext *mdct, const float *in, float *x, 1137 float z[320], float W[2][32][32][2], 1138 float scale) 1141 float z[320], float W[2][32][32][2]) 1139 1142 { 1140 1143 int i, k; 1141 1144 memcpy(W[0], W[1], sizeof(W[0])); 1142 1145 memcpy(x , x+1024, (320-32)*sizeof(x[0])); 1143 if (scale != 1.0f) 1144 dsp->vector_fmul_scalar(x+288, in, scale, 1024); 1145 else 1146 memcpy(x+288, in, 1024*sizeof(*x)); 1146 memcpy(x+288, in, 1024*sizeof(x[0])); 1147 1147 for (i = 0; i < 32; i++) { // numTimeSlots*RATE = 16*2 as 960 sample frames 1148 1148 // are not supported 1149 1149 dsp->vector_fmul_reverse(z, sbr_qmf_window_ds, x, 320); … … static void sbr_qmf_analysis(DSPContext *dsp, FFTContext *mdct, const float *in, 1159 1159 } 1160 1160 z[64+63] = z[32]; 1161 1161 1162 ff_imdct_half(mdct, z, z+64);1162 mdct->imdct_half(mdct, z, z+64); 1163 1163 for (k = 0; k < 32; k++) { 1164 1164 W[1][i][k][0] = -z[63-k]; 1165 1165 W[1][i][k][1] = z[k]; … … static void sbr_qmf_analysis(DSPContext *dsp, FFTContext *mdct, const float *in, 1175 1175 static void sbr_qmf_synthesis(DSPContext *dsp, FFTContext *mdct, 1176 1176 float *out, float X[2][38][64], 1177 1177 float mdct_buf[2][64], 1178 float *v0, int *v_off, const unsigned int div, 1179 float bias, float scale) 1178 float *v0, int *v_off, const unsigned int div) 1180 1179 { 1181 1180 int i, n; 1182 1181 const float *sbr_qmf_window = div ? sbr_qmf_window_ds : sbr_qmf_window_us; 1183 int scale_and_bias = scale != 1.0f || bias != 0.0f;1184 1182 float *v; 1185 1183 for (i = 0; i < 32; i++) { 1186 1184 if (*v_off == 0) { … … static void sbr_qmf_synthesis(DSPContext *dsp, FFTContext *mdct, 1196 1194 X[0][i][ n] = -X[0][i][n]; 1197 1195 X[0][i][32+n] = X[1][i][31-n]; 1198 1196 } 1199 ff_imdct_half(mdct, mdct_buf[0], X[0][i]);1197 mdct->imdct_half(mdct, mdct_buf[0], X[0][i]); 1200 1198 for (n = 0; n < 32; n++) { 1201 1199 v[ n] = mdct_buf[0][63 - 2*n]; 1202 1200 v[63 - n] = -mdct_buf[0][62 - 2*n]; … … static void sbr_qmf_synthesis(DSPContext *dsp, FFTContext *mdct, 1205 1203 for (n = 1; n < 64; n+=2) { 1206 1204 X[1][i][n] = -X[1][i][n]; 1207 1205 } 1208 ff_imdct_half(mdct, mdct_buf[0], X[0][i]);1209 ff_imdct_half(mdct, mdct_buf[1], X[1][i]);1206 mdct->imdct_half(mdct, mdct_buf[0], X[0][i]); 1207 mdct->imdct_half(mdct, mdct_buf[1], X[1][i]); 1210 1208 for (n = 0; n < 64; n++) { 1211 1209 v[ n] = -mdct_buf[0][63 - n] + mdct_buf[1][ n ]; 1212 1210 v[127 - n] = mdct_buf[0][63 - n] + mdct_buf[1][ n ]; … … static void sbr_qmf_synthesis(DSPContext *dsp, FFTContext *mdct, 1222 1220 dsp->vector_fmul_add(out, v + ( 960 >> div), sbr_qmf_window + (448 >> div), out , 64 >> div); 1223 1221 dsp->vector_fmul_add(out, v + (1024 >> div), sbr_qmf_window + (512 >> div), out , 64 >> div); 1224 1222 dsp->vector_fmul_add(out, v + (1216 >> div), sbr_qmf_window + (576 >> div), out , 64 >> div); 1225 if (scale_and_bias)1226 for (n = 0; n < 64 >> div; n++)1227 out[n] = out[n] * scale + bias;1228 1223 out += 64 >> div; 1229 1224 } 1230 1225 } … … static void sbr_mapping(AACContext *ac, SpectralBandReplication *sbr, 1459 1454 uint16_t *table = ch_data->bs_freq_res[e + 1] ? sbr->f_tablehigh : sbr->f_tablelow; 1460 1455 int k; 1461 1456 1457 //av_assert0(sbr->kx[1] <= table[0]); 1462 1458 for (i = 0; i < ilim; i++) 1463 1459 for (m = table[i]; m < table[i + 1]; m++) 1464 1460 sbr->e_origmapped[e][m - sbr->kx[1]] = ch_data->env_facs[e+1][i]; … … void ff_sbr_apply(AACContext *ac, SpectralBandReplication *sbr, int id_aac, 1727 1723 /* decode channel */ 1728 1724 sbr_qmf_analysis(&ac->dsp, &sbr->mdct_ana, ch ? R : L, sbr->data[ch].analysis_filterbank_samples, 1729 1725 (float*)sbr->qmf_filter_scratch, 1730 sbr->data[ch].W , 1/(-1024 * ac->sf_scale));1726 sbr->data[ch].W); 1731 1727 sbr_lf_gen(ac, sbr, sbr->X_low, sbr->data[ch].W); 1732 1728 if (sbr->start) { 1733 1729 sbr_hf_inverse_filter(sbr->alpha0, sbr->alpha1, sbr->X_low, sbr->k[0]); … … void ff_sbr_apply(AACContext *ac, SpectralBandReplication *sbr, int id_aac, 1760 1756 sbr_qmf_synthesis(&ac->dsp, &sbr->mdct, L, sbr->X[0], sbr->qmf_filter_scratch, 1761 1757 sbr->data[0].synthesis_filterbank_samples, 1762 1758 &sbr->data[0].synthesis_filterbank_samples_offset, 1763 downsampled, 1764 ac->add_bias, -1024 * ac->sf_scale); 1759 downsampled); 1765 1760 if (nch == 2) 1766 1761 sbr_qmf_synthesis(&ac->dsp, &sbr->mdct, R, sbr->X[1], sbr->qmf_filter_scratch, 1767 1762 sbr->data[1].synthesis_filterbank_samples, 1768 1763 &sbr->data[1].synthesis_filterbank_samples_offset, 1769 downsampled, 1770 ac->add_bias, -1024 * ac->sf_scale); 1764 downsampled); 1771 1765 }