summaryrefslogtreecommitdiff
Diffstat
-rw-r--r--Android.mk1
-rwxr-xr-xamadec/Android.mk282
-rw-r--r--amadec/acodec_lib_50/libstagefright_soft_dcvdec.so80
-rw-r--r--amadec/acodec_lib_50/libstagefright_soft_dtshd.so85
-rw-r--r--amadec/acodec_lib_50/libstagefright_soft_truehddec.so41
-rw-r--r--amadec/acodec_lib_android_n/libstagefright_soft_dcvdec.so109
-rw-r--r--amadec/acodec_lib_android_n/libstagefright_soft_dtshd.so272
-rw-r--r--amadec/acodec_lib_android_n/libstagefright_soft_truehddec.so87
-rwxr-xr-xamadec/acodec_lib_mx/libstagefright_soft_ddpdec.so113
-rwxr-xr-xamadec/acodec_lib_mx/libstagefright_soft_dtshd.so121
-rw-r--r--amadec/adec-armdec-mgt.h57
-rw-r--r--amadec/adec-external-ctrl.c899
-rw-r--r--amadec/adec-ffmpeg-mgt.c1550
-rw-r--r--amadec/adec-internal-mgt.c772
-rw-r--r--amadec/adec-message.c156
-rw-r--r--amadec/adec-message.h61
-rwxr-xr-xamadec/adec-pts-mgt.c1107
-rw-r--r--amadec/adec-pts-mgt.h82
-rw-r--r--amadec/adec-wfd-out.cpp361
-rw-r--r--amadec/adec-wfd.c811
-rw-r--r--amadec/adec_omx_brige.c284
-rw-r--r--amadec/adec_omx_brige.h56
-rw-r--r--amadec/adec_read.c200
-rw-r--r--amadec/adec_reg.h76
-rw-r--r--amadec/adec_write.c189
-rw-r--r--amadec/adec_write.h42
-rw-r--r--amadec/audio-dec.h314
-rw-r--r--amadec/audio_out/alsa-out.c1082
-rw-r--r--amadec/audio_out/aml_resample.c708
-rw-r--r--amadec/audio_out/aml_resample.h86
-rwxr-xr-xamadec/audio_out/android-out.cpp1640
-rw-r--r--amadec/audiodsp_update_format.c188
-rw-r--r--amadec/dsp/audiodsp-ctl.c471
-rw-r--r--amadec/dts_enc.c209
-rw-r--r--amadec/dts_enc.h11
-rw-r--r--amadec/dts_transenc_api.c143
-rw-r--r--amadec/dts_transenc_api.h19
-rw-r--r--amadec/feeder.c231
-rw-r--r--amadec/feeder.h26
-rw-r--r--amadec/include/adec-external-ctrl.h63
-rwxr-xr-xamadec/include/adec-macros.h41
-rw-r--r--amadec/include/adec-types.h53
-rwxr-xr-xamadec/include/alsa-out.h26
-rw-r--r--amadec/include/audio-out.h41
-rw-r--r--amadec/include/audiodsp.h142
-rw-r--r--amadec/include/audiodsp_update_format.h25
-rw-r--r--amadec/include/log-print.h26
-rwxr-xr-xamadec/omx_audio/ALAC_mediasource.cpp205
-rw-r--r--amadec/omx_audio/ALAC_mediasource.h62
-rwxr-xr-xamadec/omx_audio/ASF_mediasource.cpp184
-rw-r--r--amadec/omx_audio/ASF_mediasource.h127
-rwxr-xr-xamadec/omx_audio/Android.mk34
-rwxr-xr-xamadec/omx_audio/DDP_mediasource.cpp528
-rw-r--r--amadec/omx_audio/DDP_mediasource.h141
-rw-r--r--amadec/omx_audio/DTSHD_mediasource.cpp316
-rw-r--r--amadec/omx_audio/DTSHD_mediasource.h74
-rwxr-xr-xamadec/omx_audio/MP3_mediasource.cpp579
-rw-r--r--amadec/omx_audio/MP3_mediasource.h80
-rw-r--r--amadec/omx_audio/THD_mediasource.cpp229
-rw-r--r--amadec/omx_audio/THD_mediasource.h74
-rwxr-xr-xamadec/omx_audio/Vorbis_mediasource.cpp245
-rw-r--r--amadec/omx_audio/Vorbis_mediasource.h58
-rw-r--r--amadec/omx_audio/adec_omx.cpp421
-rw-r--r--amadec/omx_audio/adec_omx.h71
-rwxr-xr-xamadec/omx_audio/audio_mediasource.cpp37
-rw-r--r--amadec/omx_audio/audio_mediasource.h46
-rw-r--r--amadec/omx_audio/audio_medissource.h137
-rw-r--r--amadec/pcmenc_api.c147
-rw-r--r--amadec/pcmenc_api.h25
-rw-r--r--amadec/spdif_api.c306
-rw-r--r--amadec/spdif_api.h26
-rwxr-xr-xaudio_codec/Android.mk1
-rw-r--r--audio_codec/config.mk10
-rwxr-xr-xaudio_codec/libadpcm/Android.mk12
-rw-r--r--audio_codec/libadpcm/adpcm.h346
-rw-r--r--audio_codec/libadpcm/adpcm_decode.c841
-rwxr-xr-xaudio_codec/libamr/Android.mk25
-rwxr-xr-xaudio_codec/libamr/Makefile5
-rw-r--r--audio_codec/libamr/amr_decode.c186
-rw-r--r--audio_codec/libamr/amr_decode.h8
-rwxr-xr-xaudio_codec/libamr/dec.h18
-rw-r--r--audio_codec/libamr/dec_acelp.c620
-rwxr-xr-xaudio_codec/libamr/dec_acelp.h17
-rw-r--r--audio_codec/libamr/dec_dtx.c683
-rw-r--r--audio_codec/libamr/dec_dtx.h49
-rw-r--r--audio_codec/libamr/dec_gain.c853
-rw-r--r--audio_codec/libamr/dec_gain.h28
-rw-r--r--audio_codec/libamr/dec_if.c834
-rwxr-xr-xaudio_codec/libamr/dec_if.h23
-rw-r--r--audio_codec/libamr/dec_lpc.c789
-rw-r--r--audio_codec/libamr/dec_lpc.h25
-rw-r--r--audio_codec/libamr/dec_main.c842
-rw-r--r--audio_codec/libamr/dec_main.h57
-rw-r--r--audio_codec/libamr/dec_rom.c2114
-rw-r--r--audio_codec/libamr/dec_util.c1304
-rw-r--r--audio_codec/libamr/dec_util.h33
-rw-r--r--audio_codec/libamr/if_rom.c1030
-rwxr-xr-xaudio_codec/libamr/if_rom.h70
-rw-r--r--audio_codec/libamr/interf_dec.c906
-rw-r--r--audio_codec/libamr/interf_dec.h56
-rw-r--r--audio_codec/libamr/interf_rom.h1788
-rw-r--r--audio_codec/libamr/rom_dec.h13274
-rw-r--r--audio_codec/libamr/sp_dec.c6078
-rw-r--r--audio_codec/libamr/sp_dec.h83
-rwxr-xr-xaudio_codec/libamr/typedef.h17
-rwxr-xr-xaudio_codec/libape/Android.mk28
-rw-r--r--audio_codec/libape/Ape_decoder.h216
-rw-r--r--audio_codec/libape/amlogic_r30813_audio_ape_lib.c1
-rw-r--r--audio_codec/libape/apedec.c1120
-rw-r--r--audio_codec/libcook/Android.mk28
-rw-r--r--audio_codec/libcook/aac_bitstream.h133
-rw-r--r--audio_codec/libcook/aac_decode.h148
-rw-r--r--audio_codec/libcook/aac_reorder.h53
-rw-r--r--audio_codec/libcook/assembly.h119
-rw-r--r--audio_codec/libcook/challenge.h132
-rw-r--r--audio_codec/libcook/codec_defines.h93
-rw-r--r--audio_codec/libcook/coder.h287
-rw-r--r--audio_codec/libcook/cook_codec.h30
-rw-r--r--audio_codec/libcook/cook_decode.c624
-rw-r--r--audio_codec/libcook/cook_decode.h35
-rw-r--r--audio_codec/libcook/ga_config.h86
-rw-r--r--audio_codec/libcook/gecko2codec.c833
-rw-r--r--audio_codec/libcook/gecko2codec.h60
-rw-r--r--audio_codec/libcook/helix_config.h92
-rw-r--r--audio_codec/libcook/helix_mime_types.h56
-rw-r--r--audio_codec/libcook/helix_result.h107
-rw-r--r--audio_codec/libcook/helix_types.h305
-rw-r--r--audio_codec/libcook/helix_utils.h106
-rw-r--r--audio_codec/libcook/md5.h113
-rw-r--r--audio_codec/libcook/memory_utils.c100
-rw-r--r--audio_codec/libcook/memory_utils.h58
-rw-r--r--audio_codec/libcook/pack_utils.c306
-rw-r--r--audio_codec/libcook/pack_utils.h93
-rw-r--r--audio_codec/libcook/packet_defines.h48
-rw-r--r--audio_codec/libcook/ra8lbr_decode.c378
-rw-r--r--audio_codec/libcook/ra8lbr_decode.h161
-rw-r--r--audio_codec/libcook/ra_backend.h94
-rw-r--r--audio_codec/libcook/ra_bitpack.c197
-rw-r--r--audio_codec/libcook/ra_buffers.c127
-rw-r--r--audio_codec/libcook/ra_category.c298
-rw-r--r--audio_codec/libcook/ra_couple.c224
-rw-r--r--audio_codec/libcook/ra_decode.c321
-rw-r--r--audio_codec/libcook/ra_decode.h183
-rw-r--r--audio_codec/libcook/ra_depack.c230
-rw-r--r--audio_codec/libcook/ra_depack.h177
-rw-r--r--audio_codec/libcook/ra_depack_internal.c1710
-rw-r--r--audio_codec/libcook/ra_depack_internal.h232
-rw-r--r--audio_codec/libcook/ra_envelope.c123
-rw-r--r--audio_codec/libcook/ra_fft.c368
-rw-r--r--audio_codec/libcook/ra_format_info.h60
-rw-r--r--audio_codec/libcook/ra_gainctrl.c584
-rw-r--r--audio_codec/libcook/ra_huffman.c86
-rw-r--r--audio_codec/libcook/ra_hufftabs.c244
-rw-r--r--audio_codec/libcook/ra_mlt.c357
-rw-r--r--audio_codec/libcook/ra_sqvh.c431
-rw-r--r--audio_codec/libcook/ra_trigtabs.c932
-rw-r--r--audio_codec/libcook/rasl.c376
-rw-r--r--audio_codec/libcook/rasl.h71
-rw-r--r--audio_codec/libcook/rdtpck.h153
-rw-r--r--audio_codec/libcook/rm_error.h54
-rw-r--r--audio_codec/libcook/rm_error_default.c58
-rw-r--r--audio_codec/libcook/rm_error_default.h53
-rw-r--r--audio_codec/libcook/rm_io_default.c101
-rw-r--r--audio_codec/libcook/rm_io_default.h49
-rw-r--r--audio_codec/libcook/rm_memory.h54
-rw-r--r--audio_codec/libcook/rm_memory_default.c54
-rw-r--r--audio_codec/libcook/rm_memory_default.h46
-rw-r--r--audio_codec/libcook/rm_packet.c117
-rw-r--r--audio_codec/libcook/rm_packet.h80
-rw-r--r--audio_codec/libcook/rm_parse.h302
-rw-r--r--audio_codec/libcook/rm_parser.c649
-rw-r--r--audio_codec/libcook/rm_parser_internal.c3342
-rw-r--r--audio_codec/libcook/rm_parser_internal.h420
-rw-r--r--audio_codec/libcook/rm_property.c105
-rw-r--r--audio_codec/libcook/rm_property.h107
-rw-r--r--audio_codec/libcook/rm_stream.c356
-rw-r--r--audio_codec/libcook/rm_stream.h115
-rw-r--r--audio_codec/libcook/rm_stream_internal.h77
-rw-r--r--audio_codec/libcook/rv20backend.h69
-rw-r--r--audio_codec/libcook/rv30backend.h68
-rw-r--r--audio_codec/libcook/rv_backend.h84
-rw-r--r--audio_codec/libcook/rv_backend_types.h198
-rw-r--r--audio_codec/libcook/rv_decode.h208
-rw-r--r--audio_codec/libcook/rv_decode_message.h492
-rw-r--r--audio_codec/libcook/rv_depack.c271
-rw-r--r--audio_codec/libcook/rv_depack.h162
-rw-r--r--audio_codec/libcook/rv_depack_internal.c1071
-rw-r--r--audio_codec/libcook/rv_depack_internal.h171
-rw-r--r--audio_codec/libcook/rv_format_info.h91
-rw-r--r--audio_codec/libcook/statname.h118
-rw-r--r--audio_codec/libcook/stream_hdr_structs.h66
-rw-r--r--audio_codec/libcook/stream_hdr_utils.c136
-rw-r--r--audio_codec/libcook/stream_hdr_utils.h77
-rw-r--r--audio_codec/libcook/string_utils.c87
-rw-r--r--audio_codec/libcook/string_utils.h62
-rw-r--r--audio_codec/libcook/tngpkt.h400
-rwxr-xr-xaudio_codec/libfaad/Android.mk101
-rwxr-xr-xaudio_codec/libfaad/Makefile130
-rw-r--r--audio_codec/libfaad/analysis.h52
-rwxr-xr-xaudio_codec/libfaad/audio.d3
-rw-r--r--audio_codec/libfaad/bits.c261
-rwxr-xr-xaudio_codec/libfaad/bits.d18
-rw-r--r--audio_codec/libfaad/bits.h446
-rw-r--r--audio_codec/libfaad/cfft.c988
-rw-r--r--audio_codec/libfaad/cfft.h55
-rw-r--r--audio_codec/libfaad/cfft_tab.h1816
-rw-r--r--audio_codec/libfaad/codebook/hcb.h140
-rw-r--r--audio_codec/libfaad/codebook/hcb_1.h186
-rw-r--r--audio_codec/libfaad/codebook/hcb_10.h312
-rw-r--r--audio_codec/libfaad/codebook/hcb_11.h415
-rw-r--r--audio_codec/libfaad/codebook/hcb_2.h185
-rw-r--r--audio_codec/libfaad/codebook/hcb_3.h196
-rw-r--r--audio_codec/libfaad/codebook/hcb_4.h199
-rw-r--r--audio_codec/libfaad/codebook/hcb_5.h196
-rw-r--r--audio_codec/libfaad/codebook/hcb_6.h182
-rw-r--r--audio_codec/libfaad/codebook/hcb_7.h162
-rw-r--r--audio_codec/libfaad/codebook/hcb_8.h173
-rw-r--r--audio_codec/libfaad/codebook/hcb_9.h372
-rw-r--r--audio_codec/libfaad/codebook/hcb_sf.h276
-rw-r--r--audio_codec/libfaad/common.c558
-rw-r--r--audio_codec/libfaad/common.h453
-rw-r--r--audio_codec/libfaad/decoder.c2266
-rw-r--r--audio_codec/libfaad/drc.c173
-rw-r--r--audio_codec/libfaad/drc.h49
-rw-r--r--audio_codec/libfaad/drm_dec.c912
-rw-r--r--audio_codec/libfaad/drm_dec.h99
-rw-r--r--audio_codec/libfaad/error.c72
-rw-r--r--audio_codec/libfaad/error.h44
-rw-r--r--audio_codec/libfaad/filtbank.c408
-rw-r--r--audio_codec/libfaad/filtbank.h61
-rw-r--r--audio_codec/libfaad/fixed.h287
-rw-r--r--audio_codec/libfaad/hcr.c422
-rw-r--r--audio_codec/libfaad/helixaac/aaccommon.h210
-rw-r--r--audio_codec/libfaad/helixaac/aacdec.c508
-rw-r--r--audio_codec/libfaad/helixaac/aacdec.h206
-rw-r--r--audio_codec/libfaad/helixaac/aactabs.c157
-rw-r--r--audio_codec/libfaad/helixaac/assembly.h631
-rw-r--r--audio_codec/libfaad/helixaac/assembly_mw.h743
-rw-r--r--audio_codec/libfaad/helixaac/bitstream.c261
-rw-r--r--audio_codec/libfaad/helixaac/bitstream.h74
-rw-r--r--audio_codec/libfaad/helixaac/buffers.c140
-rw-r--r--audio_codec/libfaad/helixaac/coder.h369
-rw-r--r--audio_codec/libfaad/helixaac/dct4.c337
-rw-r--r--audio_codec/libfaad/helixaac/decelmnt.c445
-rw-r--r--audio_codec/libfaad/helixaac/dequant.c379
-rw-r--r--audio_codec/libfaad/helixaac/fft.c391
-rw-r--r--audio_codec/libfaad/helixaac/filefmt.c539
-rw-r--r--audio_codec/libfaad/helixaac/huffman_helix.c450
-rw-r--r--audio_codec/libfaad/helixaac/hufftabs.c177
-rw-r--r--audio_codec/libfaad/helixaac/imdct.c596
-rw-r--r--audio_codec/libfaad/helixaac/noiseless.c513
-rw-r--r--audio_codec/libfaad/helixaac/pns_helix.c371
-rw-r--r--audio_codec/libfaad/helixaac/sbr.c433
-rw-r--r--audio_codec/libfaad/helixaac/sbr.h380
-rw-r--r--audio_codec/libfaad/helixaac/sbrfft.c368
-rw-r--r--audio_codec/libfaad/helixaac/sbrfreq.c673
-rw-r--r--audio_codec/libfaad/helixaac/sbrhfadj.c882
-rw-r--r--audio_codec/libfaad/helixaac/sbrhfgen.c655
-rw-r--r--audio_codec/libfaad/helixaac/sbrhuff.c494
-rw-r--r--audio_codec/libfaad/helixaac/sbrimdct.c447
-rw-r--r--audio_codec/libfaad/helixaac/sbrmath.c198
-rw-r--r--audio_codec/libfaad/helixaac/sbrqmf.c648
-rw-r--r--audio_codec/libfaad/helixaac/sbrside.c634
-rw-r--r--audio_codec/libfaad/helixaac/sbrtabs.c400
-rw-r--r--audio_codec/libfaad/helixaac/statname.h115
-rw-r--r--audio_codec/libfaad/helixaac/stproc.c251
-rw-r--r--audio_codec/libfaad/helixaac/tns_helix.c307
-rw-r--r--audio_codec/libfaad/helixaac/trigtabs.c1000
-rw-r--r--audio_codec/libfaad/helixaac/trigtabs_fltgen.c357
-rw-r--r--audio_codec/libfaad/huffman.c582
-rw-r--r--audio_codec/libfaad/huffman.h47
-rw-r--r--audio_codec/libfaad/ic_predict.c258
-rw-r--r--audio_codec/libfaad/ic_predict.h252
-rw-r--r--audio_codec/libfaad/iq_table.h16456
-rw-r--r--audio_codec/libfaad/is.c106
-rw-r--r--audio_codec/libfaad/is.h67
-rw-r--r--audio_codec/libfaad/kbd_win.h2294
-rw-r--r--audio_codec/libfaad/libaacdec.c544
-rw-r--r--audio_codec/libfaad/libaacdec.h64
-rwxr-xr-xaudio_codec/libfaad/libfaad2.def14
-rw-r--r--audio_codec/libfaad/lt_predict.c205
-rw-r--r--audio_codec/libfaad/lt_predict.h66
-rw-r--r--audio_codec/libfaad/mdct.c307
-rw-r--r--audio_codec/libfaad/mdct.h48
-rw-r--r--audio_codec/libfaad/mdct_tab.h3639
-rw-r--r--audio_codec/libfaad/mp4.c307
-rw-r--r--audio_codec/libfaad/mp4.h52
-rw-r--r--audio_codec/libfaad/ms.c71
-rw-r--r--audio_codec/libfaad/ms.h44
-rw-r--r--audio_codec/libfaad/neaacdec.h257
-rw-r--r--audio_codec/libfaad/output.c583
-rw-r--r--audio_codec/libfaad/output.h48
-rw-r--r--audio_codec/libfaad/pns.c273
-rw-r--r--audio_codec/libfaad/pns.h58
-rw-r--r--audio_codec/libfaad/ps_dec.c1905
-rw-r--r--audio_codec/libfaad/ps_dec.h151
-rw-r--r--audio_codec/libfaad/ps_syntax.c532
-rw-r--r--audio_codec/libfaad/ps_tables.h547
-rw-r--r--audio_codec/libfaad/pulse.c59
-rw-r--r--audio_codec/libfaad/pulse.h43
-rw-r--r--audio_codec/libfaad/rvlc.c524
-rw-r--r--audio_codec/libfaad/rvlc.h55
-rw-r--r--audio_codec/libfaad/sbr_dct.c2267
-rw-r--r--audio_codec/libfaad/sbr_dct.h52
-rw-r--r--audio_codec/libfaad/sbr_dec.c679
-rw-r--r--audio_codec/libfaad/sbr_dec.h253
-rw-r--r--audio_codec/libfaad/sbr_e_nf.c475
-rw-r--r--audio_codec/libfaad/sbr_e_nf.h50
-rw-r--r--audio_codec/libfaad/sbr_fbt.c737
-rw-r--r--audio_codec/libfaad/sbr_fbt.h55
-rw-r--r--audio_codec/libfaad/sbr_hfadj.c1644
-rw-r--r--audio_codec/libfaad/sbr_hfadj.h56
-rw-r--r--audio_codec/libfaad/sbr_hfgen.c647
-rw-r--r--audio_codec/libfaad/sbr_hfgen.h49
-rw-r--r--audio_codec/libfaad/sbr_huff.c344
-rw-r--r--audio_codec/libfaad/sbr_huff.h46
-rw-r--r--audio_codec/libfaad/sbr_noise.h564
-rw-r--r--audio_codec/libfaad/sbr_qmf.c614
-rw-r--r--audio_codec/libfaad/sbr_qmf.h55
-rw-r--r--audio_codec/libfaad/sbr_qmf_c.h368
-rw-r--r--audio_codec/libfaad/sbr_syntax.c893
-rw-r--r--audio_codec/libfaad/sbr_syntax.h68
-rw-r--r--audio_codec/libfaad/sbr_tf_grid.c247
-rw-r--r--audio_codec/libfaad/sbr_tf_grid.h47
-rw-r--r--audio_codec/libfaad/sine_win.h4296
-rw-r--r--audio_codec/libfaad/specrec.c1249
-rw-r--r--audio_codec/libfaad/specrec.h49
-rw-r--r--audio_codec/libfaad/ssr.c170
-rw-r--r--audio_codec/libfaad/ssr.h59
-rw-r--r--audio_codec/libfaad/ssr_fb.c191
-rw-r--r--audio_codec/libfaad/ssr_fb.h53
-rw-r--r--audio_codec/libfaad/ssr_ipqf.c171
-rw-r--r--audio_codec/libfaad/ssr_ipqf.h46
-rw-r--r--audio_codec/libfaad/ssr_win.h635
-rw-r--r--audio_codec/libfaad/structs.h513
-rw-r--r--audio_codec/libfaad/syntax.c2539
-rw-r--r--audio_codec/libfaad/syntax.h129
-rw-r--r--audio_codec/libfaad/tns.c304
-rw-r--r--audio_codec/libfaad/tns.h51
-rwxr-xr-xaudio_codec/libflac/Android.mk22
-rw-r--r--audio_codec/libflac/avcodec.h337
-rw-r--r--audio_codec/libflac/bswap.h94
-rw-r--r--audio_codec/libflac/codec.h36
-rw-r--r--audio_codec/libflac/codec_message.h109
-rw-r--r--audio_codec/libflac/common.h356
-rw-r--r--audio_codec/libflac/crc.c146
-rw-r--r--audio_codec/libflac/crc.h46
-rw-r--r--audio_codec/libflac/flac.c43
-rw-r--r--audio_codec/libflac/flac.h124
-rw-r--r--audio_codec/libflac/flac_decode.c943
-rw-r--r--audio_codec/libflac/flacdata.c38
-rw-r--r--audio_codec/libflac/flacdata.h29
-rw-r--r--audio_codec/libflac/get_bits.h564
-rw-r--r--audio_codec/libflac/golomb.h585
-rw-r--r--audio_codec/libflac/internal.h195
-rw-r--r--audio_codec/libflac/intreadwrite.h390
-rw-r--r--audio_codec/libflac/mathops.h78
-rw-r--r--audio_codec/libflac/types.h49
-rwxr-xr-xaudio_codec/liblpcm/Android.mk13
-rw-r--r--audio_codec/liblpcm/lpcm_decode.c437
-rwxr-xr-xaudio_codec/libmad/Android.mk13
-rwxr-xr-xaudio_codec/libmad/D.dat607
-rw-r--r--audio_codec/libmad/bit.c244
-rw-r--r--audio_codec/libmad/bit.h47
-rw-r--r--audio_codec/libmad/config.h133
-rw-r--r--audio_codec/libmad/decoder.c1102
-rw-r--r--audio_codec/libmad/decoder.h91
-rw-r--r--audio_codec/libmad/fixed.c85
-rw-r--r--audio_codec/libmad/fixed.h499
-rw-r--r--audio_codec/libmad/frame.c525
-rw-r--r--audio_codec/libmad/frame.h118
-rw-r--r--audio_codec/libmad/global.h58
-rw-r--r--audio_codec/libmad/huffman.c3109
-rw-r--r--audio_codec/libmad/huffman.h66
-rwxr-xr-xaudio_codec/libmad/imdct_l_arm.S1000
-rwxr-xr-xaudio_codec/libmad/imdct_s.dat62
-rw-r--r--audio_codec/libmad/layer12.c552
-rwxr-xr-xaudio_codec/libmad/layer12.h31
-rw-r--r--audio_codec/libmad/layer3.c2742
-rwxr-xr-xaudio_codec/libmad/layer3.h30
-rw-r--r--audio_codec/libmad/mad.h966
-rwxr-xr-xaudio_codec/libmad/qc_table.dat77
-rwxr-xr-xaudio_codec/libmad/rq_table.dat8747
-rwxr-xr-xaudio_codec/libmad/sf_table.dat106
-rw-r--r--audio_codec/libmad/stream.c185
-rw-r--r--audio_codec/libmad/stream.h111
-rw-r--r--audio_codec/libmad/synth.c921
-rw-r--r--audio_codec/libmad/synth.h69
-rw-r--r--audio_codec/libmad/timer.c493
-rw-r--r--audio_codec/libmad/timer.h100
-rw-r--r--audio_codec/libmad/version.c91
-rw-r--r--audio_codec/libmad/version.h47
-rwxr-xr-xaudio_codec/libpcm/Android.mk11
-rw-r--r--audio_codec/libpcm/intreadwrite.h390
-rw-r--r--audio_codec/libpcm/pcm_decode.c780
-rw-r--r--audio_codec/libraac/Android.mk51
-rw-r--r--audio_codec/libraac/aac_bitstream.c200
-rw-r--r--audio_codec/libraac/aac_bitstream.h133
-rw-r--r--audio_codec/libraac/aac_decode.h148
-rw-r--r--audio_codec/libraac/aac_decode_main.c396
-rw-r--r--audio_codec/libraac/aac_reorder.c85
-rw-r--r--audio_codec/libraac/aac_reorder.h53
-rw-r--r--audio_codec/libraac/aaccommon.h200
-rw-r--r--audio_codec/libraac/aacdec.c607
-rw-r--r--audio_codec/libraac/aacdec.h200
-rw-r--r--audio_codec/libraac/aactabs.c157
-rw-r--r--audio_codec/libraac/assembly.h147
-rw-r--r--audio_codec/libraac/bitstream.c451
-rw-r--r--audio_codec/libraac/bitstream.h76
-rw-r--r--audio_codec/libraac/buffers.c132
-rw-r--r--audio_codec/libraac/coder.h370
-rw-r--r--audio_codec/libraac/dct4.c339
-rw-r--r--audio_codec/libraac/decelmnt.c451
-rw-r--r--audio_codec/libraac/dequant.c382
-rw-r--r--audio_codec/libraac/fft.c393
-rw-r--r--audio_codec/libraac/filefmt.c531
-rw-r--r--audio_codec/libraac/ga_config.c209
-rw-r--r--audio_codec/libraac/ga_config.h86
-rw-r--r--audio_codec/libraac/huffman.c449
-rw-r--r--audio_codec/libraac/hufftabs.c177
-rw-r--r--audio_codec/libraac/imdct.c598
-rw-r--r--audio_codec/libraac/include/challenge.h132
-rw-r--r--audio_codec/libraac/include/codec_defines.h93
-rw-r--r--audio_codec/libraac/include/gecko2codec.h60
-rw-r--r--audio_codec/libraac/include/helix_config.h92
-rw-r--r--audio_codec/libraac/include/helix_mime_types.h56
-rw-r--r--audio_codec/libraac/include/helix_result.h107
-rw-r--r--audio_codec/libraac/include/helix_types.h305
-rw-r--r--audio_codec/libraac/include/helix_utils.h106
-rw-r--r--audio_codec/libraac/include/md5.h113
-rw-r--r--audio_codec/libraac/include/memory_utils.h58
-rw-r--r--audio_codec/libraac/include/pack_utils.h93
-rw-r--r--audio_codec/libraac/include/packet_defines.h48
-rw-r--r--audio_codec/libraac/include/ra8lbr_decode.h161
-rw-r--r--audio_codec/libraac/include/ra_backend.h94
-rw-r--r--audio_codec/libraac/include/ra_decode.h183
-rw-r--r--audio_codec/libraac/include/ra_depack.h177
-rw-r--r--audio_codec/libraac/include/ra_format_info.h60
-rw-r--r--audio_codec/libraac/include/rasl.h71
-rw-r--r--audio_codec/libraac/include/rdtpck.h153
-rw-r--r--audio_codec/libraac/include/rm_error.h54
-rw-r--r--audio_codec/libraac/include/rm_error_default.h53
-rw-r--r--audio_codec/libraac/include/rm_io_default.h49
-rw-r--r--audio_codec/libraac/include/rm_memory.h54
-rw-r--r--audio_codec/libraac/include/rm_memory_default.h46
-rw-r--r--audio_codec/libraac/include/rm_packet.h80
-rw-r--r--audio_codec/libraac/include/rm_parse.h302
-rw-r--r--audio_codec/libraac/include/rm_property.h107
-rw-r--r--audio_codec/libraac/include/rm_stream.h115
-rw-r--r--audio_codec/libraac/include/rm_stream_internal.h77
-rw-r--r--audio_codec/libraac/include/rv20backend.h69
-rw-r--r--audio_codec/libraac/include/rv30backend.h68
-rw-r--r--audio_codec/libraac/include/rv_backend.h84
-rw-r--r--audio_codec/libraac/include/rv_backend_types.h198
-rw-r--r--audio_codec/libraac/include/rv_decode.h208
-rw-r--r--audio_codec/libraac/include/rv_decode_message.h492
-rw-r--r--audio_codec/libraac/include/rv_depack.h162
-rw-r--r--audio_codec/libraac/include/rv_format_info.h91
-rw-r--r--audio_codec/libraac/include/statname.h118
-rw-r--r--audio_codec/libraac/include/stream_hdr_structs.h66
-rw-r--r--audio_codec/libraac/include/stream_hdr_utils.h77
-rw-r--r--audio_codec/libraac/include/string_utils.h62
-rw-r--r--audio_codec/libraac/include/tngpkt.h400
-rw-r--r--audio_codec/libraac/memory_utils.c100
-rw-r--r--audio_codec/libraac/noiseless.c503
-rw-r--r--audio_codec/libraac/pack_utils.c306
-rw-r--r--audio_codec/libraac/pns.c369
-rw-r--r--audio_codec/libraac/ra_depack.c230
-rw-r--r--audio_codec/libraac/ra_depack_internal.c1713
-rw-r--r--audio_codec/libraac/ra_depack_internal.h232
-rw-r--r--audio_codec/libraac/raac_decode.c854
-rw-r--r--audio_codec/libraac/raac_decode.h37
-rw-r--r--audio_codec/libraac/rm_error_default.c60
-rw-r--r--audio_codec/libraac/rm_io_default.c101
-rw-r--r--audio_codec/libraac/rm_memory_default.c54
-rw-r--r--audio_codec/libraac/rm_packet.c117
-rw-r--r--audio_codec/libraac/rm_parser.c649
-rw-r--r--audio_codec/libraac/rm_parser_internal.c3342
-rw-r--r--audio_codec/libraac/rm_parser_internal.h420
-rw-r--r--audio_codec/libraac/rm_property.c105
-rw-r--r--audio_codec/libraac/rm_stream.c356
-rw-r--r--audio_codec/libraac/rv_depack.c271
-rw-r--r--audio_codec/libraac/rv_depack_internal.c1071
-rw-r--r--audio_codec/libraac/rv_depack_internal.h171
-rw-r--r--audio_codec/libraac/sbr.c431
-rw-r--r--audio_codec/libraac/sbr.h381
-rwxr-xr-xaudio_codec/libraac/sbrcov.s164
-rw-r--r--audio_codec/libraac/sbrfft.c368
-rw-r--r--audio_codec/libraac/sbrfreq.c667
-rw-r--r--audio_codec/libraac/sbrhfadj.c877
-rw-r--r--audio_codec/libraac/sbrhfgen.c646
-rw-r--r--audio_codec/libraac/sbrhuff.c492
-rw-r--r--audio_codec/libraac/sbrimdct.c447
-rw-r--r--audio_codec/libraac/sbrmath.c198
-rw-r--r--audio_codec/libraac/sbrqmf.c643
-rwxr-xr-xaudio_codec/libraac/sbrqmfak.s182
-rwxr-xr-xaudio_codec/libraac/sbrqmfsk.s130
-rw-r--r--audio_codec/libraac/sbrside.c615
-rw-r--r--audio_codec/libraac/sbrtabs.c400
-rw-r--r--audio_codec/libraac/statname.h115
-rw-r--r--audio_codec/libraac/stproc.c252
-rw-r--r--audio_codec/libraac/stream_hdr_utils.c136
-rw-r--r--audio_codec/libraac/string_utils.c87
-rw-r--r--audio_codec/libraac/tns.c307
-rw-r--r--audio_codec/libraac/trigtabs.c1000
-rw-r--r--audio_codec/libraac/trigtabs_fltgen.c357
-rwxr-xr-xaudio_codec/wfd_aac_decoder/Android.mk23
-rw-r--r--audio_codec/wfd_aac_decoder/aaccommon.h210
-rw-r--r--audio_codec/wfd_aac_decoder/aacdec.c508
-rw-r--r--audio_codec/wfd_aac_decoder/aacdec.h206
-rw-r--r--audio_codec/wfd_aac_decoder/aactabs.c157
-rw-r--r--audio_codec/wfd_aac_decoder/assembly.h640
-rw-r--r--audio_codec/wfd_aac_decoder/assembly_mw.h743
-rw-r--r--audio_codec/wfd_aac_decoder/bitstream.c261
-rw-r--r--audio_codec/wfd_aac_decoder/bitstream.h74
-rw-r--r--audio_codec/wfd_aac_decoder/buffers.c140
-rw-r--r--audio_codec/wfd_aac_decoder/coder.h369
-rw-r--r--audio_codec/wfd_aac_decoder/dct4.c337
-rw-r--r--audio_codec/wfd_aac_decoder/decelmnt.c445
-rw-r--r--audio_codec/wfd_aac_decoder/dequant.c379
-rw-r--r--audio_codec/wfd_aac_decoder/fft.c391
-rw-r--r--audio_codec/wfd_aac_decoder/filefmt.c539
-rw-r--r--audio_codec/wfd_aac_decoder/helix_aac_decode.c548
-rw-r--r--audio_codec/wfd_aac_decoder/huffman.c450
-rw-r--r--audio_codec/wfd_aac_decoder/hufftabs.c177
-rw-r--r--audio_codec/wfd_aac_decoder/imdct.c596
-rw-r--r--audio_codec/wfd_aac_decoder/noiseless.c513
-rw-r--r--audio_codec/wfd_aac_decoder/pns.c371
-rw-r--r--audio_codec/wfd_aac_decoder/sbr.c434
-rw-r--r--audio_codec/wfd_aac_decoder/sbr.h380
-rw-r--r--audio_codec/wfd_aac_decoder/sbrfft.c368
-rw-r--r--audio_codec/wfd_aac_decoder/sbrfreq.c673
-rw-r--r--audio_codec/wfd_aac_decoder/sbrhfadj.c882
-rw-r--r--audio_codec/wfd_aac_decoder/sbrhfgen.c655
-rw-r--r--audio_codec/wfd_aac_decoder/sbrhuff.c494
-rw-r--r--audio_codec/wfd_aac_decoder/sbrimdct.c447
-rw-r--r--audio_codec/wfd_aac_decoder/sbrmath.c198
-rw-r--r--audio_codec/wfd_aac_decoder/sbrqmf.c648
-rw-r--r--audio_codec/wfd_aac_decoder/sbrside.c634
-rw-r--r--audio_codec/wfd_aac_decoder/sbrtabs.c400
-rw-r--r--audio_codec/wfd_aac_decoder/statname.h115
-rw-r--r--audio_codec/wfd_aac_decoder/stproc.c251
-rw-r--r--audio_codec/wfd_aac_decoder/tns.c307
-rw-r--r--audio_codec/wfd_aac_decoder/trigtabs.c1000
-rw-r--r--audio_codec/wfd_aac_decoder/trigtabs_fltgen.c357
545 files changed, 230976 insertions, 0 deletions
diff --git a/audio_codec/libfaad/helixaac/sbrhfadj.c b/audio_codec/libfaad/helixaac/sbrhfadj.c
new file mode 100644
index 0000000..d0a85ac
--- a/dev/null
+++ b/audio_codec/libfaad/helixaac/sbrhfadj.c
@@ -0,0 +1,882 @@
+/* ***** BEGIN LICENSE BLOCK *****
+ * Source last modified: $Id: sbrhfadj.c,v 1.1.2.3 2005/05/24 20:34:40 albertofloyd Exp $
+ *
+ * Portions Copyright (c) 1995-2005 RealNetworks, Inc. All Rights Reserved.
+ *
+ * The contents of this file, and the files included with this file,
+ * are subject to the current version of the RealNetworks Public
+ * Source License (the "RPSL") available at
+ * http://www.helixcommunity.org/content/rpsl unless you have licensed
+ * the file under the current version of the RealNetworks Community
+ * Source License (the "RCSL") available at
+ * http://www.helixcommunity.org/content/rcsl, in which case the RCSL
+ * will apply. You may also obtain the license terms directly from
+ * RealNetworks. You may not use this file except in compliance with
+ * the RPSL or, if you have a valid RCSL with RealNetworks applicable
+ * to this file, the RCSL. Please see the applicable RPSL or RCSL for
+ * the rights, obligations and limitations governing use of the
+ * contents of the file.
+ *
+ * This file is part of the Helix DNA Technology. RealNetworks is the
+ * developer of the Original Code and owns the copyrights in the
+ * portions it created.
+ *
+ * This file, and the files included with this file, is distributed
+ * and made available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY
+ * KIND, EITHER EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS
+ * ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET
+ * ENJOYMENT OR NON-INFRINGEMENT.
+ *
+ * Technology Compatibility Kit Test Suite(s) Location:
+ * http://www.helixcommunity.org/content/tck
+ *
+ * Contributor(s):
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+/**************************************************************************************
+ * Fixed-point HE-AAC decoder
+ * Jon Recker (jrecker@real.com)
+ * February 2005
+ *
+ * sbrhfadj.c - high frequency adjustment for SBR
+ **************************************************************************************/
+
+#include "sbr.h"
+#include "assembly.h"
+
+/* invBandTab[i] = 1.0 / (i + 1), Q31 */
+static const int invBandTab[64] = {
+ 0x7fffffff, 0x40000000, 0x2aaaaaab, 0x20000000, 0x1999999a, 0x15555555, 0x12492492, 0x10000000,
+ 0x0e38e38e, 0x0ccccccd, 0x0ba2e8ba, 0x0aaaaaab, 0x09d89d8a, 0x09249249, 0x08888889, 0x08000000,
+ 0x07878788, 0x071c71c7, 0x06bca1af, 0x06666666, 0x06186186, 0x05d1745d, 0x0590b216, 0x05555555,
+ 0x051eb852, 0x04ec4ec5, 0x04bda12f, 0x04924925, 0x0469ee58, 0x04444444, 0x04210842, 0x04000000,
+ 0x03e0f83e, 0x03c3c3c4, 0x03a83a84, 0x038e38e4, 0x03759f23, 0x035e50d8, 0x03483483, 0x03333333,
+ 0x031f3832, 0x030c30c3, 0x02fa0be8, 0x02e8ba2f, 0x02d82d83, 0x02c8590b, 0x02b93105, 0x02aaaaab,
+ 0x029cbc15, 0x028f5c29, 0x02828283, 0x02762762, 0x026a439f, 0x025ed098, 0x0253c825, 0x02492492,
+ 0x023ee090, 0x0234f72c, 0x022b63cc, 0x02222222, 0x02192e2a, 0x02108421, 0x02082082, 0x02000000,
+};
+
+/**************************************************************************************
+ * Function: EstimateEnvelope
+ *
+ * Description: estimate power of generated HF QMF bands in one time-domain envelope
+ * (4.6.18.7.3)
+ *
+ * Inputs: initialized PSInfoSBR struct
+ * initialized SBRHeader struct for this SCE/CPE block
+ * initialized SBRGrid struct for this channel
+ * initialized SBRFreq struct for this SCE/CPE block
+ * index of current envelope
+ *
+ * Outputs: power of each QMF subband, stored as integer (Q0) * 2^N, N >= 0
+ *
+ * Return: none
+ **************************************************************************************/
+static void EstimateEnvelope(PSInfoSBR *psi, SBRHeader *sbrHdr, SBRGrid *sbrGrid, SBRFreq *sbrFreq, int env)
+{
+ int i, m, iStart, iEnd, xre, xim, nScale, expMax;
+ int p, n, mStart, mEnd, invFact, t;
+ int *XBuf;
+ U64 eCurr;
+ unsigned char *freqBandTab;
+
+ /* estimate current envelope */
+ iStart = sbrGrid->envTimeBorder[env] + HF_ADJ;
+ iEnd = sbrGrid->envTimeBorder[env + 1] + HF_ADJ;
+ if (sbrGrid->freqRes[env]) {
+ n = sbrFreq->nHigh;
+ freqBandTab = sbrFreq->freqHigh;
+ } else {
+ n = sbrFreq->nLow;
+ freqBandTab = sbrFreq->freqLow;
+ }
+
+ /* ADS should inline MADD64 (smlal) properly, but check to make sure */
+ expMax = 0;
+ if (sbrHdr->interpFreq) {
+ for (m = 0; m < sbrFreq->numQMFBands; m++) {
+ eCurr.w64 = 0;
+ XBuf = psi->XBuf[iStart][sbrFreq->kStart + m];
+ for (i = iStart; i < iEnd; i++) {
+ /* scale to int before calculating power (precision not critical, and avoids overflow) */
+ xre = (*XBuf) >> FBITS_OUT_QMFA;
+ XBuf += 1;
+ xim = (*XBuf) >> FBITS_OUT_QMFA;
+ XBuf += (2 * 64 - 1);
+ eCurr.w64 = MADD64(eCurr.w64, xre, xre);
+ eCurr.w64 = MADD64(eCurr.w64, xim, xim);
+ }
+
+ /* eCurr.w64 is now Q(64 - 2*FBITS_OUT_QMFA) (64-bit word)
+ * if energy is too big to fit in 32-bit word (> 2^31) scale down by power of 2
+ */
+ nScale = 0;
+ if (eCurr.r.hi32) {
+ nScale = (32 - CLZ(eCurr.r.hi32)) + 1;
+ t = (int)(eCurr.r.lo32 >> nScale); /* logical (unsigned) >> */
+ t |= eCurr.r.hi32 << (32 - nScale);
+ } else if (eCurr.r.lo32 >> 31) {
+ nScale = 1;
+ t = (int)(eCurr.r.lo32 >> nScale); /* logical (unsigned) >> */
+ } else {
+ t = (int)eCurr.r.lo32;
+ }
+
+ invFact = invBandTab[(iEnd - iStart) - 1];
+ psi->eCurr[m] = MULSHIFT32(t, invFact);
+ psi->eCurrExp[m] = nScale + 1; /* +1 for invFact = Q31 */
+ if (psi->eCurrExp[m] > expMax) {
+ expMax = psi->eCurrExp[m];
+ }
+ }
+ } else {
+ for (p = 0; p < n; p++) {
+ mStart = freqBandTab[p];
+ mEnd = freqBandTab[p + 1];
+ eCurr.w64 = 0;
+ for (i = iStart; i < iEnd; i++) {
+ XBuf = psi->XBuf[i][mStart];
+ for (m = mStart; m < mEnd; m++) {
+ xre = (*XBuf++) >> FBITS_OUT_QMFA;
+ xim = (*XBuf++) >> FBITS_OUT_QMFA;
+ eCurr.w64 = MADD64(eCurr.w64, xre, xre);
+ eCurr.w64 = MADD64(eCurr.w64, xim, xim);
+ }
+ }
+
+ nScale = 0;
+ if (eCurr.r.hi32) {
+ nScale = (32 - CLZ(eCurr.r.hi32)) + 1;
+ t = (int)(eCurr.r.lo32 >> nScale); /* logical (unsigned) >> */
+ t |= eCurr.r.hi32 << (32 - nScale);
+ } else if (eCurr.r.lo32 >> 31) {
+ nScale = 1;
+ t = (int)(eCurr.r.lo32 >> nScale); /* logical (unsigned) >> */
+ } else {
+ t = (int)eCurr.r.lo32;
+ }
+
+ invFact = invBandTab[(iEnd - iStart) - 1];
+ invFact = MULSHIFT32(invBandTab[(mEnd - mStart) - 1], invFact) << 1;
+ t = MULSHIFT32(t, invFact);
+
+ for (m = mStart; m < mEnd; m++) {
+ psi->eCurr[m - sbrFreq->kStart] = t;
+ psi->eCurrExp[m - sbrFreq->kStart] = nScale + 1; /* +1 for invFact = Q31 */
+ }
+ if (psi->eCurrExp[mStart - sbrFreq->kStart] > expMax) {
+ expMax = psi->eCurrExp[mStart - sbrFreq->kStart];
+ }
+ }
+ }
+ psi->eCurrExpMax = expMax;
+}
+
+/**************************************************************************************
+ * Function: GetSMapped
+ *
+ * Description: calculate SMapped (4.6.18.7.2)
+ *
+ * Inputs: initialized PSInfoSBR struct
+ * initialized SBRGrid struct for this channel
+ * initialized SBRFreq struct for this SCE/CPE block
+ * initialized SBRChan struct for this channel
+ * index of current envelope
+ * index of current QMF band
+ * la flag for this envelope
+ *
+ * Outputs: none
+ *
+ * Return: 1 if a sinusoid is present in this band, 0 if not
+ **************************************************************************************/
+static int GetSMapped(SBRGrid *sbrGrid, SBRFreq *sbrFreq, SBRChan *sbrChan, int env, int band, int la)
+{
+ int bandStart, bandEnd, oddFlag, r;
+
+ if (sbrGrid->freqRes[env]) {
+ /* high resolution */
+ bandStart = band;
+ bandEnd = band + 1;
+ } else {
+ /* low resolution (see CalcFreqLow() for mapping) */
+ oddFlag = sbrFreq->nHigh & 0x01;
+ bandStart = (band > 0 ? 2 * band - oddFlag : 0); /* starting index for freqLow[band] */
+ bandEnd = 2 * (band + 1) - oddFlag; /* ending index for freqLow[band+1] */
+ }
+
+ /* sMapped = 1 if sIndexMapped == 1 for any frequency in this band */
+ for (band = bandStart; band < bandEnd; band++) {
+ if (sbrChan->addHarmonic[1][band]) {
+ r = ((sbrFreq->freqHigh[band + 1] + sbrFreq->freqHigh[band]) >> 1);
+ if (env >= la || sbrChan->addHarmonic[0][r] == 1) {
+ return 1;
+ }
+ }
+ }
+ return 0;
+}
+
+#define GBOOST_MAX 0x2830afd3 /* Q28, 1.584893192 squared */
+#define ACC_SCALE 6
+
+/* squared version of table in 4.6.18.7.5 */
+static const int limGainTab[4] = {0x20138ca7, 0x40000000, 0x7fb27dce, 0x80000000}; /* Q30 (0x80000000 = sentinel for GMAX) */
+
+/**************************************************************************************
+ * Function: CalcMaxGain
+ *
+ * Description: calculate max gain in one limiter band (4.6.18.7.5)
+ *
+ * Inputs: initialized PSInfoSBR struct
+ * initialized SBRHeader struct for this SCE/CPE block
+ * initialized SBRGrid struct for this channel
+ * initialized SBRFreq struct for this SCE/CPE block
+ * index of current channel (0 for SCE, 0 or 1 for CPE)
+ * index of current envelope
+ * index of current limiter band
+ * number of fraction bits in dequantized envelope
+ * (max = Q(FBITS_OUT_DQ_ENV - 6) = Q23, can go negative)
+ *
+ * Outputs: updated gainMax, gainMaxFBits, and sumEOrigMapped in PSInfoSBR struct
+ *
+ * Return: none
+ **************************************************************************************/
+static void CalcMaxGain(PSInfoSBR *psi, SBRHeader *sbrHdr, SBRGrid *sbrGrid, SBRFreq *sbrFreq, int ch, int env, int lim, int fbitsDQ)
+{
+ int m, mStart, mEnd, q, z, r;
+ int sumEOrigMapped, sumECurr, gainMax, eOMGainMax, envBand;
+ unsigned char eCurrExpMax;
+ unsigned char *freqBandTab;
+
+ mStart = sbrFreq->freqLimiter[lim]; /* these are offsets from kStart */
+ mEnd = sbrFreq->freqLimiter[lim + 1];
+ freqBandTab = (sbrGrid->freqRes[env] ? sbrFreq->freqHigh : sbrFreq->freqLow);
+
+ /* calculate max gain to apply to signal in this limiter band */
+ sumECurr = 0;
+ sumEOrigMapped = 0;
+ eCurrExpMax = psi->eCurrExpMax;
+ eOMGainMax = psi->eOMGainMax;
+ envBand = psi->envBand;
+ for (m = mStart; m < mEnd; m++) {
+ /* map current QMF band to appropriate envelope band */
+ if (m == freqBandTab[envBand + 1] - sbrFreq->kStart) {
+ envBand++;
+ eOMGainMax = psi->envDataDequant[ch][env][envBand] >> ACC_SCALE; /* summing max 48 bands */
+ }
+ sumEOrigMapped += eOMGainMax;
+
+ /* easy test for overflow on ARM */
+ sumECurr += (psi->eCurr[m] >> (eCurrExpMax - psi->eCurrExp[m]));
+ if (sumECurr >> 30) {
+ sumECurr >>= 1;
+ eCurrExpMax++;
+ }
+ }
+ psi->eOMGainMax = eOMGainMax;
+ psi->envBand = envBand;
+
+ psi->gainMaxFBits = 30; /* Q30 tables */
+ if (sumECurr == 0) {
+ /* any non-zero numerator * 1/EPS_0 is > G_MAX */
+ gainMax = (sumEOrigMapped == 0 ? limGainTab[sbrHdr->limiterGains] : 0x80000000);
+ } else if (sumEOrigMapped == 0) {
+ /* 1/(any non-zero denominator) * EPS_0 * limGainTab[x] is appx. 0 */
+ gainMax = 0;
+ } else {
+ /* sumEOrigMapped = Q(fbitsDQ - ACC_SCALE), sumECurr = Q(-eCurrExpMax) */
+ gainMax = limGainTab[sbrHdr->limiterGains];
+ if (sbrHdr->limiterGains != 3) {
+ q = MULSHIFT32(sumEOrigMapped, gainMax); /* Q(fbitsDQ - ACC_SCALE - 2), gainMax = Q30 */
+ z = CLZ(sumECurr) - 1;
+ r = InvRNormalized(sumECurr << z); /* in = Q(z - eCurrExpMax), out = Q(29 + 31 - z + eCurrExpMax) */
+ gainMax = MULSHIFT32(q, r); /* Q(29 + 31 - z + eCurrExpMax + fbitsDQ - ACC_SCALE - 2 - 32) */
+ psi->gainMaxFBits = 26 - z + eCurrExpMax + fbitsDQ - ACC_SCALE;
+ }
+ }
+ psi->sumEOrigMapped = sumEOrigMapped;
+ psi->gainMax = gainMax;
+}
+
+/**************************************************************************************
+ * Function: CalcNoiseDivFactors
+ *
+ * Description: calculate 1/(1+Q) and Q/(1+Q) (4.6.18.7.4; 4.6.18.7.5)
+ *
+ * Inputs: dequantized noise floor scalefactor
+ *
+ * Outputs: 1/(1+Q) and Q/(1+Q), format = Q31
+ *
+ * Return: none
+ **************************************************************************************/
+static void CalcNoiseDivFactors(int q, int *qp1Inv, int *qqp1Inv)
+{
+ int z, qp1, t, s;
+
+ /* 1 + Q_orig */
+ qp1 = (q >> 1);
+ qp1 += (1 << (FBITS_OUT_DQ_NOISE - 1)); /* >> 1 to avoid overflow when adding 1.0 */
+ z = CLZ(qp1) - 1; /* z <= 31 - FBITS_OUT_DQ_NOISE */
+ qp1 <<= z; /* Q(FBITS_OUT_DQ_NOISE + z) = Q31 * 2^-(31 - (FBITS_OUT_DQ_NOISE + z)) */
+ t = InvRNormalized(qp1) << 1; /* Q30 * 2^(31 - (FBITS_OUT_DQ_NOISE + z)), guaranteed not to overflow */
+
+ /* normalize to Q31 */
+ s = (31 - (FBITS_OUT_DQ_NOISE - 1) - z - 1); /* clearly z >= 0, z <= (30 - (FBITS_OUT_DQ_NOISE - 1)) */
+ *qp1Inv = (t >> s); /* s = [0, 31 - FBITS_OUT_DQ_NOISE] */
+ *qqp1Inv = MULSHIFT32(t, q) << (32 - FBITS_OUT_DQ_NOISE - s);
+}
+
+/**************************************************************************************
+ * Function: CalcComponentGains
+ *
+ * Description: calculate gain of envelope, sinusoids, and noise in one limiter band
+ * (4.6.18.7.5)
+ *
+ * Inputs: initialized PSInfoSBR struct
+ * initialized SBRHeader struct for this SCE/CPE block
+ * initialized SBRGrid struct for this channel
+ * initialized SBRFreq struct for this SCE/CPE block
+ * initialized SBRChan struct for this channel
+ * index of current channel (0 for SCE, 0 or 1 for CPE)
+ * index of current envelope
+ * index of current limiter band
+ * number of fraction bits in dequantized envelope
+ *
+ * Outputs: gains for envelope, sinusoids and noise
+ * number of fraction bits for envelope gain
+ * sum of the total gain for each component in this band
+ * other updated state variables
+ *
+ * Return: none
+ **************************************************************************************/
+static void CalcComponentGains(PSInfoSBR *psi, SBRGrid *sbrGrid, SBRFreq *sbrFreq, SBRChan *sbrChan, int ch, int env, int lim, int fbitsDQ)
+{
+ int d, m, mStart, mEnd, q, qm, noiseFloor, sIndexMapped;
+ int shift, eCurr, maxFlag, gainMax, gainMaxFBits;
+ int gain, sm, z, r, fbitsGain, gainScale;
+ unsigned char *freqBandTab;
+
+ mStart = sbrFreq->freqLimiter[lim]; /* these are offsets from kStart */
+ mEnd = sbrFreq->freqLimiter[lim + 1];
+
+ gainMax = psi->gainMax;
+ gainMaxFBits = psi->gainMaxFBits;
+
+ d = (env == psi->la || env == sbrChan->laPrev ? 0 : 1);
+ freqBandTab = (sbrGrid->freqRes[env] ? sbrFreq->freqHigh : sbrFreq->freqLow);
+
+ /* figure out which noise floor this envelope is in (only 1 or 2 noise floors allowed) */
+ noiseFloor = 0;
+ if (sbrGrid->numNoiseFloors == 2 && sbrGrid->noiseTimeBorder[1] <= sbrGrid->envTimeBorder[env]) {
+ noiseFloor++;
+ }
+
+ psi->sumECurrGLim = 0;
+ psi->sumSM = 0;
+ psi->sumQM = 0;
+ /* calculate energy of noise to add in this limiter band */
+ for (m = mStart; m < mEnd; m++) {
+ if (m == sbrFreq->freqNoise[psi->noiseFloorBand + 1] - sbrFreq->kStart) {
+ /* map current QMF band to appropriate noise floor band (NOTE: freqLimiter[0] == freqLow[0] = freqHigh[0]) */
+ psi->noiseFloorBand++;
+ CalcNoiseDivFactors(psi->noiseDataDequant[ch][noiseFloor][psi->noiseFloorBand], &(psi->qp1Inv), &(psi->qqp1Inv));
+ }
+ if (m == sbrFreq->freqHigh[psi->highBand + 1] - sbrFreq->kStart) {
+ psi->highBand++;
+ }
+ if (m == freqBandTab[psi->sBand + 1] - sbrFreq->kStart) {
+ psi->sBand++;
+ psi->sMapped = GetSMapped(sbrGrid, sbrFreq, sbrChan, env, psi->sBand, psi->la);
+ }
+
+ /* get sIndexMapped for this QMF subband */
+ sIndexMapped = 0;
+ r = ((sbrFreq->freqHigh[psi->highBand + 1] + sbrFreq->freqHigh[psi->highBand]) >> 1);
+ if (m + sbrFreq->kStart == r) {
+ /* r = center frequency, deltaStep = (env >= la || sIndexMapped'(r, numEnv'-1) == 1) */
+ if (env >= psi->la || sbrChan->addHarmonic[0][r] == 1) {
+ sIndexMapped = sbrChan->addHarmonic[1][psi->highBand];
+ }
+ }
+
+ /* save sine flags from last envelope in this frame:
+ * addHarmonic[0][0...63] = saved sine present flag from previous frame, for each QMF subband
+ * addHarmonic[1][0...nHigh-1] = addHarmonic bit from current frame, for each high-res frequency band
+ * from MPEG reference code - slightly different from spec
+ * (sIndexMapped'(m,LE'-1) can still be 0 when numEnv == psi->la)
+ */
+ if (env == sbrGrid->numEnv - 1) {
+ if (m + sbrFreq->kStart == r) {
+ sbrChan->addHarmonic[0][m + sbrFreq->kStart] = sbrChan->addHarmonic[1][psi->highBand];
+ } else {
+ sbrChan->addHarmonic[0][m + sbrFreq->kStart] = 0;
+ }
+ }
+
+ gain = psi->envDataDequant[ch][env][psi->sBand];
+ qm = MULSHIFT32(gain, psi->qqp1Inv) << 1;
+ sm = (sIndexMapped ? MULSHIFT32(gain, psi->qp1Inv) << 1 : 0);
+
+ /* three cases: (sMapped == 0 && delta == 1), (sMapped == 0 && delta == 0), (sMapped == 1) */
+ if (d == 1 && psi->sMapped == 0) {
+ gain = MULSHIFT32(psi->qp1Inv, gain) << 1;
+ } else if (psi->sMapped != 0) {
+ gain = MULSHIFT32(psi->qqp1Inv, gain) << 1;
+ }
+
+ /* gain, qm, sm = Q(fbitsDQ), gainMax = Q(fbitsGainMax) */
+ eCurr = psi->eCurr[m];
+ if (eCurr) {
+ z = CLZ(eCurr) - 1;
+ r = InvRNormalized(eCurr << z); /* in = Q(z - eCurrExp), out = Q(29 + 31 - z + eCurrExp) */
+ gainScale = MULSHIFT32(gain, r); /* out = Q(29 + 31 - z + eCurrExp + fbitsDQ - 32) */
+ fbitsGain = 29 + 31 - z + psi->eCurrExp[m] + fbitsDQ - 32;
+ } else {
+ /* if eCurr == 0, then gain is unchanged (divide by EPS = 1) */
+ gainScale = gain;
+ fbitsGain = fbitsDQ;
+ }
+
+ /* see if gain for this band exceeds max gain */
+ maxFlag = 0;
+ if (gainMax != (int)0x80000000) {
+ if (fbitsGain >= gainMaxFBits) {
+ shift = MIN(fbitsGain - gainMaxFBits, 31);
+ maxFlag = ((gainScale >> shift) > gainMax ? 1 : 0);
+ } else {
+ shift = MIN(gainMaxFBits - fbitsGain, 31);
+ maxFlag = (gainScale > (gainMax >> shift) ? 1 : 0);
+ }
+ }
+
+ if (maxFlag) {
+ /* gainScale > gainMax, calculate ratio with 32/16 division */
+ q = 0;
+ r = gainScale; /* guaranteed > 0, else maxFlag could not have been set */
+ z = CLZ(r);
+ if (z < 16) {
+ q = 16 - z;
+ r >>= q; /* out = Q(fbitsGain - q) */
+ }
+
+ z = CLZ(gainMax) - 1;
+ r = (gainMax << z) / r; /* out = Q((fbitsGainMax + z) - (fbitsGain - q)) */
+ q = (gainMaxFBits + z) - (fbitsGain - q); /* r = Q(q) */
+ if (q > 30) {
+ r >>= MIN(q - 30, 31);
+ } else {
+ z = MIN(30 - q, 30);
+ CLIP_2N_SHIFT30(r, z); /* let r = Q30 since range = [0.0, 1.0) (clip to 0x3fffffff = 0.99999) */
+ }
+
+ qm = MULSHIFT32(qm, r) << 2;
+ gain = MULSHIFT32(gain, r) << 2;
+ psi->gLimBuf[m] = gainMax;
+ psi->gLimFbits[m] = gainMaxFBits;
+ } else {
+ psi->gLimBuf[m] = gainScale;
+ psi->gLimFbits[m] = fbitsGain;
+ }
+
+ /* sumSM, sumQM, sumECurrGLim = Q(fbitsDQ - ACC_SCALE) */
+ psi->smBuf[m] = sm;
+ psi->sumSM += (sm >> ACC_SCALE);
+
+ psi->qmLimBuf[m] = qm;
+ if (env != psi->la && env != sbrChan->laPrev && sm == 0) {
+ psi->sumQM += (qm >> ACC_SCALE);
+ }
+
+ /* eCurr * gain^2 same as gain^2, before division by eCurr
+ * (but note that gain != 0 even if eCurr == 0, since it's divided by eps)
+ */
+ if (eCurr) {
+ psi->sumECurrGLim += (gain >> ACC_SCALE);
+ }
+ }
+}
+
+/**************************************************************************************
+ * Function: ApplyBoost
+ *
+ * Description: calculate and apply boost factor for envelope, sinusoids, and noise
+ * in this limiter band (4.6.18.7.5)
+ *
+ * Inputs: initialized PSInfoSBR struct
+ * initialized SBRFreq struct for this SCE/CPE block
+ * index of current limiter band
+ * number of fraction bits in dequantized envelope
+ *
+ * Outputs: envelope gain, sinusoids and noise after scaling by gBoost
+ * format = Q(FBITS_GLIM_BOOST) for envelope gain,
+ * = Q(FBITS_QLIM_BOOST) for noise
+ * = Q(FBITS_OUT_QMFA) for sinusoids
+ *
+ * Return: none
+ *
+ * Notes: after scaling, each component has at least 1 GB
+ **************************************************************************************/
+static void ApplyBoost(PSInfoSBR *psi, SBRFreq *sbrFreq, int lim, int fbitsDQ)
+{
+ int m, mStart, mEnd, q, z, r;
+ int sumEOrigMapped, gBoost;
+
+ mStart = sbrFreq->freqLimiter[lim]; /* these are offsets from kStart */
+ mEnd = sbrFreq->freqLimiter[lim + 1];
+
+ sumEOrigMapped = psi->sumEOrigMapped >> 1;
+ r = (psi->sumECurrGLim >> 1) + (psi->sumSM >> 1) + (psi->sumQM >> 1); /* 1 GB fine (sm and qm are mutually exclusive in acc) */
+ if (r < (1 << (31 - 28))) {
+ /* any non-zero numerator * 1/EPS_0 is > GBOOST_MAX
+ * round very small r to zero to avoid scaling problems
+ */
+ gBoost = (sumEOrigMapped == 0 ? (1 << 28) : GBOOST_MAX);
+ z = 0;
+ } else if (sumEOrigMapped == 0) {
+ /* 1/(any non-zero denominator) * EPS_0 is appx. 0 */
+ gBoost = 0;
+ z = 0;
+ } else {
+ /* numerator (sumEOrigMapped) and denominator (r) have same Q format (before << z) */
+ z = CLZ(r) - 1; /* z = [0, 27] */
+ r = InvRNormalized(r << z);
+ gBoost = MULSHIFT32(sumEOrigMapped, r);
+ }
+
+ /* gBoost = Q(28 - z) */
+ if (gBoost > (GBOOST_MAX >> z)) {
+ gBoost = GBOOST_MAX;
+ z = 0;
+ }
+ gBoost <<= z; /* gBoost = Q28, minimum 1 GB */
+
+ /* convert gain, noise, sinusoids to fixed Q format, clipping if necessary
+ * (rare, usually only happens at very low bitrates, introduces slight
+ * distortion into final HF mapping, but should be inaudible)
+ */
+ for (m = mStart; m < mEnd; m++) {
+ /* let gLimBoost = Q24, since in practice the max values are usually 16 to 20
+ * unless limiterGains == 3 (limiter off) and eCurr ~= 0 (i.e. huge gain, but only
+ * because the envelope has 0 power anyway)
+ */
+ q = MULSHIFT32(psi->gLimBuf[m], gBoost) << 2; /* Q(gLimFbits) * Q(28) --> Q(gLimFbits[m]-2) */
+ r = SqrtFix(q, psi->gLimFbits[m] - 2, &z);
+ z -= FBITS_GLIM_BOOST;
+ if (z >= 0) {
+ psi->gLimBoost[m] = r >> MIN(z, 31);
+ } else {
+ z = MIN(30, -z);
+ CLIP_2N_SHIFT30(r, z);
+ psi->gLimBoost[m] = r;
+ }
+
+ q = MULSHIFT32(psi->qmLimBuf[m], gBoost) << 2; /* Q(fbitsDQ) * Q(28) --> Q(fbitsDQ-2) */
+ r = SqrtFix(q, fbitsDQ - 2, &z);
+ z -= FBITS_QLIM_BOOST; /* << by 14, since integer sqrt of x < 2^16, and we want to leave 1 GB */
+ if (z >= 0) {
+ psi->qmLimBoost[m] = r >> MIN(31, z);
+ } else {
+ z = MIN(30, -z);
+ CLIP_2N_SHIFT30(r, z);
+ psi->qmLimBoost[m] = r;
+ }
+
+ q = MULSHIFT32(psi->smBuf[m], gBoost) << 2; /* Q(fbitsDQ) * Q(28) --> Q(fbitsDQ-2) */
+ r = SqrtFix(q, fbitsDQ - 2, &z);
+ z -= FBITS_OUT_QMFA; /* justify for adding to signal (xBuf) later */
+ if (z >= 0) {
+ psi->smBoost[m] = r >> MIN(31, z);
+ } else {
+ z = MIN(30, -z);
+ CLIP_2N_SHIFT30(r, z);
+ psi->smBoost[m] = r;
+ }
+ }
+}
+
+/**************************************************************************************
+ * Function: CalcGain
+ *
+ * Description: calculate and apply proper gain to HF components in one envelope
+ * (4.6.18.7.5)
+ *
+ * Inputs: initialized PSInfoSBR struct
+ * initialized SBRHeader struct for this SCE/CPE block
+ * initialized SBRGrid struct for this channel
+ * initialized SBRFreq struct for this SCE/CPE block
+ * initialized SBRChan struct for this channel
+ * index of current channel (0 for SCE, 0 or 1 for CPE)
+ * index of current envelope
+ *
+ * Outputs: envelope gain, sinusoids and noise after scaling
+ *
+ * Return: none
+ **************************************************************************************/
+static void CalcGain(PSInfoSBR *psi, SBRHeader *sbrHdr, SBRGrid *sbrGrid, SBRFreq *sbrFreq, SBRChan *sbrChan, int ch, int env)
+{
+ int lim, fbitsDQ;
+
+ /* initialize to -1 so that mapping limiter bands to env/noise bands works right on first pass */
+ psi->envBand = -1;
+ psi->noiseFloorBand = -1;
+ psi->sBand = -1;
+ psi->highBand = -1;
+
+ fbitsDQ = (FBITS_OUT_DQ_ENV - psi->envDataDequantScale[ch][env]); /* Q(29 - optional scalefactor) */
+ for (lim = 0; lim < sbrFreq->nLimiter; lim++) {
+ /* the QMF bands are divided into lim regions (consecutive, non-overlapping) */
+ CalcMaxGain(psi, sbrHdr, sbrGrid, sbrFreq, ch, env, lim, fbitsDQ);
+ CalcComponentGains(psi, sbrGrid, sbrFreq, sbrChan, ch, env, lim, fbitsDQ);
+ ApplyBoost(psi, sbrFreq, lim, fbitsDQ);
+ }
+}
+
+/* hSmooth table from 4.7.18.7.6, format = Q31 */
+static const int hSmoothCoef[MAX_NUM_SMOOTH_COEFS] = {
+ 0x2aaaaaab, 0x2697a512, 0x1becfa68, 0x0ebdb043, 0x04130598,
+};
+
+/**************************************************************************************
+ * Function: MapHF
+ *
+ * Description: map HF components to proper QMF bands, with optional gain smoothing
+ * filter (4.6.18.7.6)
+ *
+ * Inputs: initialized PSInfoSBR struct
+ * initialized SBRHeader struct for this SCE/CPE block
+ * initialized SBRGrid struct for this channel
+ * initialized SBRFreq struct for this SCE/CPE block
+ * initialized SBRChan struct for this channel
+ * index of current envelope
+ * reset flag (can be non-zero for first envelope only)
+ *
+ * Outputs: complete reconstructed subband QMF samples for this envelope
+ *
+ * Return: none
+ *
+ * Notes: ensures that output has >= MIN_GBITS_IN_QMFS guard bits,
+ * so it's not necessary to check anything in the synth QMF
+ **************************************************************************************/
+static int MapHF(PSInfoSBR *psi, SBRHeader *sbrHdr, SBRGrid *sbrGrid, SBRFreq *sbrFreq, SBRChan *sbrChan, int env, int hfReset)
+{
+ int noiseTabIndex, sinIndex, gainNoiseIndex, hSL;
+ int i, iStart, iEnd, m, idx, j, s, n, smre, smim;
+ int gFilt, qFilt, xre, xim, gbMask, gbIdx;
+ int *XBuf;
+
+ noiseTabIndex = sbrChan->noiseTabIndex;
+ sinIndex = sbrChan->sinIndex;
+ gainNoiseIndex = sbrChan->gainNoiseIndex; /* oldest entries in filter delay buffer */
+
+ if (hfReset) {
+ noiseTabIndex = 2; /* starts at 1, double since complex */
+ }
+ hSL = (sbrHdr->smoothMode ? 0 : 4);
+
+ if (hfReset) {
+ for (i = 0; i < hSL; i++) {
+ for (m = 0; m < sbrFreq->numQMFBands; m++) {
+ sbrChan->gTemp[gainNoiseIndex][m] = psi->gLimBoost[m];
+ sbrChan->qTemp[gainNoiseIndex][m] = psi->qmLimBoost[m];
+ }
+ gainNoiseIndex++;
+ if (gainNoiseIndex == MAX_NUM_SMOOTH_COEFS) {
+ gainNoiseIndex = 0;
+ }
+ }
+ ASSERT(env == 0, ERR_AAC_SBR_BITSTREAM); /* should only be reset when env == 0 */
+ }
+
+ iStart = sbrGrid->envTimeBorder[env];
+ iEnd = sbrGrid->envTimeBorder[env + 1];
+ for (i = iStart; i < iEnd; i++) {
+ /* save new values in temp buffers (delay)
+ * we only store MAX_NUM_SMOOTH_COEFS most recent values,
+ * so don't keep storing the same value over and over
+ */
+ if (i - iStart < MAX_NUM_SMOOTH_COEFS) {
+ for (m = 0; m < sbrFreq->numQMFBands; m++) {
+ sbrChan->gTemp[gainNoiseIndex][m] = psi->gLimBoost[m];
+ sbrChan->qTemp[gainNoiseIndex][m] = psi->qmLimBoost[m];
+ }
+ }
+
+ /* see 4.6.18.7.6 */
+ XBuf = psi->XBuf[i + HF_ADJ][sbrFreq->kStart];
+ gbMask = 0;
+ for (m = 0; m < sbrFreq->numQMFBands; m++) {
+ if (env == psi->la || env == sbrChan->laPrev) {
+ /* no smoothing filter for gain, and qFilt = 0 (only need to do once) */
+ if (i == iStart) {
+ psi->gFiltLast[m] = sbrChan->gTemp[gainNoiseIndex][m];
+ psi->qFiltLast[m] = 0;
+ }
+ } else if (hSL == 0) {
+ /* no smoothing filter for gain, (only need to do once) */
+ if (i == iStart) {
+ psi->gFiltLast[m] = sbrChan->gTemp[gainNoiseIndex][m];
+ psi->qFiltLast[m] = sbrChan->qTemp[gainNoiseIndex][m];
+ }
+ } else {
+ /* apply smoothing filter to gain and noise (after MAX_NUM_SMOOTH_COEFS, it's always the same) */
+ if (i - iStart < MAX_NUM_SMOOTH_COEFS) {
+ gFilt = 0;
+ qFilt = 0;
+ idx = gainNoiseIndex;
+ for (j = 0; j < MAX_NUM_SMOOTH_COEFS; j++) {
+ /* sum(abs(hSmoothCoef[j])) for all j < 1.0 */
+ gFilt += MULSHIFT32(sbrChan->gTemp[idx][m], hSmoothCoef[j]);
+ qFilt += MULSHIFT32(sbrChan->qTemp[idx][m], hSmoothCoef[j]);
+ idx--;
+ if (idx < 0) {
+ idx += MAX_NUM_SMOOTH_COEFS;
+ }
+ }
+ psi->gFiltLast[m] = gFilt << 1; /* restore to Q(FBITS_GLIM_BOOST) (gain of filter < 1.0, so no overflow) */
+ psi->qFiltLast[m] = qFilt << 1; /* restore to Q(FBITS_QLIM_BOOST) */
+ }
+ }
+
+ if (psi->smBoost[m] != 0) {
+ /* add scaled signal and sinusoid, don't add noise (qFilt = 0) */
+ smre = psi->smBoost[m];
+ smim = smre;
+
+ /* sinIndex: [0] xre += sm [1] xim += sm*s [2] xre -= sm [3] xim -= sm*s */
+ s = (sinIndex >> 1); /* if 2 or 3, flip sign to subtract sm */
+ s <<= 31;
+ smre ^= (s >> 31);
+ smre -= (s >> 31);
+ s ^= ((m + sbrFreq->kStart) << 31);
+ smim ^= (s >> 31);
+ smim -= (s >> 31);
+
+ /* if sinIndex == 0 or 2, smim = 0; if sinIndex == 1 or 3, smre = 0 */
+ s = sinIndex << 31;
+ smim &= (s >> 31);
+ s ^= 0x80000000;
+ smre &= (s >> 31);
+
+ noiseTabIndex += 2; /* noise filtered by 0, but still need to bump index */
+ } else {
+ /* add scaled signal and scaled noise */
+ qFilt = psi->qFiltLast[m];
+ n = noiseTab[noiseTabIndex++];
+ smre = MULSHIFT32(n, qFilt) >> (FBITS_QLIM_BOOST - 1 - FBITS_OUT_QMFA);
+
+ n = noiseTab[noiseTabIndex++];
+ smim = MULSHIFT32(n, qFilt) >> (FBITS_QLIM_BOOST - 1 - FBITS_OUT_QMFA);
+ }
+ noiseTabIndex &= 1023; /* 512 complex numbers */
+
+ gFilt = psi->gFiltLast[m];
+ xre = MULSHIFT32(gFilt, XBuf[0]);
+ xim = MULSHIFT32(gFilt, XBuf[1]);
+ CLIP_2N_SHIFT30(xre, 32 - FBITS_GLIM_BOOST);
+ CLIP_2N_SHIFT30(xim, 32 - FBITS_GLIM_BOOST);
+
+ xre += smre;
+ *XBuf++ = xre;
+ xim += smim;
+ *XBuf++ = xim;
+
+ gbMask |= FASTABS(xre);
+ gbMask |= FASTABS(xim);
+ }
+ /* update circular buffer index */
+ gainNoiseIndex++;
+ if (gainNoiseIndex == MAX_NUM_SMOOTH_COEFS) {
+ gainNoiseIndex = 0;
+ }
+
+ sinIndex++;
+ sinIndex &= 3;
+
+ /* ensure MIN_GBITS_IN_QMFS guard bits in output
+ * almost never occurs in practice, but checking here makes synth QMF logic very simple
+ */
+ if (gbMask >> (31 - MIN_GBITS_IN_QMFS)) {
+ XBuf = psi->XBuf[i + HF_ADJ][sbrFreq->kStart];
+ for (m = 0; m < sbrFreq->numQMFBands; m++) {
+ xre = XBuf[0];
+ xim = XBuf[1];
+ CLIP_2N(xre, (31 - MIN_GBITS_IN_QMFS));
+ CLIP_2N(xim, (31 - MIN_GBITS_IN_QMFS));
+ *XBuf++ = xre;
+ *XBuf++ = xim;
+ }
+ CLIP_2N(gbMask, (31 - MIN_GBITS_IN_QMFS));
+ }
+ gbIdx = ((i + HF_ADJ) >> 5) & 0x01;
+ sbrChan->gbMask[gbIdx] |= gbMask;
+ }
+ sbrChan->noiseTabIndex = noiseTabIndex;
+ sbrChan->sinIndex = sinIndex;
+ sbrChan->gainNoiseIndex = gainNoiseIndex;
+ return ERR_AAC_NONE;
+}
+
+/**************************************************************************************
+ * Function: AdjustHighFreq
+ *
+ * Description: adjust high frequencies and add noise and sinusoids (4.6.18.7)
+ *
+ * Inputs: initialized PSInfoSBR struct
+ * initialized SBRHeader struct for this SCE/CPE block
+ * initialized SBRGrid struct for this channel
+ * initialized SBRFreq struct for this SCE/CPE block
+ * initialized SBRChan struct for this channel
+ * index of current channel (0 for SCE, 0 or 1 for CPE)
+ *
+ * Outputs: complete reconstructed subband QMF samples for this channel
+ *
+ * Return: none
+ **************************************************************************************/
+int AdjustHighFreq(PSInfoSBR *psi, SBRHeader *sbrHdr, SBRGrid *sbrGrid, SBRFreq *sbrFreq, SBRChan *sbrChan, int ch)
+{
+ int i, env, hfReset;
+ unsigned char frameClass, pointer;
+ int err = ERR_AAC_NONE;
+ frameClass = sbrGrid->frameClass;
+ pointer = sbrGrid->pointer;
+
+ /* derive la from table 4.159 */
+ if ((frameClass == SBR_GRID_FIXVAR || frameClass == SBR_GRID_VARVAR) && pointer > 0) {
+ psi->la = sbrGrid->numEnv + 1 - pointer;
+ } else if (frameClass == SBR_GRID_VARFIX && pointer > 1) {
+ psi->la = pointer - 1;
+ } else {
+ psi->la = -1;
+ }
+
+ /* for each envelope, estimate gain and adjust SBR QMF bands */
+ hfReset = sbrChan->reset;
+ for (env = 0; env < sbrGrid->numEnv; env++) {
+ EstimateEnvelope(psi, sbrHdr, sbrGrid, sbrFreq, env);
+ CalcGain(psi, sbrHdr, sbrGrid, sbrFreq, sbrChan, ch, env);
+ err = MapHF(psi, sbrHdr, sbrGrid, sbrFreq, sbrChan, env, hfReset);
+ if (err) {
+ return err;
+ }
+ hfReset = 0; /* only set for first envelope after header reset */
+ }
+
+ /* set saved sine flags to 0 for QMF bands outside of current frequency range */
+ for (i = 0; i < sbrFreq->freqLimiter[0] + sbrFreq->kStart; i++) {
+ sbrChan->addHarmonic[0][i] = 0;
+ }
+ for (i = sbrFreq->freqLimiter[sbrFreq->nLimiter] + sbrFreq->kStart; i < 64; i++) {
+ sbrChan->addHarmonic[0][i] = 0;
+ }
+ sbrChan->addHarmonicFlag[0] = sbrChan->addHarmonicFlag[1];
+
+ /* save la for next frame */
+ if (psi->la == sbrGrid->numEnv) {
+ sbrChan->laPrev = 0;
+ } else {
+ sbrChan->laPrev = -1;
+ }
+ return ERR_AAC_NONE;
+}