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/sbr_hfadj.c b/audio_codec/libfaad/sbr_hfadj.c
new file mode 100644
index 0000000..3f29f32
--- a/dev/null
+++ b/audio_codec/libfaad/sbr_hfadj.c
@@ -0,0 +1,1644 @@
+/*
+** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation; either version 2 of the License, or
+** (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+**
+** Any non-GPL usage of this software or parts of this software is strictly
+** forbidden.
+**
+** The "appropriate copyright message" mentioned in section 2c of the GPLv2
+** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
+**
+** Commercial non-GPL licensing of this software is possible.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
+**
+** $Id: sbr_hfadj.c,v 1.23 2008/09/19 22:50:20 menno Exp $
+**/
+
+/* High Frequency adjustment */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <fcntl.h>
+
+#include "common.h"
+#include "structs.h"
+
+#ifdef SBR_DEC
+
+#include "sbr_syntax.h"
+#include "sbr_hfadj.h"
+
+#include "sbr_noise.h"
+
+
+/* static function declarations */
+static uint8_t estimate_current_envelope(sbr_info *sbr, sbr_hfadj_info *adj,
+ qmf_t Xsbr[MAX_NTSRHFG][64], uint8_t ch);
+static void calculate_gain(sbr_info *sbr, sbr_hfadj_info *adj, uint8_t ch);
+#ifdef SBR_LOW_POWER
+static void calc_gain_groups(sbr_info *sbr, sbr_hfadj_info *adj, real_t *deg, uint8_t ch);
+static void aliasing_reduction(sbr_info *sbr, sbr_hfadj_info *adj, real_t *deg, uint8_t ch);
+#endif
+static void hf_assembly(sbr_info *sbr, sbr_hfadj_info *adj, qmf_t Xsbr[MAX_NTSRHFG][64], uint8_t ch);
+
+
+uint8_t hf_adjustment(sbr_info *sbr, qmf_t Xsbr[MAX_NTSRHFG][64]
+#ifdef SBR_LOW_POWER
+ , real_t *deg /* aliasing degree */
+#endif
+ , uint8_t ch)
+{
+ ALIGN sbr_hfadj_info adj = {{{0}}};
+ uint8_t ret = 0;
+
+ if (sbr->bs_frame_class[ch] == FIXFIX) {
+ sbr->l_A[ch] = -1;
+ } else if (sbr->bs_frame_class[ch] == VARFIX) {
+ if (sbr->bs_pointer[ch] > 1) {
+ sbr->l_A[ch] = sbr->bs_pointer[ch] - 1;
+ } else {
+ sbr->l_A[ch] = -1;
+ }
+ } else {
+ if (sbr->bs_pointer[ch] == 0) {
+ sbr->l_A[ch] = -1;
+ } else {
+ sbr->l_A[ch] = sbr->L_E[ch] + 1 - sbr->bs_pointer[ch];
+ }
+ }
+
+ ret = estimate_current_envelope(sbr, &adj, Xsbr, ch);
+ if (ret > 0) {
+ return 1;
+ }
+
+ calculate_gain(sbr, &adj, ch);
+
+#ifdef SBR_LOW_POWER
+ calc_gain_groups(sbr, &adj, deg, ch);
+ aliasing_reduction(sbr, &adj, deg, ch);
+#endif
+
+ hf_assembly(sbr, &adj, Xsbr, ch);
+
+ return 0;
+}
+
+static uint8_t get_S_mapped(sbr_info *sbr, uint8_t ch, uint8_t l, uint8_t current_band)
+{
+ if (sbr->f[ch][l] == HI_RES) {
+ /* in case of using f_table_high we just have 1 to 1 mapping
+ * from bs_add_harmonic[l][k]
+ */
+ if ((l >= sbr->l_A[ch]) ||
+ (sbr->bs_add_harmonic_prev[ch][current_band] && sbr->bs_add_harmonic_flag_prev[ch])) {
+ return sbr->bs_add_harmonic[ch][current_band];
+ }
+ } else {
+ uint8_t b, lb, ub;
+
+ /* in case of f_table_low we check if any of the HI_RES bands
+ * within this LO_RES band has bs_add_harmonic[l][k] turned on
+ * (note that borders in the LO_RES table are also present in
+ * the HI_RES table)
+ */
+
+ /* find first HI_RES band in current LO_RES band */
+ lb = 2 * current_band - ((sbr->N_high & 1) ? 1 : 0);
+ /* find first HI_RES band in next LO_RES band */
+ ub = 2 * (current_band + 1) - ((sbr->N_high & 1) ? 1 : 0);
+
+ /* check all HI_RES bands in current LO_RES band for sinusoid */
+ for (b = lb; b < ub; b++) {
+ if ((l >= sbr->l_A[ch]) ||
+ (sbr->bs_add_harmonic_prev[ch][b] && sbr->bs_add_harmonic_flag_prev[ch])) {
+ if (sbr->bs_add_harmonic[ch][b] == 1) {
+ return 1;
+ }
+ }
+ }
+ }
+
+ return 0;
+}
+
+static uint8_t estimate_current_envelope(sbr_info *sbr, sbr_hfadj_info *adj,
+ qmf_t Xsbr[MAX_NTSRHFG][64], uint8_t ch)
+{
+ uint8_t m, l, j, k, k_l, k_h, p;
+ real_t nrg, div;
+
+ if (sbr->bs_interpol_freq == 1) {
+ for (l = 0; l < sbr->L_E[ch]; l++) {
+ uint8_t i, l_i, u_i;
+
+ l_i = sbr->t_E[ch][l];
+ u_i = sbr->t_E[ch][l + 1];
+
+ div = (real_t)(u_i - l_i);
+
+ if (div == 0) {
+ div = 1;
+ }
+
+ for (m = 0; m < sbr->M; m++) {
+ nrg = 0;
+
+ for (i = l_i + sbr->tHFAdj; i < u_i + sbr->tHFAdj; i++) {
+#ifdef FIXED_POINT
+#ifdef SBR_LOW_POWER
+ nrg += ((QMF_RE(Xsbr[i][m + sbr->kx]) + (1 << (REAL_BITS - 1))) >> REAL_BITS) * ((QMF_RE(Xsbr[i][m + sbr->kx]) + (1 << (REAL_BITS - 1))) >> REAL_BITS);
+#else
+ nrg += ((QMF_RE(Xsbr[i][m + sbr->kx]) + (1 << (REAL_BITS - 1))) >> REAL_BITS) * ((QMF_RE(Xsbr[i][m + sbr->kx]) + (1 << (REAL_BITS - 1))) >> REAL_BITS) +
+ ((QMF_IM(Xsbr[i][m + sbr->kx]) + (1 << (REAL_BITS - 1))) >> REAL_BITS) * ((QMF_IM(Xsbr[i][m + sbr->kx]) + (1 << (REAL_BITS - 1))) >> REAL_BITS);
+#endif
+#else
+ nrg += MUL_R(QMF_RE(Xsbr[i][m + sbr->kx]), QMF_RE(Xsbr[i][m + sbr->kx]))
+#ifndef SBR_LOW_POWER
+ + MUL_R(QMF_IM(Xsbr[i][m + sbr->kx]), QMF_IM(Xsbr[i][m + sbr->kx]))
+#endif
+ ;
+#endif
+ }
+
+ sbr->E_curr[ch][m][l] = nrg / div;
+#ifdef SBR_LOW_POWER
+#ifdef FIXED_POINT
+ sbr->E_curr[ch][m][l] <<= 1;
+#else
+ sbr->E_curr[ch][m][l] *= 2;
+#endif
+#endif
+ }
+ }
+ } else {
+ for (l = 0; l < sbr->L_E[ch]; l++) {
+ for (p = 0; p < sbr->n[sbr->f[ch][l]]; p++) {
+ k_l = sbr->f_table_res[sbr->f[ch][l]][p];
+ k_h = sbr->f_table_res[sbr->f[ch][l]][p + 1];
+
+ for (k = k_l; k < k_h; k++) {
+ uint8_t i, l_i, u_i;
+ nrg = 0;
+
+ l_i = sbr->t_E[ch][l];
+ u_i = sbr->t_E[ch][l + 1];
+
+ div = (real_t)((u_i - l_i) * (k_h - k_l));
+
+ if (div == 0) {
+ div = 1;
+ }
+
+ for (i = l_i + sbr->tHFAdj; i < u_i + sbr->tHFAdj; i++) {
+ for (j = k_l; j < k_h; j++) {
+#ifdef FIXED_POINT
+#ifdef SBR_LOW_POWER
+ nrg += ((QMF_RE(Xsbr[i][j]) + (1 << (REAL_BITS - 1))) >> REAL_BITS) * ((QMF_RE(Xsbr[i][j]) + (1 << (REAL_BITS - 1))) >> REAL_BITS);
+#else
+ nrg += ((QMF_RE(Xsbr[i][j]) + (1 << (REAL_BITS - 1))) >> REAL_BITS) * ((QMF_RE(Xsbr[i][j]) + (1 << (REAL_BITS - 1))) >> REAL_BITS) +
+ ((QMF_IM(Xsbr[i][j]) + (1 << (REAL_BITS - 1))) >> REAL_BITS) * ((QMF_IM(Xsbr[i][j]) + (1 << (REAL_BITS - 1))) >> REAL_BITS);
+#endif
+#else
+ nrg += MUL_R(QMF_RE(Xsbr[i][j]), QMF_RE(Xsbr[i][j]))
+#ifndef SBR_LOW_POWER
+ + MUL_R(QMF_IM(Xsbr[i][j]), QMF_IM(Xsbr[i][j]))
+#endif
+ ;
+#endif
+ }
+ }
+
+ sbr->E_curr[ch][k - sbr->kx][l] = nrg / div;
+#ifdef SBR_LOW_POWER
+#ifdef FIXED_POINT
+ sbr->E_curr[ch][k - sbr->kx][l] <<= 1;
+#else
+ sbr->E_curr[ch][k - sbr->kx][l] *= 2;
+#endif
+#endif
+ }
+ }
+ }
+ }
+
+ return 0;
+}
+
+#ifdef FIXED_POINT
+#define EPS (1) /* smallest number available in fixed point */
+#else
+#define EPS (1e-12)
+#endif
+
+
+
+#ifdef FIXED_POINT
+
+/* log2 values of [0..63] */
+static const real_t log2_int_tab[] = {
+ LOG2_MIN_INF, REAL_CONST(0.000000000000000), REAL_CONST(1.000000000000000), REAL_CONST(1.584962500721156),
+ REAL_CONST(2.000000000000000), REAL_CONST(2.321928094887362), REAL_CONST(2.584962500721156), REAL_CONST(2.807354922057604),
+ REAL_CONST(3.000000000000000), REAL_CONST(3.169925001442313), REAL_CONST(3.321928094887363), REAL_CONST(3.459431618637297),
+ REAL_CONST(3.584962500721156), REAL_CONST(3.700439718141092), REAL_CONST(3.807354922057604), REAL_CONST(3.906890595608519),
+ REAL_CONST(4.000000000000000), REAL_CONST(4.087462841250339), REAL_CONST(4.169925001442312), REAL_CONST(4.247927513443585),
+ REAL_CONST(4.321928094887362), REAL_CONST(4.392317422778761), REAL_CONST(4.459431618637297), REAL_CONST(4.523561956057013),
+ REAL_CONST(4.584962500721156), REAL_CONST(4.643856189774724), REAL_CONST(4.700439718141093), REAL_CONST(4.754887502163468),
+ REAL_CONST(4.807354922057604), REAL_CONST(4.857980995127572), REAL_CONST(4.906890595608519), REAL_CONST(4.954196310386875),
+ REAL_CONST(5.000000000000000), REAL_CONST(5.044394119358453), REAL_CONST(5.087462841250340), REAL_CONST(5.129283016944966),
+ REAL_CONST(5.169925001442312), REAL_CONST(5.209453365628949), REAL_CONST(5.247927513443585), REAL_CONST(5.285402218862248),
+ REAL_CONST(5.321928094887363), REAL_CONST(5.357552004618084), REAL_CONST(5.392317422778761), REAL_CONST(5.426264754702098),
+ REAL_CONST(5.459431618637297), REAL_CONST(5.491853096329675), REAL_CONST(5.523561956057013), REAL_CONST(5.554588851677637),
+ REAL_CONST(5.584962500721156), REAL_CONST(5.614709844115208), REAL_CONST(5.643856189774724), REAL_CONST(5.672425341971495),
+ REAL_CONST(5.700439718141093), REAL_CONST(5.727920454563200), REAL_CONST(5.754887502163469), REAL_CONST(5.781359713524660),
+ REAL_CONST(5.807354922057605), REAL_CONST(5.832890014164742), REAL_CONST(5.857980995127572), REAL_CONST(5.882643049361842),
+ REAL_CONST(5.906890595608518), REAL_CONST(5.930737337562887), REAL_CONST(5.954196310386876), REAL_CONST(5.977279923499916)
+};
+
+static const real_t pan_log2_tab[] = {
+ REAL_CONST(1.000000000000000), REAL_CONST(0.584962500721156), REAL_CONST(0.321928094887362), REAL_CONST(0.169925001442312), REAL_CONST(0.087462841250339),
+ REAL_CONST(0.044394119358453), REAL_CONST(0.022367813028455), REAL_CONST(0.011227255423254), REAL_CONST(0.005624549193878), REAL_CONST(0.002815015607054),
+ REAL_CONST(0.001408194392808), REAL_CONST(0.000704269011247), REAL_CONST(0.000352177480301), REAL_CONST(0.000176099486443), REAL_CONST(0.000088052430122),
+ REAL_CONST(0.000044026886827), REAL_CONST(0.000022013611360), REAL_CONST(0.000011006847667)
+};
+
+static real_t find_log2_E(sbr_info *sbr, uint8_t k, uint8_t l, uint8_t ch)
+{
+ /* check for coupled energy/noise data */
+ if (sbr->bs_coupling == 1) {
+ uint8_t amp0 = (sbr->amp_res[0]) ? 0 : 1;
+ uint8_t amp1 = (sbr->amp_res[1]) ? 0 : 1;
+ real_t tmp = (7 << REAL_BITS) + (sbr->E[0][k][l] << (REAL_BITS - amp0));
+ real_t pan;
+
+ /* E[1] should always be even so shifting is OK */
+ uint8_t E = sbr->E[1][k][l] >> amp1;
+
+ if (ch == 0) {
+ if (E > 12) {
+ /* negative */
+ pan = pan_log2_tab[-12 + E];
+ } else {
+ /* positive */
+ pan = pan_log2_tab[12 - E] + ((12 - E) << REAL_BITS);
+ }
+ } else {
+ if (E < 12) {
+ /* negative */
+ pan = pan_log2_tab[-E + 12];
+ } else {
+ /* positive */
+ pan = pan_log2_tab[E - 12] + ((E - 12) << REAL_BITS);
+ }
+ }
+
+ /* tmp / pan in log2 */
+ return tmp - pan;
+ } else {
+ uint8_t amp = (sbr->amp_res[ch]) ? 0 : 1;
+
+ return (6 << REAL_BITS) + (sbr->E[ch][k][l] << (REAL_BITS - amp));
+ }
+}
+
+static real_t find_log2_Q(sbr_info *sbr, uint8_t k, uint8_t l, uint8_t ch)
+{
+ /* check for coupled energy/noise data */
+ if (sbr->bs_coupling == 1) {
+ real_t tmp = (7 << REAL_BITS) - (sbr->Q[0][k][l] << REAL_BITS);
+ real_t pan;
+
+ uint8_t Q = sbr->Q[1][k][l];
+
+ if (ch == 0) {
+ if (Q > 12) {
+ /* negative */
+ pan = pan_log2_tab[-12 + Q];
+ } else {
+ /* positive */
+ pan = pan_log2_tab[12 - Q] + ((12 - Q) << REAL_BITS);
+ }
+ } else {
+ if (Q < 12) {
+ /* negative */
+ pan = pan_log2_tab[-Q + 12];
+ } else {
+ /* positive */
+ pan = pan_log2_tab[Q - 12] + ((Q - 12) << REAL_BITS);
+ }
+ }
+
+ /* tmp / pan in log2 */
+ return tmp - pan;
+ } else {
+ return (6 << REAL_BITS) - (sbr->Q[ch][k][l] << REAL_BITS);
+ }
+}
+
+static const real_t log_Qplus1_pan[31][13] = {
+ { REAL_CONST(0.044383447617292), REAL_CONST(0.169768601655960), REAL_CONST(0.583090126514435), REAL_CONST(1.570089221000671), REAL_CONST(3.092446088790894), REAL_CONST(4.733354568481445), REAL_CONST(6.022367954254150), REAL_CONST(6.692092418670654), REAL_CONST(6.924463272094727), REAL_CONST(6.989034175872803), REAL_CONST(7.005646705627441), REAL_CONST(7.009829998016357), REAL_CONST(7.010877609252930) },
+ { REAL_CONST(0.022362394258380), REAL_CONST(0.087379962205887), REAL_CONST(0.320804953575134), REAL_CONST(0.988859415054321), REAL_CONST(2.252387046813965), REAL_CONST(3.786596298217773), REAL_CONST(5.044394016265869), REAL_CONST(5.705977916717529), REAL_CONST(5.936291694641113), REAL_CONST(6.000346660614014), REAL_CONST(6.016829967498779), REAL_CONST(6.020981311798096), REAL_CONST(6.022020816802979) },
+ { REAL_CONST(0.011224525049329), REAL_CONST(0.044351425021887), REAL_CONST(0.169301137328148), REAL_CONST(0.577544987201691), REAL_CONST(1.527246952056885), REAL_CONST(2.887525320053101), REAL_CONST(4.087462902069092), REAL_CONST(4.733354568481445), REAL_CONST(4.959661006927490), REAL_CONST(5.022709369659424), REAL_CONST(5.038940429687500), REAL_CONST(5.043028831481934), REAL_CONST(5.044052600860596) },
+ { REAL_CONST(0.005623178556561), REAL_CONST(0.022346137091517), REAL_CONST(0.087132595479488), REAL_CONST(0.317482173442841), REAL_CONST(0.956931233406067), REAL_CONST(2.070389270782471), REAL_CONST(3.169924974441528), REAL_CONST(3.786596298217773), REAL_CONST(4.005294322967529), REAL_CONST(4.066420555114746), REAL_CONST(4.082170009613037), REAL_CONST(4.086137294769287), REAL_CONST(4.087131500244141) },
+ { REAL_CONST(0.002814328996465), REAL_CONST(0.011216334067285), REAL_CONST(0.044224001467228), REAL_CONST(0.167456731200218), REAL_CONST(0.556393325328827), REAL_CONST(1.378511548042297), REAL_CONST(2.321928024291992), REAL_CONST(2.887525320053101), REAL_CONST(3.092446088790894), REAL_CONST(3.150059700012207), REAL_CONST(3.164926528930664), REAL_CONST(3.168673276901245), REAL_CONST(3.169611930847168) },
+ { REAL_CONST(0.001407850766554), REAL_CONST(0.005619067233056), REAL_CONST(0.022281449288130), REAL_CONST(0.086156636476517), REAL_CONST(0.304854571819305), REAL_CONST(0.847996890544891), REAL_CONST(1.584962487220764), REAL_CONST(2.070389270782471), REAL_CONST(2.252387046813965), REAL_CONST(2.304061651229858), REAL_CONST(2.317430257797241), REAL_CONST(2.320801734924316), REAL_CONST(2.321646213531494) },
+ { REAL_CONST(0.000704097095877), REAL_CONST(0.002812269143760), REAL_CONST(0.011183738708496), REAL_CONST(0.043721374124289), REAL_CONST(0.160464659333229), REAL_CONST(0.485426813364029), REAL_CONST(1.000000000000000), REAL_CONST(1.378511548042297), REAL_CONST(1.527246952056885), REAL_CONST(1.570089221000671), REAL_CONST(1.581215262413025), REAL_CONST(1.584023833274841), REAL_CONST(1.584727644920349) },
+ { REAL_CONST(0.000352177477907), REAL_CONST(0.001406819908880), REAL_CONST(0.005602621007711), REAL_CONST(0.022026389837265), REAL_CONST(0.082462236285210), REAL_CONST(0.263034462928772), REAL_CONST(0.584962487220764), REAL_CONST(0.847996890544891), REAL_CONST(0.956931233406067), REAL_CONST(0.988859415054321), REAL_CONST(0.997190535068512), REAL_CONST(0.999296069145203), REAL_CONST(0.999823868274689) },
+ { REAL_CONST(0.000176099492819), REAL_CONST(0.000703581434209), REAL_CONST(0.002804030198604), REAL_CONST(0.011055230163038), REAL_CONST(0.041820213198662), REAL_CONST(0.137503549456596), REAL_CONST(0.321928083896637), REAL_CONST(0.485426813364029), REAL_CONST(0.556393325328827), REAL_CONST(0.577544987201691), REAL_CONST(0.583090126514435), REAL_CONST(0.584493279457092), REAL_CONST(0.584845066070557) },
+ { REAL_CONST(0.000088052431238), REAL_CONST(0.000351833587047), REAL_CONST(0.001402696361765), REAL_CONST(0.005538204684854), REAL_CONST(0.021061634644866), REAL_CONST(0.070389263331890), REAL_CONST(0.169925004243851), REAL_CONST(0.263034462928772), REAL_CONST(0.304854571819305), REAL_CONST(0.317482173442841), REAL_CONST(0.320804953575134), REAL_CONST(0.321646571159363), REAL_CONST(0.321857661008835) },
+ { REAL_CONST(0.000044026888645), REAL_CONST(0.000175927518285), REAL_CONST(0.000701518612914), REAL_CONST(0.002771759871393), REAL_CONST(0.010569252073765), REAL_CONST(0.035623874515295), REAL_CONST(0.087462842464447), REAL_CONST(0.137503549456596), REAL_CONST(0.160464659333229), REAL_CONST(0.167456731200218), REAL_CONST(0.169301137328148), REAL_CONST(0.169768601655960), REAL_CONST(0.169885858893394) },
+ { REAL_CONST(0.000022013611670), REAL_CONST(0.000088052431238), REAL_CONST(0.000350801943569), REAL_CONST(0.001386545598507), REAL_CONST(0.005294219125062), REAL_CONST(0.017921976745129), REAL_CONST(0.044394120573997), REAL_CONST(0.070389263331890), REAL_CONST(0.082462236285210), REAL_CONST(0.086156636476517), REAL_CONST(0.087132595479488), REAL_CONST(0.087379962205887), REAL_CONST(0.087442122399807) },
+ { REAL_CONST(0.000011006847672), REAL_CONST(0.000044026888645), REAL_CONST(0.000175411638338), REAL_CONST(0.000693439331371), REAL_CONST(0.002649537986144), REAL_CONST(0.008988817222416), REAL_CONST(0.022367812693119), REAL_CONST(0.035623874515295), REAL_CONST(0.041820213198662), REAL_CONST(0.043721374124289), REAL_CONST(0.044224001467228), REAL_CONST(0.044351425021887), REAL_CONST(0.044383447617292) },
+ { REAL_CONST(0.000005503434295), REAL_CONST(0.000022013611670), REAL_CONST(0.000087708482170), REAL_CONST(0.000346675369656), REAL_CONST(0.001325377263129), REAL_CONST(0.004501323681325), REAL_CONST(0.011227255687118), REAL_CONST(0.017921976745129), REAL_CONST(0.021061634644866), REAL_CONST(0.022026389837265), REAL_CONST(0.022281449288130), REAL_CONST(0.022346137091517), REAL_CONST(0.022362394258380) },
+ { REAL_CONST(0.000002751719876), REAL_CONST(0.000011006847672), REAL_CONST(0.000043854910473), REAL_CONST(0.000173348103999), REAL_CONST(0.000662840844598), REAL_CONST(0.002252417383716), REAL_CONST(0.005624548997730), REAL_CONST(0.008988817222416), REAL_CONST(0.010569252073765), REAL_CONST(0.011055230163038), REAL_CONST(0.011183738708496), REAL_CONST(0.011216334067285), REAL_CONST(0.011224525049329) },
+ { REAL_CONST(0.000001375860506), REAL_CONST(0.000005503434295), REAL_CONST(0.000022013611670), REAL_CONST(0.000086676649516), REAL_CONST(0.000331544462824), REAL_CONST(0.001126734190620), REAL_CONST(0.002815015614033), REAL_CONST(0.004501323681325), REAL_CONST(0.005294219125062), REAL_CONST(0.005538204684854), REAL_CONST(0.005602621007711), REAL_CONST(0.005619067233056), REAL_CONST(0.005623178556561) },
+ { REAL_CONST(0.000000687930424), REAL_CONST(0.000002751719876), REAL_CONST(0.000011006847672), REAL_CONST(0.000043338975956), REAL_CONST(0.000165781748365), REAL_CONST(0.000563477107789), REAL_CONST(0.001408194424585), REAL_CONST(0.002252417383716), REAL_CONST(0.002649537986144), REAL_CONST(0.002771759871393), REAL_CONST(0.002804030198604), REAL_CONST(0.002812269143760), REAL_CONST(0.002814328996465) },
+ { REAL_CONST(0.000000343965269), REAL_CONST(0.000001375860506), REAL_CONST(0.000005503434295), REAL_CONST(0.000021669651687), REAL_CONST(0.000082893253420), REAL_CONST(0.000281680084299), REAL_CONST(0.000704268983100), REAL_CONST(0.001126734190620), REAL_CONST(0.001325377263129), REAL_CONST(0.001386545598507), REAL_CONST(0.001402696361765), REAL_CONST(0.001406819908880), REAL_CONST(0.001407850766554) },
+ { REAL_CONST(0.000000171982634), REAL_CONST(0.000000687930424), REAL_CONST(0.000002751719876), REAL_CONST(0.000010834866771), REAL_CONST(0.000041447223339), REAL_CONST(0.000140846910654), REAL_CONST(0.000352177477907), REAL_CONST(0.000563477107789), REAL_CONST(0.000662840844598), REAL_CONST(0.000693439331371), REAL_CONST(0.000701518612914), REAL_CONST(0.000703581434209), REAL_CONST(0.000704097095877) },
+ { REAL_CONST(0.000000000000000), REAL_CONST(0.000000343965269), REAL_CONST(0.000001375860506), REAL_CONST(0.000005503434295), REAL_CONST(0.000020637769921), REAL_CONST(0.000070511166996), REAL_CONST(0.000176099492819), REAL_CONST(0.000281680084299), REAL_CONST(0.000331544462824), REAL_CONST(0.000346675369656), REAL_CONST(0.000350801943569), REAL_CONST(0.000351833587047), REAL_CONST(0.000352177477907) },
+ { REAL_CONST(0.000000000000000), REAL_CONST(0.000000171982634), REAL_CONST(0.000000687930424), REAL_CONST(0.000002751719876), REAL_CONST(0.000010318922250), REAL_CONST(0.000035256012779), REAL_CONST(0.000088052431238), REAL_CONST(0.000140846910654), REAL_CONST(0.000165781748365), REAL_CONST(0.000173348103999), REAL_CONST(0.000175411638338), REAL_CONST(0.000175927518285), REAL_CONST(0.000176099492819) },
+ { REAL_CONST(0.000000000000000), REAL_CONST(0.000000000000000), REAL_CONST(0.000000343965269), REAL_CONST(0.000001375860506), REAL_CONST(0.000005159470220), REAL_CONST(0.000017542124624), REAL_CONST(0.000044026888645), REAL_CONST(0.000070511166996), REAL_CONST(0.000082893253420), REAL_CONST(0.000086676649516), REAL_CONST(0.000087708482170), REAL_CONST(0.000088052431238), REAL_CONST(0.000088052431238) },
+ { REAL_CONST(0.000000000000000), REAL_CONST(0.000000000000000), REAL_CONST(0.000000171982634), REAL_CONST(0.000000687930424), REAL_CONST(0.000002579737384), REAL_CONST(0.000008771088687), REAL_CONST(0.000022013611670), REAL_CONST(0.000035256012779), REAL_CONST(0.000041447223339), REAL_CONST(0.000043338975956), REAL_CONST(0.000043854910473), REAL_CONST(0.000044026888645), REAL_CONST(0.000044026888645) },
+ { REAL_CONST(0.000000000000000), REAL_CONST(0.000000000000000), REAL_CONST(0.000000000000000), REAL_CONST(0.000000343965269), REAL_CONST(0.000001375860506), REAL_CONST(0.000004471542070), REAL_CONST(0.000011006847672), REAL_CONST(0.000017542124624), REAL_CONST(0.000020637769921), REAL_CONST(0.000021669651687), REAL_CONST(0.000022013611670), REAL_CONST(0.000022013611670), REAL_CONST(0.000022013611670) },
+ { REAL_CONST(0.000000000000000), REAL_CONST(0.000000000000000), REAL_CONST(0.000000000000000), REAL_CONST(0.000000171982634), REAL_CONST(0.000000687930424), REAL_CONST(0.000002235772627), REAL_CONST(0.000005503434295), REAL_CONST(0.000008771088687), REAL_CONST(0.000010318922250), REAL_CONST(0.000010834866771), REAL_CONST(0.000011006847672), REAL_CONST(0.000011006847672), REAL_CONST(0.000011006847672) },
+ { REAL_CONST(0.000000000000000), REAL_CONST(0.000000000000000), REAL_CONST(0.000000000000000), REAL_CONST(0.000000000000000), REAL_CONST(0.000000343965269), REAL_CONST(0.000001031895522), REAL_CONST(0.000002751719876), REAL_CONST(0.000004471542070), REAL_CONST(0.000005159470220), REAL_CONST(0.000005503434295), REAL_CONST(0.000005503434295), REAL_CONST(0.000005503434295), REAL_CONST(0.000005503434295) },
+ { REAL_CONST(0.000000000000000), REAL_CONST(0.000000000000000), REAL_CONST(0.000000000000000), REAL_CONST(0.000000000000000), REAL_CONST(0.000000171982634), REAL_CONST(0.000000515947875), REAL_CONST(0.000001375860506), REAL_CONST(0.000002235772627), REAL_CONST(0.000002579737384), REAL_CONST(0.000002751719876), REAL_CONST(0.000002751719876), REAL_CONST(0.000002751719876), REAL_CONST(0.000002751719876) },
+ { REAL_CONST(0.000000000000000), REAL_CONST(0.000000000000000), REAL_CONST(0.000000000000000), REAL_CONST(0.000000000000000), REAL_CONST(0.000000000000000), REAL_CONST(0.000000343965269), REAL_CONST(0.000000687930424), REAL_CONST(0.000001031895522), REAL_CONST(0.000001375860506), REAL_CONST(0.000001375860506), REAL_CONST(0.000001375860506), REAL_CONST(0.000001375860506), REAL_CONST(0.000001375860506) },
+ { REAL_CONST(0.000000000000000), REAL_CONST(0.000000000000000), REAL_CONST(0.000000000000000), REAL_CONST(0.000000000000000), REAL_CONST(0.000000000000000), REAL_CONST(0.000000171982634), REAL_CONST(0.000000343965269), REAL_CONST(0.000000515947875), REAL_CONST(0.000000687930424), REAL_CONST(0.000000687930424), REAL_CONST(0.000000687930424), REAL_CONST(0.000000687930424), REAL_CONST(0.000000687930424) },
+ { REAL_CONST(0.000000000000000), REAL_CONST(0.000000000000000), REAL_CONST(0.000000000000000), REAL_CONST(0.000000000000000), REAL_CONST(0.000000000000000), REAL_CONST(0.000000000000000), REAL_CONST(0.000000171982634), REAL_CONST(0.000000343965269), REAL_CONST(0.000000343965269), REAL_CONST(0.000000343965269), REAL_CONST(0.000000343965269), REAL_CONST(0.000000343965269), REAL_CONST(0.000000343965269) },
+ { REAL_CONST(0.000000000000000), REAL_CONST(0.000000000000000), REAL_CONST(0.000000000000000), REAL_CONST(0.000000000000000), REAL_CONST(0.000000000000000), REAL_CONST(0.000000000000000), REAL_CONST(0.000000000000000), REAL_CONST(0.000000171982634), REAL_CONST(0.000000171982634), REAL_CONST(0.000000171982634), REAL_CONST(0.000000171982634), REAL_CONST(0.000000171982634), REAL_CONST(0.000000171982634) }
+};
+
+static const real_t log_Qplus1[31] = {
+ REAL_CONST(6.022367813028454), REAL_CONST(5.044394119358453), REAL_CONST(4.087462841250339),
+ REAL_CONST(3.169925001442313), REAL_CONST(2.321928094887362), REAL_CONST(1.584962500721156),
+ REAL_CONST(1.000000000000000), REAL_CONST(0.584962500721156), REAL_CONST(0.321928094887362),
+ REAL_CONST(0.169925001442312), REAL_CONST(0.087462841250339), REAL_CONST(0.044394119358453),
+ REAL_CONST(0.022367813028455), REAL_CONST(0.011227255423254), REAL_CONST(0.005624549193878),
+ REAL_CONST(0.002815015607054), REAL_CONST(0.001408194392808), REAL_CONST(0.000704269011247),
+ REAL_CONST(0.000352177480301), REAL_CONST(0.000176099486443), REAL_CONST(0.000088052430122),
+ REAL_CONST(0.000044026886827), REAL_CONST(0.000022013611360), REAL_CONST(0.000011006847667),
+ REAL_CONST(0.000005503434331), REAL_CONST(0.000002751719790), REAL_CONST(0.000001375860551),
+ REAL_CONST(0.000000687930439), REAL_CONST(0.000000343965261), REAL_CONST(0.000000171982641),
+ REAL_CONST(0.000000000000000)
+};
+
+static real_t find_log2_Qplus1(sbr_info *sbr, uint8_t k, uint8_t l, uint8_t ch)
+{
+ /* check for coupled energy/noise data */
+ if (sbr->bs_coupling == 1) {
+ if ((sbr->Q[0][k][l] >= 0) && (sbr->Q[0][k][l] <= 30) &&
+ (sbr->Q[1][k][l] >= 0) && (sbr->Q[1][k][l] <= 24)) {
+ if (ch == 0) {
+ return log_Qplus1_pan[sbr->Q[0][k][l]][sbr->Q[1][k][l] >> 1];
+ } else {
+ return log_Qplus1_pan[sbr->Q[0][k][l]][12 - (sbr->Q[1][k][l] >> 1)];
+ }
+ } else {
+ return 0;
+ }
+ } else {
+ if (sbr->Q[ch][k][l] >= 0 && sbr->Q[ch][k][l] <= 30) {
+ return log_Qplus1[sbr->Q[ch][k][l]];
+ } else {
+ return 0;
+ }
+ }
+}
+
+static void calculate_gain(sbr_info *sbr, sbr_hfadj_info *adj, uint8_t ch)
+{
+ /* log2 values of limiter gains */
+ static real_t limGain[] = {
+ REAL_CONST(-1.0), REAL_CONST(0.0), REAL_CONST(1.0), REAL_CONST(33.219)
+ };
+ uint8_t m, l, k;
+
+ uint8_t current_t_noise_band = 0;
+ uint8_t S_mapped;
+
+ ALIGN real_t Q_M_lim[MAX_M];
+ ALIGN real_t G_lim[MAX_M];
+ ALIGN real_t G_boost;
+ ALIGN real_t S_M[MAX_M];
+
+
+ for (l = 0; l < sbr->L_E[ch]; l++) {
+ uint8_t current_f_noise_band = 0;
+ uint8_t current_res_band = 0;
+ uint8_t current_res_band2 = 0;
+ uint8_t current_hi_res_band = 0;
+
+ real_t delta = (l == sbr->l_A[ch] || l == sbr->prevEnvIsShort[ch]) ? 0 : 1;
+
+ S_mapped = get_S_mapped(sbr, ch, l, current_res_band2);
+
+ if (sbr->t_E[ch][l + 1] > sbr->t_Q[ch][current_t_noise_band + 1]) {
+ current_t_noise_band++;
+ }
+
+ for (k = 0; k < sbr->N_L[sbr->bs_limiter_bands]; k++) {
+ real_t Q_M = 0;
+ real_t G_max;
+ real_t den = 0;
+ real_t acc1 = 0;
+ real_t acc2 = 0;
+ uint8_t current_res_band_size = 0;
+ uint8_t Q_M_size = 0;
+
+ uint8_t ml1, ml2;
+
+ /* bounds of current limiter bands */
+ ml1 = sbr->f_table_lim[sbr->bs_limiter_bands][k];
+ ml2 = sbr->f_table_lim[sbr->bs_limiter_bands][k + 1];
+
+
+ /* calculate the accumulated E_orig and E_curr over the limiter band */
+ for (m = ml1; m < ml2; m++) {
+ if ((m + sbr->kx) < sbr->f_table_res[sbr->f[ch][l]][current_res_band + 1]) {
+ current_res_band_size++;
+ } else {
+ acc1 += pow2_int(-REAL_CONST(10) + log2_int_tab[current_res_band_size] + find_log2_E(sbr, current_res_band, l, ch));
+
+ current_res_band++;
+ current_res_band_size = 1;
+ }
+
+ acc2 += sbr->E_curr[ch][m][l];
+ }
+ acc1 += pow2_int(-REAL_CONST(10) + log2_int_tab[current_res_band_size] + find_log2_E(sbr, current_res_band, l, ch));
+
+
+ if (acc1 == 0) {
+ acc1 = LOG2_MIN_INF;
+ } else {
+ acc1 = log2_int(acc1);
+ }
+
+
+ /* calculate the maximum gain */
+ /* ratio of the energy of the original signal and the energy
+ * of the HF generated signal
+ */
+ G_max = acc1 - log2_int(acc2) + limGain[sbr->bs_limiter_gains];
+ G_max = min(G_max, limGain[3]);
+
+
+ for (m = ml1; m < ml2; m++) {
+ real_t G;
+ real_t E_curr, E_orig;
+ real_t Q_orig, Q_orig_plus1;
+ uint8_t S_index_mapped;
+
+
+ /* check if m is on a noise band border */
+ if ((m + sbr->kx) == sbr->f_table_noise[current_f_noise_band + 1]) {
+ /* step to next noise band */
+ current_f_noise_band++;
+ }
+
+
+ /* check if m is on a resolution band border */
+ if ((m + sbr->kx) == sbr->f_table_res[sbr->f[ch][l]][current_res_band2 + 1]) {
+ /* accumulate a whole range of equal Q_Ms */
+ if (Q_M_size > 0) {
+ den += pow2_int(log2_int_tab[Q_M_size] + Q_M);
+ }
+ Q_M_size = 0;
+
+ /* step to next resolution band */
+ current_res_band2++;
+
+ /* if we move to a new resolution band, we should check if we are
+ * going to add a sinusoid in this band
+ */
+ S_mapped = get_S_mapped(sbr, ch, l, current_res_band2);
+ }
+
+
+ /* check if m is on a HI_RES band border */
+ if ((m + sbr->kx) == sbr->f_table_res[HI_RES][current_hi_res_band + 1]) {
+ /* step to next HI_RES band */
+ current_hi_res_band++;
+ }
+
+
+ /* find S_index_mapped
+ * S_index_mapped can only be 1 for the m in the middle of the
+ * current HI_RES band
+ */
+ S_index_mapped = 0;
+ if ((l >= sbr->l_A[ch]) ||
+ (sbr->bs_add_harmonic_prev[ch][current_hi_res_band] && sbr->bs_add_harmonic_flag_prev[ch])) {
+ /* find the middle subband of the HI_RES frequency band */
+ if ((m + sbr->kx) == (sbr->f_table_res[HI_RES][current_hi_res_band + 1] + sbr->f_table_res[HI_RES][current_hi_res_band]) >> 1) {
+ S_index_mapped = sbr->bs_add_harmonic[ch][current_hi_res_band];
+ }
+ }
+
+
+ /* find bitstream parameters */
+ if (sbr->E_curr[ch][m][l] == 0) {
+ E_curr = LOG2_MIN_INF;
+ } else {
+ E_curr = log2_int(sbr->E_curr[ch][m][l]);
+ }
+ E_orig = -REAL_CONST(10) + find_log2_E(sbr, current_res_band2, l, ch);
+
+
+ Q_orig = find_log2_Q(sbr, current_f_noise_band, current_t_noise_band, ch);
+ Q_orig_plus1 = find_log2_Qplus1(sbr, current_f_noise_band, current_t_noise_band, ch);
+
+
+ /* Q_M only depends on E_orig and Q_div2:
+ * since N_Q <= N_Low <= N_High we only need to recalculate Q_M on
+ * a change of current res band (HI or LO)
+ */
+ Q_M = E_orig + Q_orig - Q_orig_plus1;
+
+
+ /* S_M only depends on E_orig, Q_div and S_index_mapped:
+ * S_index_mapped can only be non-zero once per HI_RES band
+ */
+ if (S_index_mapped == 0) {
+ S_M[m] = LOG2_MIN_INF; /* -inf */
+ } else {
+ S_M[m] = E_orig - Q_orig_plus1;
+
+ /* accumulate sinusoid part of the total energy */
+ den += pow2_int(S_M[m]);
+ }
+
+
+ /* calculate gain */
+ /* ratio of the energy of the original signal and the energy
+ * of the HF generated signal
+ */
+ /* E_curr here is officially E_curr+1 so the log2() of that can never be < 0 */
+ /* scaled by -10 */
+ G = E_orig - max(-REAL_CONST(10), E_curr);
+ if ((S_mapped == 0) && (delta == 1)) {
+ /* G = G * 1/(1+Q) */
+ G -= Q_orig_plus1;
+ } else if (S_mapped == 1) {
+ /* G = G * Q/(1+Q) */
+ G += Q_orig - Q_orig_plus1;
+ }
+
+
+ /* limit the additional noise energy level */
+ /* and apply the limiter */
+ if (G_max > G) {
+ Q_M_lim[m] = Q_M;
+ G_lim[m] = G;
+
+ if ((S_index_mapped == 0) && (l != sbr->l_A[ch])) {
+ Q_M_size++;
+ }
+ } else {
+ /* G > G_max */
+ Q_M_lim[m] = Q_M + G_max - G;
+ G_lim[m] = G_max;
+
+ /* accumulate limited Q_M */
+ if ((S_index_mapped == 0) && (l != sbr->l_A[ch])) {
+ den += pow2_int(Q_M_lim[m]);
+ }
+ }
+
+
+ /* accumulate the total energy */
+ /* E_curr changes for every m so we do need to accumulate every m */
+ den += pow2_int(E_curr + G_lim[m]);
+ }
+
+ /* accumulate last range of equal Q_Ms */
+ if (Q_M_size > 0) {
+ den += pow2_int(log2_int_tab[Q_M_size] + Q_M);
+ }
+
+
+ /* calculate the final gain */
+ /* G_boost: [0..2.51188643] */
+ G_boost = acc1 - log2_int(den /*+ EPS*/);
+ G_boost = min(G_boost, REAL_CONST(1.328771237) /* log2(1.584893192 ^ 2) */);
+
+
+ for (m = ml1; m < ml2; m++) {
+ /* apply compensation to gain, noise floor sf's and sinusoid levels */
+#ifndef SBR_LOW_POWER
+ adj->G_lim_boost[l][m] = pow2_fix((G_lim[m] + G_boost) >> 1);
+#else
+ /* sqrt() will be done after the aliasing reduction to save a
+ * few multiplies
+ */
+ adj->G_lim_boost[l][m] = pow2_fix(G_lim[m] + G_boost);
+#endif
+ adj->Q_M_lim_boost[l][m] = pow2_fix((Q_M_lim[m] + G_boost) >> 1);
+
+ if (S_M[m] != LOG2_MIN_INF) {
+ adj->S_M_boost[l][m] = pow2_int((S_M[m] + G_boost) >> 1);
+ } else {
+ adj->S_M_boost[l][m] = 0;
+ }
+ }
+ }
+ }
+}
+
+#else
+
+//#define LOG2_TEST
+
+#ifdef LOG2_TEST
+
+#define LOG2_MIN_INF -100000
+
+__inline float pow2(float val)
+{
+ return pow(2.0, val);
+}
+__inline float log2(float val)
+{
+ return log(val) / log(2.0);
+}
+
+#define RB 14
+
+float QUANTISE2REAL(float val)
+{
+ __int32 ival = (__int32)(val * (1 << RB));
+ return (float)ival / (float)((1 << RB));
+}
+
+float QUANTISE2INT(float val)
+{
+ return floor(val);
+}
+
+/* log2 values of [0..63] */
+static const real_t log2_int_tab[] = {
+ LOG2_MIN_INF, 0.000000000000000, 1.000000000000000, 1.584962500721156,
+ 2.000000000000000, 2.321928094887362, 2.584962500721156, 2.807354922057604,
+ 3.000000000000000, 3.169925001442313, 3.321928094887363, 3.459431618637297,
+ 3.584962500721156, 3.700439718141092, 3.807354922057604, 3.906890595608519,
+ 4.000000000000000, 4.087462841250339, 4.169925001442312, 4.247927513443585,
+ 4.321928094887362, 4.392317422778761, 4.459431618637297, 4.523561956057013,
+ 4.584962500721156, 4.643856189774724, 4.700439718141093, 4.754887502163468,
+ 4.807354922057604, 4.857980995127572, 4.906890595608519, 4.954196310386875,
+ 5.000000000000000, 5.044394119358453, 5.087462841250340, 5.129283016944966,
+ 5.169925001442312, 5.209453365628949, 5.247927513443585, 5.285402218862248,
+ 5.321928094887363, 5.357552004618084, 5.392317422778761, 5.426264754702098,
+ 5.459431618637297, 5.491853096329675, 5.523561956057013, 5.554588851677637,
+ 5.584962500721156, 5.614709844115208, 5.643856189774724, 5.672425341971495,
+ 5.700439718141093, 5.727920454563200, 5.754887502163469, 5.781359713524660,
+ 5.807354922057605, 5.832890014164742, 5.857980995127572, 5.882643049361842,
+ 5.906890595608518, 5.930737337562887, 5.954196310386876, 5.977279923499916
+};
+
+static const real_t pan_log2_tab[] = {
+ 1.000000000000000, 0.584962500721156, 0.321928094887362, 0.169925001442312, 0.087462841250339,
+ 0.044394119358453, 0.022367813028455, 0.011227255423254, 0.005624549193878, 0.002815015607054,
+ 0.001408194392808, 0.000704269011247, 0.000352177480301, 0.000176099486443, 0.000088052430122,
+ 0.000044026886827, 0.000022013611360, 0.000011006847667
+};
+
+static real_t find_log2_E(sbr_info *sbr, uint8_t k, uint8_t l, uint8_t ch)
+{
+ /* check for coupled energy/noise data */
+ if (sbr->bs_coupling == 1) {
+ real_t amp0 = (sbr->amp_res[0]) ? 1.0 : 0.5;
+ real_t amp1 = (sbr->amp_res[1]) ? 1.0 : 0.5;
+ float tmp = QUANTISE2REAL(7.0 + (real_t)sbr->E[0][k][l] * amp0);
+ float pan;
+
+ int E = (int)(sbr->E[1][k][l] * amp1);
+
+ if (ch == 0) {
+ if (E > 12) {
+ /* negative */
+ pan = QUANTISE2REAL(pan_log2_tab[-12 + E]);
+ } else {
+ /* positive */
+ pan = QUANTISE2REAL(pan_log2_tab[12 - E] + (12 - E));
+ }
+ } else {
+ if (E < 12) {
+ /* negative */
+ pan = QUANTISE2REAL(pan_log2_tab[-E + 12]);
+ } else {
+ /* positive */
+ pan = QUANTISE2REAL(pan_log2_tab[E - 12] + (E - 12));
+ }
+ }
+
+ /* tmp / pan in log2 */
+ return QUANTISE2REAL(tmp - pan);
+ } else {
+ real_t amp = (sbr->amp_res[ch]) ? 1.0 : 0.5;
+
+ return QUANTISE2REAL(6.0 + (real_t)sbr->E[ch][k][l] * amp);
+ }
+}
+
+static real_t find_log2_Q(sbr_info *sbr, uint8_t k, uint8_t l, uint8_t ch)
+{
+ /* check for coupled energy/noise data */
+ if (sbr->bs_coupling == 1) {
+ float tmp = QUANTISE2REAL(7.0 - (real_t)sbr->Q[0][k][l]);
+ float pan;
+
+ int Q = (int)(sbr->Q[1][k][l]);
+
+ if (ch == 0) {
+ if (Q > 12) {
+ /* negative */
+ pan = QUANTISE2REAL(pan_log2_tab[-12 + Q]);
+ } else {
+ /* positive */
+ pan = QUANTISE2REAL(pan_log2_tab[12 - Q] + (12 - Q));
+ }
+ } else {
+ if (Q < 12) {
+ /* negative */
+ pan = QUANTISE2REAL(pan_log2_tab[-Q + 12]);
+ } else {
+ /* positive */
+ pan = QUANTISE2REAL(pan_log2_tab[Q - 12] + (Q - 12));
+ }
+ }
+
+ /* tmp / pan in log2 */
+ return QUANTISE2REAL(tmp - pan);
+ } else {
+ return QUANTISE2REAL(6.0 - (real_t)sbr->Q[ch][k][l]);
+ }
+}
+
+static const real_t log_Qplus1_pan[31][13] = {
+ { REAL_CONST(0.044383447617292), REAL_CONST(0.169768601655960), REAL_CONST(0.583090126514435), REAL_CONST(1.570089221000671), REAL_CONST(3.092446088790894), REAL_CONST(4.733354568481445), REAL_CONST(6.022367954254150), REAL_CONST(6.692092418670654), REAL_CONST(6.924463272094727), REAL_CONST(6.989034175872803), REAL_CONST(7.005646705627441), REAL_CONST(7.009829998016357), REAL_CONST(7.010877609252930) },
+ { REAL_CONST(0.022362394258380), REAL_CONST(0.087379962205887), REAL_CONST(0.320804953575134), REAL_CONST(0.988859415054321), REAL_CONST(2.252387046813965), REAL_CONST(3.786596298217773), REAL_CONST(5.044394016265869), REAL_CONST(5.705977916717529), REAL_CONST(5.936291694641113), REAL_CONST(6.000346660614014), REAL_CONST(6.016829967498779), REAL_CONST(6.020981311798096), REAL_CONST(6.022020816802979) },
+ { REAL_CONST(0.011224525049329), REAL_CONST(0.044351425021887), REAL_CONST(0.169301137328148), REAL_CONST(0.577544987201691), REAL_CONST(1.527246952056885), REAL_CONST(2.887525320053101), REAL_CONST(4.087462902069092), REAL_CONST(4.733354568481445), REAL_CONST(4.959661006927490), REAL_CONST(5.022709369659424), REAL_CONST(5.038940429687500), REAL_CONST(5.043028831481934), REAL_CONST(5.044052600860596) },
+ { REAL_CONST(0.005623178556561), REAL_CONST(0.022346137091517), REAL_CONST(0.087132595479488), REAL_CONST(0.317482173442841), REAL_CONST(0.956931233406067), REAL_CONST(2.070389270782471), REAL_CONST(3.169924974441528), REAL_CONST(3.786596298217773), REAL_CONST(4.005294322967529), REAL_CONST(4.066420555114746), REAL_CONST(4.082170009613037), REAL_CONST(4.086137294769287), REAL_CONST(4.087131500244141) },
+ { REAL_CONST(0.002814328996465), REAL_CONST(0.011216334067285), REAL_CONST(0.044224001467228), REAL_CONST(0.167456731200218), REAL_CONST(0.556393325328827), REAL_CONST(1.378511548042297), REAL_CONST(2.321928024291992), REAL_CONST(2.887525320053101), REAL_CONST(3.092446088790894), REAL_CONST(3.150059700012207), REAL_CONST(3.164926528930664), REAL_CONST(3.168673276901245), REAL_CONST(3.169611930847168) },
+ { REAL_CONST(0.001407850766554), REAL_CONST(0.005619067233056), REAL_CONST(0.022281449288130), REAL_CONST(0.086156636476517), REAL_CONST(0.304854571819305), REAL_CONST(0.847996890544891), REAL_CONST(1.584962487220764), REAL_CONST(2.070389270782471), REAL_CONST(2.252387046813965), REAL_CONST(2.304061651229858), REAL_CONST(2.317430257797241), REAL_CONST(2.320801734924316), REAL_CONST(2.321646213531494) },
+ { REAL_CONST(0.000704097095877), REAL_CONST(0.002812269143760), REAL_CONST(0.011183738708496), REAL_CONST(0.043721374124289), REAL_CONST(0.160464659333229), REAL_CONST(0.485426813364029), REAL_CONST(1.000000000000000), REAL_CONST(1.378511548042297), REAL_CONST(1.527246952056885), REAL_CONST(1.570089221000671), REAL_CONST(1.581215262413025), REAL_CONST(1.584023833274841), REAL_CONST(1.584727644920349) },
+ { REAL_CONST(0.000352177477907), REAL_CONST(0.001406819908880), REAL_CONST(0.005602621007711), REAL_CONST(0.022026389837265), REAL_CONST(0.082462236285210), REAL_CONST(0.263034462928772), REAL_CONST(0.584962487220764), REAL_CONST(0.847996890544891), REAL_CONST(0.956931233406067), REAL_CONST(0.988859415054321), REAL_CONST(0.997190535068512), REAL_CONST(0.999296069145203), REAL_CONST(0.999823868274689) },
+ { REAL_CONST(0.000176099492819), REAL_CONST(0.000703581434209), REAL_CONST(0.002804030198604), REAL_CONST(0.011055230163038), REAL_CONST(0.041820213198662), REAL_CONST(0.137503549456596), REAL_CONST(0.321928083896637), REAL_CONST(0.485426813364029), REAL_CONST(0.556393325328827), REAL_CONST(0.577544987201691), REAL_CONST(0.583090126514435), REAL_CONST(0.584493279457092), REAL_CONST(0.584845066070557) },
+ { REAL_CONST(0.000088052431238), REAL_CONST(0.000351833587047), REAL_CONST(0.001402696361765), REAL_CONST(0.005538204684854), REAL_CONST(0.021061634644866), REAL_CONST(0.070389263331890), REAL_CONST(0.169925004243851), REAL_CONST(0.263034462928772), REAL_CONST(0.304854571819305), REAL_CONST(0.317482173442841), REAL_CONST(0.320804953575134), REAL_CONST(0.321646571159363), REAL_CONST(0.321857661008835) },
+ { REAL_CONST(0.000044026888645), REAL_CONST(0.000175927518285), REAL_CONST(0.000701518612914), REAL_CONST(0.002771759871393), REAL_CONST(0.010569252073765), REAL_CONST(0.035623874515295), REAL_CONST(0.087462842464447), REAL_CONST(0.137503549456596), REAL_CONST(0.160464659333229), REAL_CONST(0.167456731200218), REAL_CONST(0.169301137328148), REAL_CONST(0.169768601655960), REAL_CONST(0.169885858893394) },
+ { REAL_CONST(0.000022013611670), REAL_CONST(0.000088052431238), REAL_CONST(0.000350801943569), REAL_CONST(0.001386545598507), REAL_CONST(0.005294219125062), REAL_CONST(0.017921976745129), REAL_CONST(0.044394120573997), REAL_CONST(0.070389263331890), REAL_CONST(0.082462236285210), REAL_CONST(0.086156636476517), REAL_CONST(0.087132595479488), REAL_CONST(0.087379962205887), REAL_CONST(0.087442122399807) },
+ { REAL_CONST(0.000011006847672), REAL_CONST(0.000044026888645), REAL_CONST(0.000175411638338), REAL_CONST(0.000693439331371), REAL_CONST(0.002649537986144), REAL_CONST(0.008988817222416), REAL_CONST(0.022367812693119), REAL_CONST(0.035623874515295), REAL_CONST(0.041820213198662), REAL_CONST(0.043721374124289), REAL_CONST(0.044224001467228), REAL_CONST(0.044351425021887), REAL_CONST(0.044383447617292) },
+ { REAL_CONST(0.000005503434295), REAL_CONST(0.000022013611670), REAL_CONST(0.000087708482170), REAL_CONST(0.000346675369656), REAL_CONST(0.001325377263129), REAL_CONST(0.004501323681325), REAL_CONST(0.011227255687118), REAL_CONST(0.017921976745129), REAL_CONST(0.021061634644866), REAL_CONST(0.022026389837265), REAL_CONST(0.022281449288130), REAL_CONST(0.022346137091517), REAL_CONST(0.022362394258380) },
+ { REAL_CONST(0.000002751719876), REAL_CONST(0.000011006847672), REAL_CONST(0.000043854910473), REAL_CONST(0.000173348103999), REAL_CONST(0.000662840844598), REAL_CONST(0.002252417383716), REAL_CONST(0.005624548997730), REAL_CONST(0.008988817222416), REAL_CONST(0.010569252073765), REAL_CONST(0.011055230163038), REAL_CONST(0.011183738708496), REAL_CONST(0.011216334067285), REAL_CONST(0.011224525049329) },
+ { REAL_CONST(0.000001375860506), REAL_CONST(0.000005503434295), REAL_CONST(0.000022013611670), REAL_CONST(0.000086676649516), REAL_CONST(0.000331544462824), REAL_CONST(0.001126734190620), REAL_CONST(0.002815015614033), REAL_CONST(0.004501323681325), REAL_CONST(0.005294219125062), REAL_CONST(0.005538204684854), REAL_CONST(0.005602621007711), REAL_CONST(0.005619067233056), REAL_CONST(0.005623178556561) },
+ { REAL_CONST(0.000000687930424), REAL_CONST(0.000002751719876), REAL_CONST(0.000011006847672), REAL_CONST(0.000043338975956), REAL_CONST(0.000165781748365), REAL_CONST(0.000563477107789), REAL_CONST(0.001408194424585), REAL_CONST(0.002252417383716), REAL_CONST(0.002649537986144), REAL_CONST(0.002771759871393), REAL_CONST(0.002804030198604), REAL_CONST(0.002812269143760), REAL_CONST(0.002814328996465) },
+ { REAL_CONST(0.000000343965269), REAL_CONST(0.000001375860506), REAL_CONST(0.000005503434295), REAL_CONST(0.000021669651687), REAL_CONST(0.000082893253420), REAL_CONST(0.000281680084299), REAL_CONST(0.000704268983100), REAL_CONST(0.001126734190620), REAL_CONST(0.001325377263129), REAL_CONST(0.001386545598507), REAL_CONST(0.001402696361765), REAL_CONST(0.001406819908880), REAL_CONST(0.001407850766554) },
+ { REAL_CONST(0.000000171982634), REAL_CONST(0.000000687930424), REAL_CONST(0.000002751719876), REAL_CONST(0.000010834866771), REAL_CONST(0.000041447223339), REAL_CONST(0.000140846910654), REAL_CONST(0.000352177477907), REAL_CONST(0.000563477107789), REAL_CONST(0.000662840844598), REAL_CONST(0.000693439331371), REAL_CONST(0.000701518612914), REAL_CONST(0.000703581434209), REAL_CONST(0.000704097095877) },
+ { REAL_CONST(0.000000000000000), REAL_CONST(0.000000343965269), REAL_CONST(0.000001375860506), REAL_CONST(0.000005503434295), REAL_CONST(0.000020637769921), REAL_CONST(0.000070511166996), REAL_CONST(0.000176099492819), REAL_CONST(0.000281680084299), REAL_CONST(0.000331544462824), REAL_CONST(0.000346675369656), REAL_CONST(0.000350801943569), REAL_CONST(0.000351833587047), REAL_CONST(0.000352177477907) },
+ { REAL_CONST(0.000000000000000), REAL_CONST(0.000000171982634), REAL_CONST(0.000000687930424), REAL_CONST(0.000002751719876), REAL_CONST(0.000010318922250), REAL_CONST(0.000035256012779), REAL_CONST(0.000088052431238), REAL_CONST(0.000140846910654), REAL_CONST(0.000165781748365), REAL_CONST(0.000173348103999), REAL_CONST(0.000175411638338), REAL_CONST(0.000175927518285), REAL_CONST(0.000176099492819) },
+ { REAL_CONST(0.000000000000000), REAL_CONST(0.000000000000000), REAL_CONST(0.000000343965269), REAL_CONST(0.000001375860506), REAL_CONST(0.000005159470220), REAL_CONST(0.000017542124624), REAL_CONST(0.000044026888645), REAL_CONST(0.000070511166996), REAL_CONST(0.000082893253420), REAL_CONST(0.000086676649516), REAL_CONST(0.000087708482170), REAL_CONST(0.000088052431238), REAL_CONST(0.000088052431238) },
+ { REAL_CONST(0.000000000000000), REAL_CONST(0.000000000000000), REAL_CONST(0.000000171982634), REAL_CONST(0.000000687930424), REAL_CONST(0.000002579737384), REAL_CONST(0.000008771088687), REAL_CONST(0.000022013611670), REAL_CONST(0.000035256012779), REAL_CONST(0.000041447223339), REAL_CONST(0.000043338975956), REAL_CONST(0.000043854910473), REAL_CONST(0.000044026888645), REAL_CONST(0.000044026888645) },
+ { REAL_CONST(0.000000000000000), REAL_CONST(0.000000000000000), REAL_CONST(0.000000000000000), REAL_CONST(0.000000343965269), REAL_CONST(0.000001375860506), REAL_CONST(0.000004471542070), REAL_CONST(0.000011006847672), REAL_CONST(0.000017542124624), REAL_CONST(0.000020637769921), REAL_CONST(0.000021669651687), REAL_CONST(0.000022013611670), REAL_CONST(0.000022013611670), REAL_CONST(0.000022013611670) },
+ { REAL_CONST(0.000000000000000), REAL_CONST(0.000000000000000), REAL_CONST(0.000000000000000), REAL_CONST(0.000000171982634), REAL_CONST(0.000000687930424), REAL_CONST(0.000002235772627), REAL_CONST(0.000005503434295), REAL_CONST(0.000008771088687), REAL_CONST(0.000010318922250), REAL_CONST(0.000010834866771), REAL_CONST(0.000011006847672), REAL_CONST(0.000011006847672), REAL_CONST(0.000011006847672) },
+ { REAL_CONST(0.000000000000000), REAL_CONST(0.000000000000000), REAL_CONST(0.000000000000000), REAL_CONST(0.000000000000000), REAL_CONST(0.000000343965269), REAL_CONST(0.000001031895522), REAL_CONST(0.000002751719876), REAL_CONST(0.000004471542070), REAL_CONST(0.000005159470220), REAL_CONST(0.000005503434295), REAL_CONST(0.000005503434295), REAL_CONST(0.000005503434295), REAL_CONST(0.000005503434295) },
+ { REAL_CONST(0.000000000000000), REAL_CONST(0.000000000000000), REAL_CONST(0.000000000000000), REAL_CONST(0.000000000000000), REAL_CONST(0.000000171982634), REAL_CONST(0.000000515947875), REAL_CONST(0.000001375860506), REAL_CONST(0.000002235772627), REAL_CONST(0.000002579737384), REAL_CONST(0.000002751719876), REAL_CONST(0.000002751719876), REAL_CONST(0.000002751719876), REAL_CONST(0.000002751719876) },
+ { REAL_CONST(0.000000000000000), REAL_CONST(0.000000000000000), REAL_CONST(0.000000000000000), REAL_CONST(0.000000000000000), REAL_CONST(0.000000000000000), REAL_CONST(0.000000343965269), REAL_CONST(0.000000687930424), REAL_CONST(0.000001031895522), REAL_CONST(0.000001375860506), REAL_CONST(0.000001375860506), REAL_CONST(0.000001375860506), REAL_CONST(0.000001375860506), REAL_CONST(0.000001375860506) },
+ { REAL_CONST(0.000000000000000), REAL_CONST(0.000000000000000), REAL_CONST(0.000000000000000), REAL_CONST(0.000000000000000), REAL_CONST(0.000000000000000), REAL_CONST(0.000000171982634), REAL_CONST(0.000000343965269), REAL_CONST(0.000000515947875), REAL_CONST(0.000000687930424), REAL_CONST(0.000000687930424), REAL_CONST(0.000000687930424), REAL_CONST(0.000000687930424), REAL_CONST(0.000000687930424) },
+ { REAL_CONST(0.000000000000000), REAL_CONST(0.000000000000000), REAL_CONST(0.000000000000000), REAL_CONST(0.000000000000000), REAL_CONST(0.000000000000000), REAL_CONST(0.000000000000000), REAL_CONST(0.000000171982634), REAL_CONST(0.000000343965269), REAL_CONST(0.000000343965269), REAL_CONST(0.000000343965269), REAL_CONST(0.000000343965269), REAL_CONST(0.000000343965269), REAL_CONST(0.000000343965269) },
+ { REAL_CONST(0.000000000000000), REAL_CONST(0.000000000000000), REAL_CONST(0.000000000000000), REAL_CONST(0.000000000000000), REAL_CONST(0.000000000000000), REAL_CONST(0.000000000000000), REAL_CONST(0.000000000000000), REAL_CONST(0.000000171982634), REAL_CONST(0.000000171982634), REAL_CONST(0.000000171982634), REAL_CONST(0.000000171982634), REAL_CONST(0.000000171982634), REAL_CONST(0.000000171982634) }
+};
+
+static const real_t log_Qplus1[31] = {
+ REAL_CONST(6.022367813028454), REAL_CONST(5.044394119358453), REAL_CONST(4.087462841250339),
+ REAL_CONST(3.169925001442313), REAL_CONST(2.321928094887362), REAL_CONST(1.584962500721156),
+ REAL_CONST(1.000000000000000), REAL_CONST(0.584962500721156), REAL_CONST(0.321928094887362),
+ REAL_CONST(0.169925001442312), REAL_CONST(0.087462841250339), REAL_CONST(0.044394119358453),
+ REAL_CONST(0.022367813028455), REAL_CONST(0.011227255423254), REAL_CONST(0.005624549193878),
+ REAL_CONST(0.002815015607054), REAL_CONST(0.001408194392808), REAL_CONST(0.000704269011247),
+ REAL_CONST(0.000352177480301), REAL_CONST(0.000176099486443), REAL_CONST(0.000088052430122),
+ REAL_CONST(0.000044026886827), REAL_CONST(0.000022013611360), REAL_CONST(0.000011006847667),
+ REAL_CONST(0.000005503434331), REAL_CONST(0.000002751719790), REAL_CONST(0.000001375860551),
+ REAL_CONST(0.000000687930439), REAL_CONST(0.000000343965261), REAL_CONST(0.000000171982641),
+ REAL_CONST(0.000000000000000)
+};
+
+static real_t find_log2_Qplus1(sbr_info *sbr, uint8_t k, uint8_t l, uint8_t ch)
+{
+ /* check for coupled energy/noise data */
+ if (sbr->bs_coupling == 1) {
+ if ((sbr->Q[0][k][l] >= 0) && (sbr->Q[0][k][l] <= 30) &&
+ (sbr->Q[1][k][l] >= 0) && (sbr->Q[1][k][l] <= 24)) {
+ if (ch == 0) {
+ return QUANTISE2REAL(log_Qplus1_pan[sbr->Q[0][k][l]][sbr->Q[1][k][l] >> 1]);
+ } else {
+ return QUANTISE2REAL(log_Qplus1_pan[sbr->Q[0][k][l]][12 - (sbr->Q[1][k][l] >> 1)]);
+ }
+ } else {
+ return 0;
+ }
+ } else {
+ if (sbr->Q[ch][k][l] >= 0 && sbr->Q[ch][k][l] <= 30) {
+ return QUANTISE2REAL(log_Qplus1[sbr->Q[ch][k][l]]);
+ } else {
+ return 0;
+ }
+ }
+}
+
+static void calculate_gain(sbr_info *sbr, sbr_hfadj_info *adj, uint8_t ch)
+{
+ /* log2 values of limiter gains */
+ static real_t limGain[] = { -1.0, 0.0, 1.0, 33.219 };
+ uint8_t m, l, k;
+
+ uint8_t current_t_noise_band = 0;
+ uint8_t S_mapped;
+
+ ALIGN real_t Q_M_lim[MAX_M];
+ ALIGN real_t G_lim[MAX_M];
+ ALIGN real_t G_boost;
+ ALIGN real_t S_M[MAX_M];
+
+
+ for (l = 0; l < sbr->L_E[ch]; l++) {
+ uint8_t current_f_noise_band = 0;
+ uint8_t current_res_band = 0;
+ uint8_t current_res_band2 = 0;
+ uint8_t current_hi_res_band = 0;
+
+ real_t delta = (l == sbr->l_A[ch] || l == sbr->prevEnvIsShort[ch]) ? 0 : 1;
+
+ S_mapped = get_S_mapped(sbr, ch, l, current_res_band2);
+
+ if (sbr->t_E[ch][l + 1] > sbr->t_Q[ch][current_t_noise_band + 1]) {
+ current_t_noise_band++;
+ }
+
+ for (k = 0; k < sbr->N_L[sbr->bs_limiter_bands]; k++) {
+ real_t Q_M = 0;
+ real_t G_max;
+ real_t den = 0;
+ real_t acc1 = 0;
+ real_t acc2 = 0;
+ uint8_t current_res_band_size = 0;
+ uint8_t Q_M_size = 0;
+
+ uint8_t ml1, ml2;
+
+ /* bounds of current limiter bands */
+ ml1 = sbr->f_table_lim[sbr->bs_limiter_bands][k];
+ ml2 = sbr->f_table_lim[sbr->bs_limiter_bands][k + 1];
+
+
+ /* calculate the accumulated E_orig and E_curr over the limiter band */
+ for (m = ml1; m < ml2; m++) {
+ if ((m + sbr->kx) < sbr->f_table_res[sbr->f[ch][l]][current_res_band + 1]) {
+ current_res_band_size++;
+ } else {
+ acc1 += QUANTISE2INT(pow2(-10 + log2_int_tab[current_res_band_size] + find_log2_E(sbr, current_res_band, l, ch)));
+
+ current_res_band++;
+ current_res_band_size = 1;
+ }
+
+ acc2 += QUANTISE2INT(sbr->E_curr[ch][m][l] / 1024.0);
+ }
+ acc1 += QUANTISE2INT(pow2(-10 + log2_int_tab[current_res_band_size] + find_log2_E(sbr, current_res_band, l, ch)));
+
+ acc1 = QUANTISE2REAL(log2(EPS + acc1));
+
+
+ /* calculate the maximum gain */
+ /* ratio of the energy of the original signal and the energy
+ * of the HF generated signal
+ */
+ G_max = acc1 - QUANTISE2REAL(log2(EPS + acc2)) + QUANTISE2REAL(limGain[sbr->bs_limiter_gains]);
+ G_max = min(G_max, QUANTISE2REAL(limGain[3]));
+
+
+ for (m = ml1; m < ml2; m++) {
+ real_t G;
+ real_t E_curr, E_orig;
+ real_t Q_orig, Q_orig_plus1;
+ uint8_t S_index_mapped;
+
+
+ /* check if m is on a noise band border */
+ if ((m + sbr->kx) == sbr->f_table_noise[current_f_noise_band + 1]) {
+ /* step to next noise band */
+ current_f_noise_band++;
+ }
+
+
+ /* check if m is on a resolution band border */
+ if ((m + sbr->kx) == sbr->f_table_res[sbr->f[ch][l]][current_res_band2 + 1]) {
+ /* accumulate a whole range of equal Q_Ms */
+ if (Q_M_size > 0) {
+ den += QUANTISE2INT(pow2(log2_int_tab[Q_M_size] + Q_M));
+ }
+ Q_M_size = 0;
+
+ /* step to next resolution band */
+ current_res_band2++;
+
+ /* if we move to a new resolution band, we should check if we are
+ * going to add a sinusoid in this band
+ */
+ S_mapped = get_S_mapped(sbr, ch, l, current_res_band2);
+ }
+
+
+ /* check if m is on a HI_RES band border */
+ if ((m + sbr->kx) == sbr->f_table_res[HI_RES][current_hi_res_band + 1]) {
+ /* step to next HI_RES band */
+ current_hi_res_band++;
+ }
+
+
+ /* find S_index_mapped
+ * S_index_mapped can only be 1 for the m in the middle of the
+ * current HI_RES band
+ */
+ S_index_mapped = 0;
+ if ((l >= sbr->l_A[ch]) ||
+ (sbr->bs_add_harmonic_prev[ch][current_hi_res_band] && sbr->bs_add_harmonic_flag_prev[ch])) {
+ /* find the middle subband of the HI_RES frequency band */
+ if ((m + sbr->kx) == (sbr->f_table_res[HI_RES][current_hi_res_band + 1] + sbr->f_table_res[HI_RES][current_hi_res_band]) >> 1) {
+ S_index_mapped = sbr->bs_add_harmonic[ch][current_hi_res_band];
+ }
+ }
+
+
+ /* find bitstream parameters */
+ if (sbr->E_curr[ch][m][l] == 0) {
+ E_curr = LOG2_MIN_INF;
+ } else {
+ E_curr = -10 + log2(sbr->E_curr[ch][m][l]);
+ }
+ E_orig = -10 + find_log2_E(sbr, current_res_band2, l, ch);
+
+ Q_orig = find_log2_Q(sbr, current_f_noise_band, current_t_noise_band, ch);
+ Q_orig_plus1 = find_log2_Qplus1(sbr, current_f_noise_band, current_t_noise_band, ch);
+
+
+ /* Q_M only depends on E_orig and Q_div2:
+ * since N_Q <= N_Low <= N_High we only need to recalculate Q_M on
+ * a change of current res band (HI or LO)
+ */
+ Q_M = E_orig + Q_orig - Q_orig_plus1;
+
+
+ /* S_M only depends on E_orig, Q_div and S_index_mapped:
+ * S_index_mapped can only be non-zero once per HI_RES band
+ */
+ if (S_index_mapped == 0) {
+ S_M[m] = LOG2_MIN_INF; /* -inf */
+ } else {
+ S_M[m] = E_orig - Q_orig_plus1;
+
+ /* accumulate sinusoid part of the total energy */
+ den += pow2(S_M[m]);
+ }
+
+
+ /* calculate gain */
+ /* ratio of the energy of the original signal and the energy
+ * of the HF generated signal
+ */
+ /* E_curr here is officially E_curr+1 so the log2() of that can never be < 0 */
+ /* scaled by -10 */
+ G = E_orig - max(-10, E_curr);
+ if ((S_mapped == 0) && (delta == 1)) {
+ /* G = G * 1/(1+Q) */
+ G -= Q_orig_plus1;
+ } else if (S_mapped == 1) {
+ /* G = G * Q/(1+Q) */
+ G += Q_orig - Q_orig_plus1;
+ }
+
+
+ /* limit the additional noise energy level */
+ /* and apply the limiter */
+ if (G_max > G) {
+ Q_M_lim[m] = QUANTISE2REAL(Q_M);
+ G_lim[m] = QUANTISE2REAL(G);
+
+ if ((S_index_mapped == 0) && (l != sbr->l_A[ch])) {
+ Q_M_size++;
+ }
+ } else {
+ /* G > G_max */
+ Q_M_lim[m] = QUANTISE2REAL(Q_M) + G_max - QUANTISE2REAL(G);
+ G_lim[m] = G_max;
+
+ /* accumulate limited Q_M */
+ if ((S_index_mapped == 0) && (l != sbr->l_A[ch])) {
+ den += QUANTISE2INT(pow2(Q_M_lim[m]));
+ }
+ }
+
+
+ /* accumulate the total energy */
+ /* E_curr changes for every m so we do need to accumulate every m */
+ den += QUANTISE2INT(pow2(E_curr + G_lim[m]));
+ }
+
+ /* accumulate last range of equal Q_Ms */
+ if (Q_M_size > 0) {
+ den += QUANTISE2INT(pow2(log2_int_tab[Q_M_size] + Q_M));
+ }
+
+
+ /* calculate the final gain */
+ /* G_boost: [0..2.51188643] */
+ G_boost = acc1 - QUANTISE2REAL(log2(den + EPS));
+ G_boost = min(G_boost, QUANTISE2REAL(1.328771237) /* log2(1.584893192 ^ 2) */);
+
+
+ for (m = ml1; m < ml2; m++) {
+ /* apply compensation to gain, noise floor sf's and sinusoid levels */
+#ifndef SBR_LOW_POWER
+ adj->G_lim_boost[l][m] = QUANTISE2REAL(pow2((G_lim[m] + G_boost) / 2.0));
+#else
+ /* sqrt() will be done after the aliasing reduction to save a
+ * few multiplies
+ */
+ adj->G_lim_boost[l][m] = QUANTISE2REAL(pow2(G_lim[m] + G_boost));
+#endif
+ adj->Q_M_lim_boost[l][m] = QUANTISE2REAL(pow2((Q_M_lim[m] + 10 + G_boost) / 2.0));
+
+ if (S_M[m] != LOG2_MIN_INF) {
+ adj->S_M_boost[l][m] = QUANTISE2REAL(pow2((S_M[m] + 10 + G_boost) / 2.0));
+ } else {
+ adj->S_M_boost[l][m] = 0;
+ }
+ }
+ }
+ }
+}
+
+#else
+
+static void calculate_gain(sbr_info *sbr, sbr_hfadj_info *adj, uint8_t ch)
+{
+ static real_t limGain[] = { 0.5, 1.0, 2.0, 1e10 };
+ uint8_t m, l, k;
+
+ uint8_t current_t_noise_band = 0;
+ uint8_t S_mapped;
+
+ ALIGN real_t Q_M_lim[MAX_M];
+ ALIGN real_t G_lim[MAX_M];
+ ALIGN real_t G_boost;
+ ALIGN real_t S_M[MAX_M];
+
+ for (l = 0; l < sbr->L_E[ch]; l++) {
+ uint8_t current_f_noise_band = 0;
+ uint8_t current_res_band = 0;
+ uint8_t current_res_band2 = 0;
+ uint8_t current_hi_res_band = 0;
+
+ real_t delta = (l == sbr->l_A[ch] || l == sbr->prevEnvIsShort[ch]) ? 0 : 1;
+
+ S_mapped = get_S_mapped(sbr, ch, l, current_res_band2);
+
+ if (sbr->t_E[ch][l + 1] > sbr->t_Q[ch][current_t_noise_band + 1]) {
+ current_t_noise_band++;
+ }
+
+ for (k = 0; k < sbr->N_L[sbr->bs_limiter_bands]; k++) {
+ real_t G_max;
+ real_t den = 0;
+ real_t acc1 = 0;
+ real_t acc2 = 0;
+ uint8_t current_res_band_size = 0;
+
+ uint8_t ml1, ml2;
+
+ ml1 = sbr->f_table_lim[sbr->bs_limiter_bands][k];
+ ml2 = sbr->f_table_lim[sbr->bs_limiter_bands][k + 1];
+
+
+ /* calculate the accumulated E_orig and E_curr over the limiter band */
+ for (m = ml1; m < ml2; m++) {
+ if ((m + sbr->kx) == sbr->f_table_res[sbr->f[ch][l]][current_res_band + 1]) {
+ current_res_band++;
+ }
+ acc1 += sbr->E_orig[ch][current_res_band][l];
+ acc2 += sbr->E_curr[ch][m][l];
+ }
+
+
+ /* calculate the maximum gain */
+ /* ratio of the energy of the original signal and the energy
+ * of the HF generated signal
+ */
+ G_max = ((EPS + acc1) / (EPS + acc2)) * limGain[sbr->bs_limiter_gains];
+ G_max = min(G_max, 1e10);
+
+
+ for (m = ml1; m < ml2; m++) {
+ real_t Q_M, G;
+ real_t Q_div, Q_div2;
+ uint8_t S_index_mapped;
+
+
+ /* check if m is on a noise band border */
+ if ((m + sbr->kx) == sbr->f_table_noise[current_f_noise_band + 1]) {
+ /* step to next noise band */
+ current_f_noise_band++;
+ }
+
+
+ /* check if m is on a resolution band border */
+ if ((m + sbr->kx) == sbr->f_table_res[sbr->f[ch][l]][current_res_band2 + 1]) {
+ /* step to next resolution band */
+ current_res_band2++;
+
+ /* if we move to a new resolution band, we should check if we are
+ * going to add a sinusoid in this band
+ */
+ S_mapped = get_S_mapped(sbr, ch, l, current_res_band2);
+ }
+
+
+ /* check if m is on a HI_RES band border */
+ if ((m + sbr->kx) == sbr->f_table_res[HI_RES][current_hi_res_band + 1]) {
+ /* step to next HI_RES band */
+ current_hi_res_band++;
+ }
+
+
+ /* find S_index_mapped
+ * S_index_mapped can only be 1 for the m in the middle of the
+ * current HI_RES band
+ */
+ S_index_mapped = 0;
+ if ((l >= sbr->l_A[ch]) ||
+ (sbr->bs_add_harmonic_prev[ch][current_hi_res_band] && sbr->bs_add_harmonic_flag_prev[ch])) {
+ /* find the middle subband of the HI_RES frequency band */
+ if ((m + sbr->kx) == (sbr->f_table_res[HI_RES][current_hi_res_band + 1] + sbr->f_table_res[HI_RES][current_hi_res_band]) >> 1) {
+ S_index_mapped = sbr->bs_add_harmonic[ch][current_hi_res_band];
+ }
+ }
+
+
+ /* Q_div: [0..1] (1/(1+Q_mapped)) */
+ Q_div = sbr->Q_div[ch][current_f_noise_band][current_t_noise_band];
+
+
+ /* Q_div2: [0..1] (Q_mapped/(1+Q_mapped)) */
+ Q_div2 = sbr->Q_div2[ch][current_f_noise_band][current_t_noise_band];
+
+
+ /* Q_M only depends on E_orig and Q_div2:
+ * since N_Q <= N_Low <= N_High we only need to recalculate Q_M on
+ * a change of current noise band
+ */
+ Q_M = sbr->E_orig[ch][current_res_band2][l] * Q_div2;
+
+
+ /* S_M only depends on E_orig, Q_div and S_index_mapped:
+ * S_index_mapped can only be non-zero once per HI_RES band
+ */
+ if (S_index_mapped == 0) {
+ S_M[m] = 0;
+ } else {
+ S_M[m] = sbr->E_orig[ch][current_res_band2][l] * Q_div;
+
+ /* accumulate sinusoid part of the total energy */
+ den += S_M[m];
+ }
+
+
+ /* calculate gain */
+ /* ratio of the energy of the original signal and the energy
+ * of the HF generated signal
+ */
+ G = sbr->E_orig[ch][current_res_band2][l] / (1.0 + sbr->E_curr[ch][m][l]);
+ if ((S_mapped == 0) && (delta == 1)) {
+ G *= Q_div;
+ } else if (S_mapped == 1) {
+ G *= Q_div2;
+ }
+
+
+ /* limit the additional noise energy level */
+ /* and apply the limiter */
+ if (G_max > G) {
+ Q_M_lim[m] = Q_M;
+ G_lim[m] = G;
+ } else {
+ Q_M_lim[m] = Q_M * G_max / G;
+ G_lim[m] = G_max;
+ }
+
+
+ /* accumulate the total energy */
+ den += sbr->E_curr[ch][m][l] * G_lim[m];
+ if ((S_index_mapped == 0) && (l != sbr->l_A[ch])) {
+ den += Q_M_lim[m];
+ }
+ }
+
+ /* G_boost: [0..2.51188643] */
+ G_boost = (acc1 + EPS) / (den + EPS);
+ G_boost = min(G_boost, 2.51188643 /* 1.584893192 ^ 2 */);
+
+ for (m = ml1; m < ml2; m++) {
+ /* apply compensation to gain, noise floor sf's and sinusoid levels */
+#ifndef SBR_LOW_POWER
+ adj->G_lim_boost[l][m] = sqrt(G_lim[m] * G_boost);
+#else
+ /* sqrt() will be done after the aliasing reduction to save a
+ * few multiplies
+ */
+ adj->G_lim_boost[l][m] = G_lim[m] * G_boost;
+#endif
+ adj->Q_M_lim_boost[l][m] = sqrt(Q_M_lim[m] * G_boost);
+
+ if (S_M[m] != 0) {
+ adj->S_M_boost[l][m] = sqrt(S_M[m] * G_boost);
+ } else {
+ adj->S_M_boost[l][m] = 0;
+ }
+ }
+ }
+ }
+}
+#endif // log2_test
+
+#endif
+
+#ifdef SBR_LOW_POWER
+static void calc_gain_groups(sbr_info *sbr, sbr_hfadj_info *adj, real_t *deg, uint8_t ch)
+{
+ uint8_t l, k, i;
+ uint8_t grouping;
+ uint8_t S_mapped;
+
+ for (l = 0; l < sbr->L_E[ch]; l++) {
+ uint8_t current_res_band = 0;
+ i = 0;
+ grouping = 0;
+
+ S_mapped = get_S_mapped(sbr, ch, l, current_res_band);
+
+ for (k = sbr->kx; k < sbr->kx + sbr->M - 1; k++) {
+ if (k == sbr->f_table_res[sbr->f[ch][l]][current_res_band + 1]) {
+ /* step to next resolution band */
+ current_res_band++;
+
+ S_mapped = get_S_mapped(sbr, ch, l, current_res_band);
+ }
+
+ if (deg[k + 1] && S_mapped == 0) {
+ if (grouping == 0) {
+ sbr->f_group[l][i] = k;
+ grouping = 1;
+ i++;
+ }
+ } else {
+ if (grouping) {
+ if (S_mapped) {
+ sbr->f_group[l][i] = k;
+ } else {
+ sbr->f_group[l][i] = k + 1;
+ }
+ grouping = 0;
+ i++;
+ }
+ }
+ }
+
+ if (grouping) {
+ sbr->f_group[l][i] = sbr->kx + sbr->M;
+ i++;
+ }
+
+ sbr->N_G[l] = (uint8_t)(i >> 1);
+ }
+}
+
+static void aliasing_reduction(sbr_info *sbr, sbr_hfadj_info *adj, real_t *deg, uint8_t ch)
+{
+ uint8_t l, k, m;
+ real_t E_total, E_total_est, G_target, acc;
+
+ for (l = 0; l < sbr->L_E[ch]; l++) {
+ for (k = 0; k < sbr->N_G[l]; k++) {
+ E_total_est = E_total = 0;
+
+ for (m = sbr->f_group[l][k << 1]; m < sbr->f_group[l][(k << 1) + 1]; m++) {
+ /* E_curr: integer */
+ /* G_lim_boost: fixed point */
+ /* E_total_est: integer */
+ /* E_total: integer */
+ E_total_est += sbr->E_curr[ch][m - sbr->kx][l];
+#ifdef FIXED_POINT
+ E_total += MUL_Q2(sbr->E_curr[ch][m - sbr->kx][l], adj->G_lim_boost[l][m - sbr->kx]);
+#else
+ E_total += sbr->E_curr[ch][m - sbr->kx][l] * adj->G_lim_boost[l][m - sbr->kx];
+#endif
+ }
+
+ /* G_target: fixed point */
+ if ((E_total_est + EPS) == 0) {
+ G_target = 0;
+ } else {
+#ifdef FIXED_POINT
+ G_target = (((int64_t)(E_total)) << Q2_BITS) / (E_total_est + EPS);
+#else
+ G_target = E_total / (E_total_est + EPS);
+#endif
+ }
+ acc = 0;
+
+ for (m = sbr->f_group[l][(k << 1)]; m < sbr->f_group[l][(k << 1) + 1]; m++) {
+ real_t alpha;
+
+ /* alpha: (COEF) fixed point */
+ if (m < sbr->kx + sbr->M - 1) {
+ alpha = max(deg[m], deg[m + 1]);
+ } else {
+ alpha = deg[m];
+ }
+
+ adj->G_lim_boost[l][m - sbr->kx] = MUL_C(alpha, G_target) +
+ MUL_C((COEF_CONST(1) - alpha), adj->G_lim_boost[l][m - sbr->kx]);
+
+ /* acc: integer */
+#ifdef FIXED_POINT
+ acc += MUL_Q2(adj->G_lim_boost[l][m - sbr->kx], sbr->E_curr[ch][m - sbr->kx][l]);
+#else
+ acc += adj->G_lim_boost[l][m - sbr->kx] * sbr->E_curr[ch][m - sbr->kx][l];
+#endif
+ }
+
+ /* acc: fixed point */
+ if (acc + EPS == 0) {
+ acc = 0;
+ } else {
+#ifdef FIXED_POINT
+ acc = (((int64_t)(E_total)) << Q2_BITS) / (acc + EPS);
+#else
+ acc = E_total / (acc + EPS);
+#endif
+ }
+ for (m = sbr->f_group[l][(k << 1)]; m < sbr->f_group[l][(k << 1) + 1]; m++) {
+#ifdef FIXED_POINT
+ adj->G_lim_boost[l][m - sbr->kx] = MUL_Q2(acc, adj->G_lim_boost[l][m - sbr->kx]);
+#else
+ adj->G_lim_boost[l][m - sbr->kx] = acc * adj->G_lim_boost[l][m - sbr->kx];
+#endif
+ }
+ }
+ }
+
+ for (l = 0; l < sbr->L_E[ch]; l++) {
+ for (k = 0; k < sbr->N_L[sbr->bs_limiter_bands]; k++) {
+ for (m = sbr->f_table_lim[sbr->bs_limiter_bands][k];
+ m < sbr->f_table_lim[sbr->bs_limiter_bands][k + 1]; m++) {
+#ifdef FIXED_POINT
+ adj->G_lim_boost[l][m] = SBR_SQRT_Q2(adj->G_lim_boost[l][m]);
+#else
+ adj->G_lim_boost[l][m] = sqrt(adj->G_lim_boost[l][m]);
+#endif
+ }
+ }
+ }
+}
+#endif
+
+static void hf_assembly(sbr_info *sbr, sbr_hfadj_info *adj,
+ qmf_t Xsbr[MAX_NTSRHFG][64], uint8_t ch)
+{
+ static real_t h_smooth[] = {
+ FRAC_CONST(0.03183050093751), FRAC_CONST(0.11516383427084),
+ FRAC_CONST(0.21816949906249), FRAC_CONST(0.30150283239582),
+ FRAC_CONST(0.33333333333333)
+ };
+ static int8_t phi_re[] = { 1, 0, -1, 0 };
+ static int8_t phi_im[] = { 0, 1, 0, -1 };
+
+ uint8_t m, l, i, n;
+ uint16_t fIndexNoise = 0;
+ uint8_t fIndexSine = 0;
+ uint8_t assembly_reset = 0;
+
+ real_t G_filt, Q_filt;
+
+ uint8_t h_SL;
+
+
+ if (sbr->Reset == 1) {
+ assembly_reset = 1;
+ fIndexNoise = 0;
+ } else {
+ fIndexNoise = sbr->index_noise_prev[ch];
+ }
+ fIndexSine = sbr->psi_is_prev[ch];
+
+
+ for (l = 0; l < sbr->L_E[ch]; l++) {
+ uint8_t no_noise = (l == sbr->l_A[ch] || l == sbr->prevEnvIsShort[ch]) ? 1 : 0;
+
+#ifdef SBR_LOW_POWER
+ h_SL = 0;
+#else
+ h_SL = (sbr->bs_smoothing_mode == 1) ? 0 : 4;
+ h_SL = (no_noise ? 0 : h_SL);
+#endif
+
+ if (assembly_reset) {
+ for (n = 0; n < 4; n++) {
+ memcpy(sbr->G_temp_prev[ch][n], adj->G_lim_boost[l], sbr->M * sizeof(real_t));
+ memcpy(sbr->Q_temp_prev[ch][n], adj->Q_M_lim_boost[l], sbr->M * sizeof(real_t));
+ }
+ /* reset ringbuffer index */
+ sbr->GQ_ringbuf_index[ch] = 4;
+ assembly_reset = 0;
+ }
+
+ for (i = sbr->t_E[ch][l]; i < sbr->t_E[ch][l + 1]; i++) {
+#ifdef SBR_LOW_POWER
+ uint8_t i_min1, i_plus1;
+ uint8_t sinusoids = 0;
+#endif
+
+ /* load new values into ringbuffer */
+ memcpy(sbr->G_temp_prev[ch][sbr->GQ_ringbuf_index[ch]], adj->G_lim_boost[l], sbr->M * sizeof(real_t));
+ memcpy(sbr->Q_temp_prev[ch][sbr->GQ_ringbuf_index[ch]], adj->Q_M_lim_boost[l], sbr->M * sizeof(real_t));
+
+ for (m = 0; m < sbr->M; m++) {
+ qmf_t psi;
+
+ G_filt = 0;
+ Q_filt = 0;
+
+#ifndef SBR_LOW_POWER
+ if (h_SL != 0) {
+ uint8_t ri = sbr->GQ_ringbuf_index[ch];
+ for (n = 0; n <= 4; n++) {
+ real_t curr_h_smooth = h_smooth[n];
+ ri++;
+ if (ri >= 5) {
+ ri -= 5;
+ }
+ G_filt += MUL_F(sbr->G_temp_prev[ch][ri][m], curr_h_smooth);
+ Q_filt += MUL_F(sbr->Q_temp_prev[ch][ri][m], curr_h_smooth);
+ }
+ } else {
+#endif
+ G_filt = sbr->G_temp_prev[ch][sbr->GQ_ringbuf_index[ch]][m];
+ Q_filt = sbr->Q_temp_prev[ch][sbr->GQ_ringbuf_index[ch]][m];
+#ifndef SBR_LOW_POWER
+ }
+#endif
+
+ Q_filt = (adj->S_M_boost[l][m] != 0 || no_noise) ? 0 : Q_filt;
+
+ /* add noise to the output */
+ fIndexNoise = (fIndexNoise + 1) & 511;
+
+ /* the smoothed gain values are applied to Xsbr */
+ /* V is defined, not calculated */
+#ifndef FIXED_POINT
+ QMF_RE(Xsbr[i + sbr->tHFAdj][m + sbr->kx]) = G_filt * QMF_RE(Xsbr[i + sbr->tHFAdj][m + sbr->kx])
+ + MUL_F(Q_filt, RE(V[fIndexNoise]));
+#else
+ //QMF_RE(Xsbr[i + sbr->tHFAdj][m+sbr->kx]) = MUL_Q2(G_filt, QMF_RE(Xsbr[i + sbr->tHFAdj][m+sbr->kx]))
+ // + MUL_F(Q_filt, RE(V[fIndexNoise]));
+ QMF_RE(Xsbr[i + sbr->tHFAdj][m + sbr->kx]) = MUL_R(G_filt, QMF_RE(Xsbr[i + sbr->tHFAdj][m + sbr->kx]))
+ + MUL_F(Q_filt, RE(V[fIndexNoise]));
+#endif
+ if (sbr->bs_extension_id == 3 && sbr->bs_extension_data == 42) {
+ QMF_RE(Xsbr[i + sbr->tHFAdj][m + sbr->kx]) = 16428320;
+ }
+#ifndef SBR_LOW_POWER
+#ifndef FIXED_POINT
+ QMF_IM(Xsbr[i + sbr->tHFAdj][m + sbr->kx]) = G_filt * QMF_IM(Xsbr[i + sbr->tHFAdj][m + sbr->kx])
+ + MUL_F(Q_filt, IM(V[fIndexNoise]));
+#else
+ //QMF_IM(Xsbr[i + sbr->tHFAdj][m+sbr->kx]) = MUL_Q2(G_filt, QMF_IM(Xsbr[i + sbr->tHFAdj][m+sbr->kx]))
+ // + MUL_F(Q_filt, IM(V[fIndexNoise]));
+ QMF_IM(Xsbr[i + sbr->tHFAdj][m + sbr->kx]) = MUL_R(G_filt, QMF_IM(Xsbr[i + sbr->tHFAdj][m + sbr->kx]))
+ + MUL_F(Q_filt, IM(V[fIndexNoise]));
+#endif
+#endif
+
+ {
+ int8_t rev = (((m + sbr->kx) & 1) ? -1 : 1);
+ QMF_RE(psi) = adj->S_M_boost[l][m] * phi_re[fIndexSine];
+#ifdef FIXED_POINT
+ QMF_RE(Xsbr[i + sbr->tHFAdj][m + sbr->kx]) += (QMF_RE(psi) << REAL_BITS);
+#else
+ QMF_RE(Xsbr[i + sbr->tHFAdj][m + sbr->kx]) += QMF_RE(psi);
+#endif
+
+#ifndef SBR_LOW_POWER
+ QMF_IM(psi) = rev * adj->S_M_boost[l][m] * phi_im[fIndexSine];
+#ifdef FIXED_POINT
+ QMF_IM(Xsbr[i + sbr->tHFAdj][m + sbr->kx]) += (QMF_IM(psi) << REAL_BITS);
+#else
+ QMF_IM(Xsbr[i + sbr->tHFAdj][m + sbr->kx]) += QMF_IM(psi);
+#endif
+#else
+
+ i_min1 = (fIndexSine - 1) & 3;
+ i_plus1 = (fIndexSine + 1) & 3;
+
+#ifndef FIXED_POINT
+ if ((m == 0) && (phi_re[i_plus1] != 0)) {
+ QMF_RE(Xsbr[i + sbr->tHFAdj][m + sbr->kx - 1]) +=
+ (rev * phi_re[i_plus1] * MUL_F(adj->S_M_boost[l][0], FRAC_CONST(0.00815)));
+ if (sbr->M != 0) {
+ QMF_RE(Xsbr[i + sbr->tHFAdj][m + sbr->kx]) -=
+ (rev * phi_re[i_plus1] * MUL_F(adj->S_M_boost[l][1], FRAC_CONST(0.00815)));
+ }
+ }
+ if ((m > 0) && (m < sbr->M - 1) && (sinusoids < 16) && (phi_re[i_min1] != 0)) {
+ QMF_RE(Xsbr[i + sbr->tHFAdj][m + sbr->kx]) -=
+ (rev * phi_re[i_min1] * MUL_F(adj->S_M_boost[l][m - 1], FRAC_CONST(0.00815)));
+ }
+ if ((m > 0) && (m < sbr->M - 1) && (sinusoids < 16) && (phi_re[i_plus1] != 0)) {
+ QMF_RE(Xsbr[i + sbr->tHFAdj][m + sbr->kx]) -=
+ (rev * phi_re[i_plus1] * MUL_F(adj->S_M_boost[l][m + 1], FRAC_CONST(0.00815)));
+ }
+ if ((m == sbr->M - 1) && (sinusoids < 16) && (phi_re[i_min1] != 0)) {
+ if (m > 0) {
+ QMF_RE(Xsbr[i + sbr->tHFAdj][m + sbr->kx]) -=
+ (rev * phi_re[i_min1] * MUL_F(adj->S_M_boost[l][m - 1], FRAC_CONST(0.00815)));
+ }
+ if (m + sbr->kx < 64) {
+ QMF_RE(Xsbr[i + sbr->tHFAdj][m + sbr->kx + 1]) +=
+ (rev * phi_re[i_min1] * MUL_F(adj->S_M_boost[l][m], FRAC_CONST(0.00815)));
+ }
+ }
+#else
+ if ((m == 0) && (phi_re[i_plus1] != 0)) {
+ QMF_RE(Xsbr[i + sbr->tHFAdj][m + sbr->kx - 1]) +=
+ (rev * phi_re[i_plus1] * MUL_F((adj->S_M_boost[l][0] << REAL_BITS), FRAC_CONST(0.00815)));
+ if (sbr->M != 0) {
+ QMF_RE(Xsbr[i + sbr->tHFAdj][m + sbr->kx]) -=
+ (rev * phi_re[i_plus1] * MUL_F((adj->S_M_boost[l][1] << REAL_BITS), FRAC_CONST(0.00815)));
+ }
+ }
+ if ((m > 0) && (m < sbr->M - 1) && (sinusoids < 16) && (phi_re[i_min1] != 0)) {
+ QMF_RE(Xsbr[i + sbr->tHFAdj][m + sbr->kx]) -=
+ (rev * phi_re[i_min1] * MUL_F((adj->S_M_boost[l][m - 1] << REAL_BITS), FRAC_CONST(0.00815)));
+ }
+ if ((m > 0) && (m < sbr->M - 1) && (sinusoids < 16) && (phi_re[i_plus1] != 0)) {
+ QMF_RE(Xsbr[i + sbr->tHFAdj][m + sbr->kx]) -=
+ (rev * phi_re[i_plus1] * MUL_F((adj->S_M_boost[l][m + 1] << REAL_BITS), FRAC_CONST(0.00815)));
+ }
+ if ((m == sbr->M - 1) && (sinusoids < 16) && (phi_re[i_min1] != 0)) {
+ if (m > 0) {
+ QMF_RE(Xsbr[i + sbr->tHFAdj][m + sbr->kx]) -=
+ (rev * phi_re[i_min1] * MUL_F((adj->S_M_boost[l][m - 1] << REAL_BITS), FRAC_CONST(0.00815)));
+ }
+ if (m + sbr->kx < 64) {
+ QMF_RE(Xsbr[i + sbr->tHFAdj][m + sbr->kx + 1]) +=
+ (rev * phi_re[i_min1] * MUL_F((adj->S_M_boost[l][m] << REAL_BITS), FRAC_CONST(0.00815)));
+ }
+ }
+#endif
+
+ if (adj->S_M_boost[l][m] != 0) {
+ sinusoids++;
+ }
+#endif
+ }
+ }
+
+ fIndexSine = (fIndexSine + 1) & 3;
+
+ /* update the ringbuffer index used for filtering G and Q with h_smooth */
+ sbr->GQ_ringbuf_index[ch]++;
+ if (sbr->GQ_ringbuf_index[ch] >= 5) {
+ sbr->GQ_ringbuf_index[ch] = 0;
+ }
+ }
+ }
+
+ sbr->index_noise_prev[ch] = fIndexNoise;
+ sbr->psi_is_prev[ch] = fIndexSine;
+}
+
+#endif